@@ -133,36 +133,35 @@ public function parseUntil(int $position): void
133
133
continue ;
134
134
}
135
135
136
- // Single-line string
137
- if ('" ' === $ matchChar || "' " === $ matchChar ) {
138
- if (false === $ endPos = strpos ($ this ->content , $ matchChar , $ matchPos + 1 )) {
139
- $ this ->endsWithSequence (self ::STATE_STRING , $ position );
140
-
141
- return ;
142
- }
143
- while (false !== $ endPos && '\\' == $ this ->content [$ endPos - 1 ]) {
144
- $ endPos = strpos ($ this ->content , $ matchChar , $ endPos + 1 );
136
+ if ('" ' === $ matchChar || "' " === $ matchChar || '` ' === $ matchChar ) {
137
+ $ endPos = $ matchPos + 1 ;
138
+ while (false !== $ endPos = strpos ($ this ->content , $ matchChar , $ endPos )) {
139
+ $ backslashes = 0 ;
140
+ $ i = $ endPos - 1 ;
141
+ while ($ i >= 0 && $ this ->content [$ i ] === '\\' ) {
142
+ $ backslashes ++;
143
+ $ i --;
144
+ }
145
+
146
+ if (0 === $ backslashes % 2 ) {
147
+ break ;
148
+ }
149
+
150
+ $ endPos ++;
145
151
}
146
152
147
- $ this ->cursor = min ($ endPos + 1 , $ position );
148
- $ this ->setSequence (self ::STATE_STRING , $ endPos + 1 );
149
- continue ;
150
- }
151
-
152
- // Multi-line string
153
- if ('` ' === $ matchChar ) {
154
- if (false === $ endPos = strpos ($ this ->content , $ matchChar , $ matchPos + 1 )) {
153
+ if (false === $ endPos ) {
155
154
$ this ->endsWithSequence (self ::STATE_STRING , $ position );
156
-
157
155
return ;
158
156
}
159
- while (false !== $ endPos && '\\' == $ this ->content [$ endPos - 1 ]) {
160
- $ endPos = strpos ($ this ->content , $ matchChar , $ endPos + 1 );
161
- }
162
157
163
158
$ this ->cursor = min ($ endPos + 1 , $ position );
164
159
$ this ->setSequence (self ::STATE_STRING , $ endPos + 1 );
160
+ continue ;
165
161
}
162
+
163
+ // Fallback
164
+ $ this ->cursor = $ matchPos + 1 ;
166
165
}
167
166
}
168
167
0 commit comments