shithub: rgbds

Download patch

ref: 0c85240b97af874a8245e2111e00effcdc6c3700
parent: 58ab88da82577ee9f73557fcb937016dbfd29893
author: Antonio Niño Díaz <antonio_nd@outlook.com>
date: Tue Feb 20 18:54:37 EST 2018

Allow line continuations in list of macro args

For example:

    PrintMacro : MACRO
        PRINTT \1
    ENDM

        PrintMacro STRCAT(\"Hello\"\,  \
                          \" world\\n\")

It is possible to have spaces after the '\' and before the newline
character. This is needed because Windows line endings "\r\n" are
converted to " \n" before the lexer has a chance to handle them.

Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -775,6 +775,32 @@
 			case '}':
 				ch = '}';
 				break;
+			case ' ':
+				/*
+				 * Look for line continuation character after a
+				 * series of spaces. This is also useful for
+				 * files that use Windows line endings: "\r\n"
+				 * is replaced by " \n" before the lexer has the
+				 * opportunity to see it.
+				 */
+				while (1) {
+					if (*pLexBuffer == ' ') {
+						pLexBuffer++;
+					} else if (*pLexBuffer == '\n') {
+						pLexBuffer++;
+						nLineNo += 1;
+						ch = 0;
+						break;
+					} else {
+						errx(1, "Expected a new line after the continuation character.");
+					}
+				}
+				break;
+			case '\n':
+				/* Line continuation character */
+				nLineNo += 1;
+				ch = 0;
+				break;
 			default:
 				maxLength = MAXSTRLEN - index;
 				length = CopyMacroArg(&yylval.tzString[index],