diff --git a/src/asm/lexer.c b/src/asm/lexer.c index e9a3e3ab..d0c3a01b 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -2052,9 +2052,23 @@ static int yylex_RAW(void) size_t i = 0; int c; - /* Trim left whitespace (stops at a block comment or line continuation) */ - while (isWhitespace(peek())) - shiftChar(); + /* Trim left whitespace (stops at a block comment) */ + for (;;) { + c = peek(); + if (isWhitespace(c)) { + shiftChar(); + } else if (c == '\\') { + shiftChar(); + c = peek(); + // If not a line continuation, handle as a normal char + if (!isWhitespace(c) && c != '\n' && c != '\r') + goto backslash; + // Line continuations count as "whitespace" + readLineContinuation(); + } else { + break; + } + } for (;;) { c = peek(); @@ -2103,6 +2117,7 @@ static int yylex_RAW(void) shiftChar(); c = peek(); +backslash: switch (c) { case ',': /* Escapes only valid inside a macro arg */ case '(': diff --git a/test/asm/macro-arguments.out b/test/asm/macro-arguments.out index 6da89358..ba541c31 100644 --- a/test/asm/macro-arguments.out +++ b/test/asm/macro-arguments.out @@ -4,8 +4,8 @@ \1: < 1> \2: <2> -'mac c,d': -\1: < c> +'mac c,d': +\1: \2: 'mac 1,2 + 2,3': diff --git a/test/asm/trimmed-macro-args.asm b/test/asm/trimmed-macro-args.asm new file mode 100644 index 00000000..425e08b0 --- /dev/null +++ b/test/asm/trimmed-macro-args.asm @@ -0,0 +1,19 @@ +MACRO print_all + REPT _NARG + PRINTLN "{d:_NARG}: \"\1\"" + SHIFT + ENDR +ENDM + + print_all a, \ + b \ + , c + +DEF EMPTY equs "" + print_all a, \ + {EMPTY} b \ + {EMPTY}, c + + print_all a, \ + /* . */ b \ + /* . */, c diff --git a/test/asm/trimmed-macro-args.err b/test/asm/trimmed-macro-args.err new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/trimmed-macro-args.out b/test/asm/trimmed-macro-args.out new file mode 100644 index 00000000..4a8a778a --- /dev/null +++ b/test/asm/trimmed-macro-args.out @@ -0,0 +1,9 @@ +3: "a" +2: "b" +1: "c" +3: "a" +2: "b" +1: "c" +3: "a" +2: " b" +1: "c"