aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/TokenFactory.php
diff options
context:
space:
mode:
authorAlexander Kiryukhin <alexander@kiryukhin.su>2018-09-12 20:05:09 +0300
committerGitHub <noreply@github.com>2018-09-12 20:05:09 +0300
commit4a672cfd94c07e1821227f27fd1edd2217685136 (patch)
treec50b777d06d9e9eeff6aeb59005c389ddf9a552b /src/NXP/Classes/TokenFactory.php
parent76d1b4b8f02d555e4b4f4fd4d641597f0f6b5f4e (diff)
parent2722a5201d326317e391ae6c0e2fa7e0c2b537b4 (diff)
Merge pull request #28 from phpfui/support_for_double_quoted_strings
Support for double quoted strings
Diffstat (limited to 'src/NXP/Classes/TokenFactory.php')
-rw-r--r--src/NXP/Classes/TokenFactory.php33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/NXP/Classes/TokenFactory.php b/src/NXP/Classes/TokenFactory.php
index 85c4a62..d70dd55 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,27 +32,26 @@ 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
*
@@ -91,16 +91,6 @@ class TokenFactory
}
/**
- * Add variable
- * @param string $name
- * @param mixed $value
- */
- public function addVariable($name, $value)
- {
-
- }
-
- /**
* @return string
*/
public function getTokenParserRegex()
@@ -111,8 +101,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 +132,10 @@ class TokenFactory
return new TokenRightBracket();
}
+ if ($token[0] == '"') {
+ return new TokenString(str_replace('"', '', $token));
+ }
+
if ($token == ',') {
return new TokenComma();
}