aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/TokenFactory.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/NXP/Classes/TokenFactory.php')
-rw-r--r--src/NXP/Classes/TokenFactory.php44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/NXP/Classes/TokenFactory.php b/src/NXP/Classes/TokenFactory.php
index 85c4a62..e5aa865 100644
--- a/src/NXP/Classes/TokenFactory.php
+++ b/src/NXP/Classes/TokenFactory.php
@@ -17,6 +17,7 @@ use NXP\Classes\Token\TokenLeftBracket;
use NXP\Classes\Token\TokenNumber;
use NXP\Classes\Token\TokenRightBracket;
use NXP\Classes\Token\TokenVariable;
+use NXP\Classes\Token\TokenString;
use NXP\Exception\UnknownFunctionException;
use NXP\Exception\UnknownOperatorException;
use NXP\Exception\UnknownTokenException;
@@ -31,24 +32,36 @@ class TokenFactory
*
* @var array
*/
- protected $operators = array();
+ protected $operators = [];
/**
* Available functions
*
* @var array
*/
- protected $functions = array();
+ protected $functions = [];
/**
* Add function
- * @param $name
- * @param $function
- * @param $places
+ * @param string $name
+ * @param callable $function
+ * @param int $places
*/
- public function addFunction($name, $function, $places = 1)
+ public function addFunction($name, callable $function, $places = 1)
{
- $this->functions[$name] = array($places, $function);
+ $this->functions[$name] = [$places, $function];
+ }
+
+
+ /**
+ * get functions
+ *
+ * @return array containing callback and places indexed by
+ * function name
+ */
+ public function getFunctions()
+ {
+ return $this->functions;
}
@@ -91,16 +104,6 @@ class TokenFactory
}
/**
- * Add variable
- * @param string $name
- * @param mixed $value
- */
- public function addVariable($name, $value)
- {
-
- }
-
- /**
* @return string
*/
public function getTokenParserRegex()
@@ -111,8 +114,9 @@ class TokenFactory
}
return sprintf(
- '/(%s)|([%s])|(%s)|(%s)|([%s%s%s])/i',
+ '/(%s)|(%s)|([%s])|(%s)|(%s)|([%s%s%s])/i',
TokenNumber::getRegex(),
+ TokenString::getRegex(),
$operatorsRegex,
TokenFunction::getRegex(),
TokenVariable::getRegex(),
@@ -141,6 +145,10 @@ class TokenFactory
return new TokenRightBracket();
}
+ if ($token[0] == '"') {
+ return new TokenString(str_replace('"', '', $token));
+ }
+
if ($token == ',') {
return new TokenComma();
}