A set of classes for parsing, evaluating, and formatting die roll strings.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SA_DiceExpressionStringConstants.h 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // SA_DiceExpressionStringConstants.h
  3. //
  4. // Copyright (c) 2016 Said Achmiz.
  5. //
  6. // This software is licensed under the MIT license.
  7. // See the file "LICENSE" for more information.
  8. #import <Foundation/Foundation.h>
  9. /***************************************************/
  10. #pragma mark String constants for expression parsing
  11. /***************************************************/
  12. // Each term in an expression (i.e. each node in the expression tree) has a
  13. // value for the SA_DB_TERM_TYPE key, which may be one of the term types listed
  14. // below. SA_DB_TERM_TYPE_NONE is used for terms that fail to be parsed at all,
  15. // because their input strings contain illegal characters or are empty.
  16. extern NSString * const SA_DB_TERM_TYPE; // key
  17. extern NSString * const SA_DB_TERM_TYPE_VALUE; // value
  18. extern NSString * const SA_DB_TERM_TYPE_ROLL_COMMAND; // value
  19. extern NSString * const SA_DB_TERM_TYPE_OPERATION; // value
  20. extern NSString * const SA_DB_TERM_TYPE_NONE; // value
  21. // Terms that are erroneous (malformed or illegal in some way) have a value for
  22. // the SA_DB_ERRORS key. Whether they have values for any other keys is
  23. // undefined. The value for this key is an NSArray of NSString objects, each
  24. // having one of the listed values.
  25. extern NSString * const SA_DB_ERRORS; // key
  26. extern NSString * const SA_DB_ERROR_ROLL_STRING_EMPTY; // value
  27. extern NSString * const SA_DB_ERROR_ROLL_STRING_HAS_ILLEGAL_CHARACTERS; // value
  28. // Terms of type SA_DB_TERM_TYPE_OPERATION (a.k.a. operation expressions) have a
  29. // value for the SA_DB_OPERATOR key, which may be any of the allowed operators
  30. // listed below.
  31. // Operation expressions also have a value for the SA_DB_OPERAND_RIGHT key,
  32. // and, possibly, a value for the SA_DB_OPERAND_LEFT key as well.
  33. // The values for the SA_DB_OPERAND_RIGHT (and, if present, SA_DB_OPERAND_LEFT)
  34. // are themselves expressions of some type (i.e. NSDictionary objects), which
  35. // must be recursively evaluated.
  36. extern NSString * const SA_DB_OPERATOR; // key
  37. extern NSString * const SA_DB_OPERATOR_MINUS; // value
  38. extern NSString * const SA_DB_OPERATOR_PLUS; // value
  39. extern NSString * const SA_DB_OPERATOR_TIMES; // value
  40. extern NSString * const SA_DB_OPERAND_LEFT; // key
  41. extern NSString * const SA_DB_OPERAND_RIGHT; // key
  42. // Terms of type SA_DB_TERM_TYPE_ROLL_COMMAND (a.k.a. roll command expressions)
  43. // have a value for the SA_DB_ROLL_COMMAND key, which may be any of the roll
  44. // commands listed below.
  45. // Roll command expressions also have values for the keys SA_DB_ROLL_DIE_COUNT
  46. // and SA_DB_ROLL_DIE_SIZE, which are themselves expressions of some type
  47. // (i.e. NSDictionary objects), which must be recursively evaluated.
  48. extern NSString * const SA_DB_ROLL_COMMAND; // key
  49. extern NSString * const SA_DB_ROLL_COMMAND_SUM; // value
  50. extern NSString * const SA_DB_ROLL_DIE_COUNT; // key
  51. extern NSString * const SA_DB_ROLL_DIE_SIZE; // key
  52. // Terms of type SA_DB_TERM_TYPE_VALUE (a.k.a. simple value expressions) have a
  53. // value for the SA_DB_VALUE key, which is an NSNumber that represents an
  54. // NSInteger value.
  55. extern NSString * const SA_DB_VALUE; // key
  56. // All terms that were generated via parsing a string should have a value for
  57. // the SA_DB_INPUT_STRING key. This is in order to be able to reconstruct the
  58. // input, for useful output later (i.e., it's used by the results formatter).
  59. // The value is, of course, an NSString.
  60. // Optionally, there may also be a value for the SA_DB_ATTRIBUTED_INPUT_STRING
  61. // key. The current implementation does not set a value for this key, nor is it
  62. // used in any way, but it may be used in future versions or in alternate
  63. // implementations.
  64. extern NSString * const SA_DB_INPUT_STRING; // key
  65. extern NSString * const SA_DB_ATTRIBUTED_INPUT_STRING; // key
  66. /******************************************************/
  67. #pragma mark String constants for expression evaluation
  68. /******************************************************/
  69. // Additional values for key SA_DB_ERROR
  70. extern NSString * const SA_DB_ERROR_UNKNOWN_ROLL_COMMAND; // value
  71. extern NSString * const SA_DB_ERROR_DIE_COUNT_NEGATIVE; // value
  72. extern NSString * const SA_DB_ERROR_DIE_COUNT_EXCESSIVE; // value
  73. extern NSString * const SA_DB_ERROR_DIE_SIZE_INVALID; // value
  74. extern NSString * const SA_DB_ERROR_DIE_SIZE_EXCESSIVE; // value
  75. extern NSString * const SA_DB_ERROR_UNKNOWN_OPERATOR; // value
  76. extern NSString * const SA_DB_ERROR_INVALID_EXPRESSION; // value
  77. extern NSString * const SA_DB_ERROR_INTEGER_OVERFLOW_NEGATION; // value
  78. extern NSString * const SA_DB_ERROR_INTEGER_OVERFLOW_ADDITION; // value
  79. extern NSString * const SA_DB_ERROR_INTEGER_UNDERFLOW_ADDITION; // value
  80. extern NSString * const SA_DB_ERROR_INTEGER_OVERFLOW_SUBTRACTION; // value
  81. extern NSString * const SA_DB_ERROR_INTEGER_UNDERFLOW_SUBTRACTION; // value
  82. extern NSString * const SA_DB_ERROR_INTEGER_OVERFLOW_MULTIPLICATION; // value
  83. extern NSString * const SA_DB_ERROR_INTEGER_UNDERFLOW_MULTIPLICATION; // value
  84. // Successfully evaluated terms (i.e., those that have no errors) have a value
  85. // for the SA_DB_RESULT key. This value is an NSNumber that represents an
  86. // NSInteger value.
  87. extern NSString * const SA_DB_RESULT; // key
  88. // Successfully evaluated roll command terms (i.e. those that have no errors)
  89. // have a value for the SA_DB_ROLLS key. This is an NSArray containing all of
  90. // the individual die rolls that were generated by executing the roll command.
  91. extern NSString * const SA_DB_ROLLS; // key
  92. /***************************************************************/
  93. #pragma mark String constants for retrieving string format rules
  94. /***************************************************************/
  95. extern NSString * const SA_DB_STRING_FORMAT_RULES_PLIST_NAME;
  96. /*
  97. The string format rules file (whose basename (i.e., filename minus the .plist
  98. extension) is given by the SA_DB_STRING_FORMAT_RULES_PLIST_NAME string)
  99. contains values for variables that define the properties of legal die roll
  100. strings, as well as certain variables that define the format of result strings.
  101. The file is organized as a dictionary contaning several sub-dictionaries. The
  102. valid keys (those for which values are present in the file), and the values
  103. that those keys may be expected to have, are listed below.
  104. */
  105. // The value for the top-level key SA_DB_VALID_CHARACTERS is a dictionary that
  106. // defines those characters that are recognized as valid representations of
  107. // various components of a die roll string. This dictionary has values for the
  108. // keys listed below whose names begin with SA_DB_VALID_.
  109. extern NSString * const SA_DB_VALID_CHARACTERS;
  110. // The value for the key SA_DB_VALID_NUMERAL_CHARACTERS is a string that
  111. // contains all characters that are recognized as representing decimal numerals.
  112. // (Usually, this will be the 10 characters representing the standard Arabic
  113. // numerals.)
  114. extern NSString * const SA_DB_VALID_NUMERAL_CHARACTERS;
  115. // The value for the key SA_DB_VALID_OPERATOR_CHARACTERS is a dictionary that
  116. // defines those characters that are recognized as valid representations of
  117. // the supported mathematical operators. This dictionary has values for keys
  118. // corresponding to the names of each of the supported operators (see
  119. // the "String constants for expression parsing" section, above).
  120. extern NSString * const SA_DB_VALID_OPERATOR_CHARACTERS;
  121. // The value for the key SA_DB_VALID_ROLL_COMMAND_DELIMITER_CHARACTERS is a
  122. // string that contains all the characters that are recognized as representing
  123. // die roll command delimiters. (Usually this is the lowercase and uppercase
  124. // versions of the letter 'd', as in '1d20' or '4D6'.)
  125. extern NSString * const SA_DB_VALID_ROLL_COMMAND_DELIMITER_CHARACTERS;
  126. // The value for the top-level key SA_DB_CANONICAL_REPRESENTATIONS is a
  127. // dictionary that defines canonical representations of certain components
  128. // of a formatted die roll string. This dictionary has values for the keys
  129. // listed below whose names begin with SA_DB_CANONICAL_.
  130. extern NSString * const SA_DB_CANONICAL_REPRESENTATIONS;
  131. // The value for the key SA_DB_CANONICAL_OPERATOR_REPRESENTATIONS is a
  132. // dictionary that defines canonical representations of each of the
  133. // supported mathematical operators (for use when formatting results for
  134. // output). This dictionary has values for keys corresponding to the names of
  135. // each of the supported operators (see the "String constants for expression
  136. // parsing" section, above).
  137. extern NSString * const SA_DB_CANONICAL_OPERATOR_REPRESENTATIONS;
  138. // The value for the key SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION
  139. // is the canonical representation of the die roll command delimiter.
  140. extern NSString * const SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION;