@@ -20,16 +20,16 @@ class Tokenizer
20
20
private const STATE_INTERPOLATION = 4 ;
21
21
private const STATE_COMMENT = 5 ;
22
22
23
+ private const SQ_STRING_PART = '[^ \'\\\\]*(?: \\\\.[^ \'\\\\]*)* ' ;
24
+ private const DQ_STRING_PART = '[^#" \\\\]*(?:(?: \\\\.|#(?!\{))[^#" \\\\]*)* ' ;
25
+
23
26
private const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A ' ;
24
27
private const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A ' ;
25
- private const REGEX_STRING = '/"([^#" \\\\]*(?: \\\\.[^#" \\\\]*)*)"| \'([^ \'\\\\]*(?: \\\\.[^ \'\\\\]*)*) \'/As ' ;
28
+ private const REGEX_STRING = '/"( ' .self ::DQ_STRING_PART .')"| \'( ' .self ::SQ_STRING_PART .') \'/As ' ;
29
+ private const REGEX_DQ_STRING_PART = '/ ' .self ::DQ_STRING_PART .'/As ' ;
26
30
private const REGEX_DQ_STRING_DELIM = '/"/A ' ;
27
- private const REGEX_DQ_STRING_PART = '/[^#" \\\\]*(?:(?: \\\\.|#(?!\{))[^#" \\\\]*)*/As ' ;
28
31
private const PUNCTUATION = '()[]{}:.,| ' ;
29
32
30
- // TODO: Il faut surement changer les regex pour que "a#" et "a" soient traités de la même manière
31
- // Car actuellement le second est DQ string (sans interpolation) alors que le premier est string
32
-
33
33
/**
34
34
* @var array
35
35
*/
@@ -408,7 +408,7 @@ protected function lexDqString(): void
408
408
} elseif (preg_match (self ::REGEX_DQ_STRING_PART , $ this ->code , $ match , 0 , $ this ->cursor )
409
409
&& strlen ($ match [0 ]) > 0
410
410
) {
411
- $ this ->pushToken (Token::STRING_TYPE , stripcslashes ( $ match [0 ]) );
411
+ $ this ->pushToken (Token::STRING_TYPE , $ match [0 ]);
412
412
$ this ->moveCursor ($ match [0 ]);
413
413
} elseif (preg_match (self ::REGEX_DQ_STRING_DELIM , $ this ->code , $ match , 0 , $ this ->cursor )) {
414
414
$ bracket = array_pop ($ this ->bracketsAndTernary );
@@ -667,7 +667,7 @@ protected function lexPunctuation(): void
667
667
*/
668
668
protected function lexString (string $ string ): void
669
669
{
670
- $ this ->pushToken (Token::STRING_TYPE , addcslashes ( stripcslashes ( $ string), '\\' ) );
670
+ $ this ->pushToken (Token::STRING_TYPE , $ string );
671
671
$ this ->moveCursor ($ string );
672
672
}
673
673
}
0 commit comments