@@ -160,7 +160,7 @@ protected function tokenize()
160
160
}
161
161
$ currentChar = $ stream [$ streamIndex ];
162
162
$ matches = array ();
163
- $ currentLine = (preg_match ('#(.*)\n # ' , $ stream , $ matches , null , $ streamIndex ) === 1 ) ? $ matches [1 ] : substr ($ stream , $ streamIndex );
163
+ $ currentLine = (preg_match ('#(.*?)(?:\n|\r\n?) # ' , $ stream , $ matches , null , $ streamIndex ) === 1 ) ? $ matches [1 ] : substr ($ stream , $ streamIndex );
164
164
if ($ currentChar === ' ' ) {
165
165
$ currentWord = (preg_match ('#( +)# ' , $ currentLine , $ matches ) === 1 ) ? $ matches [1 ] : $ currentLine ;
166
166
} else {
@@ -213,7 +213,7 @@ protected function tokenize()
213
213
}
214
214
215
215
if ($ MACRO_HAS_CONTEXT ($ CONTEXT_CLASS )) {
216
- if (in_array ($ currentChar , array (' ' , '( ' , "\n" ))) {
216
+ if (in_array ($ currentChar , array (' ' , '( ' , "\n" , "\r" ))) {
217
217
$ context &= ~$ CONTEXT_CLASS ;
218
218
$ MACRO_TOKEN_ADVANCE ();
219
219
} else {
@@ -225,7 +225,22 @@ protected function tokenize()
225
225
}
226
226
}
227
227
228
- if ($ currentChar === "\n" ) {
228
+ // Since we don't know what line endings are used in the file, we check for all scenarios. If we find a
229
+ // cariage return (\r), we check the next character for a line feed (\n). If so we consume it and act as
230
+ // if the cariage return was a line feed.
231
+ $ lineEnded = $ currentChar === "\n" ;
232
+ if ($ currentChar === "\r" ) {
233
+ $ lineEnded = true ;
234
+
235
+ $ nextChar = $ MACRO_STREAM_ADVANCE_CHAR ();
236
+ if ($ nextChar !== "\n" ) {
237
+ $ streamIndex --;
238
+ }
239
+
240
+ $ currentChar = "\n" ;
241
+ }
242
+
243
+ if ($ lineEnded ) {
229
244
$ MACRO_TOKEN_SET_TYPE ('ANNOTATION_NEWLINE ' );
230
245
$ MACRO_TOKEN_APPEND_CHAR ();
231
246
$ MACRO_TOKEN_ADVANCE ();
0 commit comments