A set of classes for parsing, evaluating, and formatting die roll strings.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SA_DiceExpressionStringConstants.h 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. // (An operation expression with an SA_DB_OPERATOR value of SA_DB_OPERATOR_MINUS
  34. // that does not have an SA_DB_OPERAND_LEFT value is simply a negation of the
  35. // SA_DB_OPERAND_RIGHT value.)
  36. // The values for the SA_DB_OPERAND_RIGHT (and, if present, SA_DB_OPERAND_LEFT)
  37. // are themselves expressions of some type (i.e. NSDictionary objects), which
  38. // must be recursively evaluated.
  39. extern NSString * const SA_DB_OPERATOR; // key
  40. extern NSString * const SA_DB_OPERATOR_MINUS; // value
  41. extern NSString * const SA_DB_OPERATOR_PLUS; // value
  42. extern NSString * const SA_DB_OPERATOR_TIMES; // value
  43. extern NSString * const SA_DB_OPERAND_LEFT; // key
  44. extern NSString * const SA_DB_OPERAND_RIGHT; // key
  45. // Terms of type SA_DB_TERM_TYPE_ROLL_COMMAND (a.k.a. roll command expressions)
  46. // have a value for the SA_DB_ROLL_COMMAND key, which may be any of the roll
  47. // commands listed below.
  48. // Roll command expressions also have values for the keys SA_DB_ROLL_DIE_COUNT
  49. // and SA_DB_ROLL_DIE_SIZE, which are themselves expressions of some type
  50. // (i.e. NSDictionary objects), which must be recursively evaluated.
  51. extern NSString * const SA_DB_ROLL_COMMAND; // key
  52. extern NSString * const SA_DB_ROLL_COMMAND_SUM; // value
  53. extern NSString * const SA_DB_ROLL_DIE_COUNT; // key
  54. extern NSString * const SA_DB_ROLL_DIE_SIZE; // key
  55. // Terms of type SA_DB_TERM_TYPE_VALUE (a.k.a. simple value expressions) have a
  56. // value for the SA_DB_VALUE key, which is an NSNumber that represents an
  57. // NSInteger value.
  58. // NOTE: Despite being an NSInteger, this numeric value may not be negative.
  59. extern NSString * const SA_DB_VALUE; // key
  60. // All terms that were generated via parsing a string should have a value for
  61. // the SA_DB_INPUT_STRING key. This is in order to be able to reconstruct the
  62. // input, for useful output later (i.e., it's used by the results formatter).
  63. // The value is, of course, an NSString.
  64. // Optionally, there may also be a value for the SA_DB_ATTRIBUTED_INPUT_STRING
  65. // key. The current implementation does not set a value for this key, nor is it
  66. // used in any way, but it may be used in future versions or in alternate
  67. // implementations.
  68. extern NSString * const SA_DB_INPUT_STRING; // key
  69. extern NSString * const SA_DB_ATTRIBUTED_INPUT_STRING; // key
  70. /******************************************************/
  71. #pragma mark String constants for expression evaluation
  72. /******************************************************/
  73. // Additional values for key SA_DB_ERROR
  74. extern NSString * const SA_DB_ERROR_UNKNOWN_ROLL_COMMAND; // value
  75. extern NSString * const SA_DB_ERROR_DIE_COUNT_NEGATIVE; // value
  76. extern NSString * const SA_DB_ERROR_DIE_COUNT_EXCESSIVE; // value
  77. extern NSString * const SA_DB_ERROR_DIE_SIZE_INVALID; // value
  78. extern NSString * const SA_DB_ERROR_DIE_SIZE_EXCESSIVE; // value
  79. extern NSString * const SA_DB_ERROR_UNKNOWN_OPERATOR; // value
  80. extern NSString * const SA_DB_ERROR_INVALID_EXPRESSION; // value
  81. extern NSString * const SA_DB_ERROR_INTEGER_OVERFLOW_NEGATION; // value
  82. extern NSString * const SA_DB_ERROR_INTEGER_OVERFLOW_ADDITION; // value
  83. extern NSString * const SA_DB_ERROR_INTEGER_UNDERFLOW_ADDITION; // value
  84. extern NSString * const SA_DB_ERROR_INTEGER_OVERFLOW_SUBTRACTION; // value
  85. extern NSString * const SA_DB_ERROR_INTEGER_UNDERFLOW_SUBTRACTION; // value
  86. extern NSString * const SA_DB_ERROR_INTEGER_OVERFLOW_MULTIPLICATION; // value
  87. extern NSString * const SA_DB_ERROR_INTEGER_UNDERFLOW_MULTIPLICATION; // value
  88. // Successfully evaluated terms (i.e., those that have no errors) have a value
  89. // for the SA_DB_RESULT key. This value is an NSNumber that represents an
  90. // NSInteger value.
  91. extern NSString * const SA_DB_RESULT; // key
  92. // Successfully evaluated roll command terms (i.e. those that have no errors)
  93. // have a value for the SA_DB_ROLLS key. This is an NSArray containing all of
  94. // the individual die rolls that were generated by executing the roll command.
  95. extern NSString * const SA_DB_ROLLS; // key
  96. /***************************************************************/
  97. #pragma mark String constants for retrieving string format rules
  98. /***************************************************************/
  99. extern NSString * const SA_DB_STRING_FORMAT_RULES_PLIST_NAME;
  100. /*
  101. The string format rules file (whose filename - minus the .plist extension -
  102. is given by the SA_DB_STRING_FORMAT_RULES_PLIST_NAME string) contains
  103. values for variables that define the properties of legal die roll strings,
  104. as well as certain variables that define the format of result strings.
  105. The file is organized as a dictionary contaning several sub-dictionaries. The
  106. valid keys (those for which values are present in the file), and the values
  107. that those keys may be expected to have, are listed below.
  108. */
  109. // The value for the top-level key SA_DB_VALID_CHARACTERS is a dictionary that
  110. // defines those characters that are recognized as valid representations of
  111. // various components of a die roll string. This dictionary has values for the
  112. // keys listed below whose names begin with SA_DB_VALID_.
  113. extern NSString * const SA_DB_VALID_CHARACTERS;
  114. // The value for the key SA_DB_VALID_NUMERAL_CHARACTERS is a string that
  115. // contains all characters that are recognized as representing decimal numerals.
  116. // (Usually, this will be the 10 characters representing the standard Arabic
  117. // numerals.)
  118. extern NSString * const SA_DB_VALID_NUMERAL_CHARACTERS;
  119. // The value for the key SA_DB_VALID_OPERATOR_CHARACTERS is a dictionary that
  120. // defines those characters that are recognized as valid representations of
  121. // the supported mathematical operators. This dictionary has values for keys
  122. // corresponding to the names of each of the supported operators (see
  123. // the "String constants for expression parsing" section, above).
  124. extern NSString * const SA_DB_VALID_OPERATOR_CHARACTERS;
  125. // The value for the key SA_DB_VALID_ROLL_COMMAND_DELIMITER_CHARACTERS is a
  126. // string that contains all the characters that are recognized as representing
  127. // die roll command delimiters. (Usually this is the lowercase and uppercase
  128. // versions of the letter 'd', as in '1d20' or '4D6'.)
  129. extern NSString * const SA_DB_VALID_ROLL_COMMAND_DELIMITER_CHARACTERS;
  130. // The value for the top-level key SA_DB_CANONICAL_REPRESENTATIONS is a
  131. // dictionary that defines canonical representations of certain components
  132. // of a formatted die roll string. This dictionary has values for the keys
  133. // listed below whose names begin with SA_DB_CANONICAL_.
  134. extern NSString * const SA_DB_CANONICAL_REPRESENTATIONS;
  135. // The value for the key SA_DB_CANONICAL_OPERATOR_REPRESENTATIONS is a
  136. // dictionary that defines canonical representations of each of the
  137. // supported mathematical operators (for use when formatting results for
  138. // output). This dictionary has values for keys corresponding to the names of
  139. // each of the supported operators (see the "String constants for expression
  140. // parsing" section, above).
  141. extern NSString * const SA_DB_CANONICAL_OPERATOR_REPRESENTATIONS;
  142. // The value for the key SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION
  143. // is the canonical representation of the die roll command delimiter.
  144. extern NSString * const SA_DB_CANONICAL_ROLL_COMMAND_DELIMITER_REPRESENTATION;