shithub: rgbds

Download patch

ref: e4f2fad215650efd9155adc5312bb76c6c0c3747
parent: 3f5f9bcaf01c0f6b3382f6fb85daa3ac7857ebee
author: ISSOtm <[email protected]>
date: Sat Aug 15 23:08:31 EDT 2020

Support line continuations in main scope

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -896,13 +896,14 @@
 			shiftChars(1);
 		} else if (c == '\r' || c == '\n') {
 			shiftChars(1);
+			if (c == '\r' && peek(0) == '\n')
+				shiftChars(1);
 			if (!lexerState->expansions
-			 || lexerState->expansions->distance) {
+			 || lexerState->expansions->distance)
 				lexerState->lineNo++;
-			}
 			return;
 		} else {
-			error("Begun line continuation, but encountered character %s\n",
+			error("Begun line continuation, but encountered character '%s'\n",
 			      print(c));
 			return;
 		}
@@ -1536,7 +1537,28 @@
 		case EOF:
 			return 0;
 
-		/* Handle identifiers... or error out */
+		/* Handle escapes */
+
+		case '\\':
+			c = peek(0);
+
+			switch (c) {
+			case ' ':
+			case '\r':
+			case '\n':
+				readLineContinuation();
+				break;
+
+			case EOF:
+				error("Illegal character escape at end of input\n");
+				break;
+			default:
+				shiftChars(1);
+				error("Illegal character escape '%s'\n", print(c));
+			}
+			break;
+
+		/* Handle identifiers and escapes... or error out */
 
 		default:
 			if (startsIdentifier(c)) {