aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/Tokenizer.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/NXP/Classes/Tokenizer.php')
-rw-r--r--src/NXP/Classes/Tokenizer.php58
1 files changed, 49 insertions, 9 deletions
diff --git a/src/NXP/Classes/Tokenizer.php b/src/NXP/Classes/Tokenizer.php
index c8b415d..af041c1 100644
--- a/src/NXP/Classes/Tokenizer.php
+++ b/src/NXP/Classes/Tokenizer.php
@@ -50,27 +50,67 @@ class Tokenizer
public function tokenize() : self
{
- foreach (\str_split($this->input, 1) as $ch) {
+ $isLastCharEscape = false;
+
+ foreach (\str_split($this->input) as $ch) {
switch (true) {
case $this->inSingleQuotedString:
- if ("'" === $ch) {
- $this->tokens[] = new Token(Token::String, $this->stringBuffer);
- $this->inSingleQuotedString = false;
- $this->stringBuffer = '';
+ if ('\\' === $ch) {
+ if ($isLastCharEscape) {
+ $this->stringBuffer .= '\\';
+ $isLastCharEscape = false;
+ } else {
+ $isLastCharEscape = true;
+ }
+
+ continue 2;
+ } elseif ("'" === $ch) {
+ if ($isLastCharEscape) {
+ $this->stringBuffer .= "'";
+ $isLastCharEscape = false;
+ } else {
+ $this->tokens[] = new Token(Token::String, $this->stringBuffer);
+ $this->inSingleQuotedString = false;
+ $this->stringBuffer = '';
+ }
continue 2;
}
+
+ if ($isLastCharEscape) {
+ $this->stringBuffer .= '\\';
+ $isLastCharEscape = false;
+ }
$this->stringBuffer .= $ch;
continue 2;
case $this->inDoubleQuotedString:
- if ('"' === $ch) {
- $this->tokens[] = new Token(Token::String, $this->stringBuffer);
- $this->inDoubleQuotedString = false;
- $this->stringBuffer = '';
+ if ('\\' === $ch) {
+ if ($isLastCharEscape) {
+ $this->stringBuffer .= '\\';
+ $isLastCharEscape = false;
+ } else {
+ $isLastCharEscape = true;
+ }
continue 2;
+ } elseif ('"' === $ch) {
+ if ($isLastCharEscape) {
+ $this->stringBuffer .= '"';
+ $isLastCharEscape = false;
+ } else {
+ $this->tokens[] = new Token(Token::String, $this->stringBuffer);
+ $this->inDoubleQuotedString = false;
+ $this->stringBuffer = '';
+ }
+
+ continue 2;
+ }
+
+ if ($isLastCharEscape) {
+ $this->stringBuffer .= '\\';
+ $isLastCharEscape = false;
}
$this->stringBuffer .= $ch;