From ad9c6663b5ca7448afb20135d0a215730249e702 Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Sun, 2 Feb 2020 23:11:06 +0000 Subject: [PATCH] #209 - fix class names that match [a-z]+[0-9]+\- --- src/Parser/Tokenizer/Literals.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Parser/Tokenizer/Literals.php b/src/Parser/Tokenizer/Literals.php index 7f87f07..b264131 100644 --- a/src/Parser/Tokenizer/Literals.php +++ b/src/Parser/Tokenizer/Literals.php @@ -28,11 +28,25 @@ public function tokenize(TokenizedString $str, Tokens $tokens) { } } + private function isRealSubtract($n, $str) { + $n--; + // allow foo(2-5) + //but not data(foo2-5) + while (is_numeric($str->read($n))) { + $n--; + } + + if ($n == 0) return false; + if (in_array($str->read($n), ['(', "\n", ' ', '['])) return true; + + return false; + } + private function isLiteral($n, $str) { //Is it a normal literal character return ($str->has($n) && ($str->identifyChar($n, $str) === Tokenizer::NAME //but a subtract can be part of a class name or a mathematical operation - || $str->identifyChar($n) == Tokenizer::SUBTRACT && !is_numeric($str->read($n-1))) + || $str->identifyChar($n) == Tokenizer::SUBTRACT && !$this->isRealSubtract($n, $str)) ); }