@@ -277,11 +277,19 @@ func lexPHPEnd(l *lexer) stateFn {
277277}
278278
279279func lexLineComment (l * lexer ) stateFn {
280- lineLength := strings .Index (l .input [l .pos :], "\n " ) + 1
280+ lineLength := strings .IndexAny (l .input [l .pos :], "\r \n " ) + 1
281281if lineLength == 0 {
282282// this is the last line, so lex until the end
283283lineLength = len (l .input [l .pos :])
284284}
285+
286+ // deal with varying line endings
287+ if l .input [l .pos + lineLength - 1 ] == '\r' &&
288+ len (l .input [l .pos + lineLength :]) > 0 &&
289+ l .input [l .pos + lineLength ] == '\n' {
290+ lineLength ++
291+ }
292+
285293// don't lex php end
286294if phpEndLength := strings .Index (l .input [l .pos :l .pos + lineLength ], phpEnd ); phpEndLength >= 0 && phpEndLength < lineLength {
287295lineLength = phpEndLength
@@ -315,17 +323,30 @@ func lexDoc(l *lexer) stateFn {
315323labelPos := l .pos
316324l .accept (underscore + alphabet )
317325l .acceptRun (underscore + alphabet + digits )
318- endMarker := fmt .Sprintf ("\n %s" , l .input [labelPos :l .pos ])
326+
327+ endMarkerA := fmt .Sprintf ("\r \n %s" , l .input [labelPos :l .pos ])
328+ endMarkerB := fmt .Sprintf ("\n %s" , l .input [labelPos :l .pos ])
329+ endMarkerC := fmt .Sprintf ("\r %s" , l .input [labelPos :l .pos ])
319330if nowDoc {
320331l .accept ("'" )
321332} else if l .peek () == '"' {
322333l .next ()
323334}
324- l .accept ("\n " )
325- for ! strings .HasPrefix (l .input [l .pos :], endMarker ) {
335+ l .accept ("\r \n " )
336+ l .accept ("\r \n " )
337+
338+ for ! strings .HasPrefix (l .input [l .pos :], endMarkerA ) &&
339+ ! strings .HasPrefix (l .input [l .pos :], endMarkerB ) &&
340+ ! strings .HasPrefix (l .input [l .pos :], endMarkerC ) {
326341l .next ()
327342}
328- l .pos += len (endMarker )
343+
344+ if strings .HasPrefix (l .input [l .pos :], endMarkerA ) {
345+ l .pos += len (endMarkerA )
346+ } else {
347+ l .pos += len (endMarkerB )
348+ }
349+
329350l .emit (token .StringLiteral )
330351return lexPHP
331352}
0 commit comments