shithub: rgbds

Download patch

ref: 423a7c48994fc9430960f83955d6697d484e342a
parent: ee9e45b3d45f0b6f4342159ec75179df503fdc29
author: ISSOtm <[email protected]>
date: Tue Sep 29 21:13:07 EDT 2020

Handle \\r better

Translate it to \\n regardless of the lexer mode

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -1611,9 +1611,7 @@
 		/* Handle newlines and EOF */
 
 		case '\r':
-			if (peek(0) == '\n')
-				shiftChars(1); /* Shift that EOL */
-			/* fallthrough */
+			return '\r';
 		case '\n':
 			return '\n';
 
@@ -1905,6 +1903,10 @@
 				return 0;
 			}
 		}
+	} else if (token == '\r') { /* Handle CR and CRLF line endings */
+		token = '\n'; /* We universally use '\n' as the value for line ending tokens */
+		if (peek(0) == '\n')
+			shiftChars(1); /* Shift the CRLF's LF */
 	}
 	lexerState->lastToken = token;