From 18b12aeeff34c8ac9a350165ae36f08f4138dc9c Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Thu, 10 Jan 2019 20:18:10 -0500 Subject: sync (#5) * Documentation fixes (#34) Fixing typos in and clarifying documentation. * MathExecutor allow override default operators, functions and vars (#36) * Added simple coc (#37) * Added simple coc * Fix * Replaceable operators (#38) * Updated from NeonXP/MathExecutor * Fixed function in () block issue * Fixing typos in and clarifying documentation. * Syncing from origin (#3) * Documentation fixes (#34) Fixing typos in and clarifying documentation. * MathExecutor allow override default operators, functions and vars (#36) * Allow for operators to be replaced based on regex expression * Fix md typo (#39) * Updated from NeonXP/MathExecutor * Fixed function in () block issue * Fixing typos in and clarifying documentation. * Syncing from origin (#3) * Documentation fixes (#34) Fixing typos in and clarifying documentation. * MathExecutor allow override default operators, functions and vars (#36) * Syncing to origin (#4) * Documentation fixes (#34) Fixing typos in and clarifying documentation. * MathExecutor allow override default operators, functions and vars (#36) * Added simple coc (#37) * Added simple coc * Fix * Replaceable operators (#38) * Updated from NeonXP/MathExecutor * Fixed function in () block issue * Fixing typos in and clarifying documentation. * Syncing from origin (#3) * Documentation fixes (#34) Fixing typos in and clarifying documentation. * MathExecutor allow override default operators, functions and vars (#36) * Allow for operators to be replaced based on regex expression * \\ instead of \ * Update README.md Some small fixes * Fix single quotes parsing (#41) * Fix single quotes parsing Fix e-mails Some small fixes * Mistake in test * More PHP versions * Update README.md Deleted `dev` branch --- src/NXP/Classes/TokenFactory.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/NXP/Classes/TokenFactory.php') diff --git a/src/NXP/Classes/TokenFactory.php b/src/NXP/Classes/TokenFactory.php index 778cb59..74b5789 100644 --- a/src/NXP/Classes/TokenFactory.php +++ b/src/NXP/Classes/TokenFactory.php @@ -16,14 +16,15 @@ use NXP\Classes\Token\TokenFunction; use NXP\Classes\Token\TokenLeftBracket; use NXP\Classes\Token\TokenNumber; use NXP\Classes\Token\TokenRightBracket; +use NXP\Classes\Token\TokenStringSingleQuoted; use NXP\Classes\Token\TokenVariable; -use NXP\Classes\Token\TokenString; +use NXP\Classes\Token\TokenStringDoubleQuoted; use NXP\Exception\UnknownFunctionException; use NXP\Exception\UnknownOperatorException; use NXP\Exception\UnknownTokenException; /** - * @author Alexander Kiryukhin + * @author Alexander Kiryukhin */ class TokenFactory { @@ -77,8 +78,9 @@ class TokenFactory /** * Add operator - * @param string $operatorClass - * @throws \NXP\Exception\UnknownOperatorException + * @param string $operatorClass + * @throws UnknownOperatorException + * @throws \ReflectionException */ public function addOperator($operatorClass) { @@ -135,9 +137,10 @@ class TokenFactory } return sprintf( - '/(%s)|(%s)|([%s])|(%s)|(%s)|([%s%s%s])/i', + '/(%s)|(%s)|(%s)|([%s])|(%s)|(%s)|([%s%s%s])/i', TokenNumber::getRegex(), - TokenString::getRegex(), + TokenStringDoubleQuoted::getRegex(), + TokenStringSingleQuoted::getRegex(), $operatorsRegex, TokenFunction::getRegex(), TokenVariable::getRegex(), @@ -148,9 +151,10 @@ class TokenFactory } /** - * @param string $token + * @param string $token * @return InterfaceToken * @throws UnknownTokenException + * @throws UnknownFunctionException */ public function createToken($token) { @@ -167,7 +171,11 @@ class TokenFactory } if ($token[0] == '"') { - return new TokenString(str_replace('"', '', $token)); + return new TokenStringDoubleQuoted(str_replace('"', '', $token)); + } + + if ($token[0] == "'") { + return new TokenStringSingleQuoted(str_replace("'", '', $token)); } if ($token == ',') { @@ -184,7 +192,7 @@ class TokenFactory $regex = sprintf('/%s/i', TokenVariable::getRegex()); if (preg_match($regex, $token)) { - return new TokenVariable(substr($token,1)); + return new TokenVariable(substr($token, 1)); } $regex = sprintf('/%s/i', TokenFunction::getRegex()); -- cgit v1.2.3