FormulaToken.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet\Calculation;
  3. /**
  4. * PARTLY BASED ON:
  5. * Copyright (c) 2007 E. W. Bachtal, Inc.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  8. * and associated documentation files (the "Software"), to deal in the Software without restriction,
  9. * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or substantial
  14. * portions of the Software.
  15. *
  16. * The software is provided "as is", without warranty of any kind, express or implied, including but not
  17. * limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In
  18. * no event shall the authors or copyright holders be liable for any claim, damages or other liability,
  19. * whether in an action of contract, tort or otherwise, arising from, out of or in connection with the
  20. * software or the use or other dealings in the software.
  21. *
  22. * http://ewbi.blogs.com/develops/2007/03/excel_formula_p.html
  23. * http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html
  24. */
  25. class FormulaToken
  26. {
  27. // Token types
  28. const TOKEN_TYPE_NOOP = 'Noop';
  29. const TOKEN_TYPE_OPERAND = 'Operand';
  30. const TOKEN_TYPE_FUNCTION = 'Function';
  31. const TOKEN_TYPE_SUBEXPRESSION = 'Subexpression';
  32. const TOKEN_TYPE_ARGUMENT = 'Argument';
  33. const TOKEN_TYPE_OPERATORPREFIX = 'OperatorPrefix';
  34. const TOKEN_TYPE_OPERATORINFIX = 'OperatorInfix';
  35. const TOKEN_TYPE_OPERATORPOSTFIX = 'OperatorPostfix';
  36. const TOKEN_TYPE_WHITESPACE = 'Whitespace';
  37. const TOKEN_TYPE_UNKNOWN = 'Unknown';
  38. // Token subtypes
  39. const TOKEN_SUBTYPE_NOTHING = 'Nothing';
  40. const TOKEN_SUBTYPE_START = 'Start';
  41. const TOKEN_SUBTYPE_STOP = 'Stop';
  42. const TOKEN_SUBTYPE_TEXT = 'Text';
  43. const TOKEN_SUBTYPE_NUMBER = 'Number';
  44. const TOKEN_SUBTYPE_LOGICAL = 'Logical';
  45. const TOKEN_SUBTYPE_ERROR = 'Error';
  46. const TOKEN_SUBTYPE_RANGE = 'Range';
  47. const TOKEN_SUBTYPE_MATH = 'Math';
  48. const TOKEN_SUBTYPE_CONCATENATION = 'Concatenation';
  49. const TOKEN_SUBTYPE_INTERSECTION = 'Intersection';
  50. const TOKEN_SUBTYPE_UNION = 'Union';
  51. /**
  52. * Value.
  53. *
  54. * @var string
  55. */
  56. private $value;
  57. /**
  58. * Token Type (represented by TOKEN_TYPE_*).
  59. *
  60. * @var string
  61. */
  62. private $tokenType;
  63. /**
  64. * Token SubType (represented by TOKEN_SUBTYPE_*).
  65. *
  66. * @var string
  67. */
  68. private $tokenSubType;
  69. /**
  70. * Create a new FormulaToken.
  71. *
  72. * @param string $pValue
  73. * @param string $pTokenType Token type (represented by TOKEN_TYPE_*)
  74. * @param string $pTokenSubType Token Subtype (represented by TOKEN_SUBTYPE_*)
  75. */
  76. public function __construct($pValue, $pTokenType = self::TOKEN_TYPE_UNKNOWN, $pTokenSubType = self::TOKEN_SUBTYPE_NOTHING)
  77. {
  78. // Initialise values
  79. $this->value = $pValue;
  80. $this->tokenType = $pTokenType;
  81. $this->tokenSubType = $pTokenSubType;
  82. }
  83. /**
  84. * Get Value.
  85. *
  86. * @return string
  87. */
  88. public function getValue()
  89. {
  90. return $this->value;
  91. }
  92. /**
  93. * Set Value.
  94. *
  95. * @param string $value
  96. */
  97. public function setValue($value)
  98. {
  99. $this->value = $value;
  100. }
  101. /**
  102. * Get Token Type (represented by TOKEN_TYPE_*).
  103. *
  104. * @return string
  105. */
  106. public function getTokenType()
  107. {
  108. return $this->tokenType;
  109. }
  110. /**
  111. * Set Token Type (represented by TOKEN_TYPE_*).
  112. *
  113. * @param string $value
  114. */
  115. public function setTokenType($value)
  116. {
  117. $this->tokenType = $value;
  118. }
  119. /**
  120. * Get Token SubType (represented by TOKEN_SUBTYPE_*).
  121. *
  122. * @return string
  123. */
  124. public function getTokenSubType()
  125. {
  126. return $this->tokenSubType;
  127. }
  128. /**
  129. * Set Token SubType (represented by TOKEN_SUBTYPE_*).
  130. *
  131. * @param string $value
  132. */
  133. public function setTokenSubType($value)
  134. {
  135. $this->tokenSubType = $value;
  136. }
  137. }