Files
rgbds/test/asm/raw-macro-args.asm
Rangi d049ffc0f0 Handle string literals within macro arguments (#685)
Fixes #683 and #691

The lexer's raw mode for reading macro args already attempted
to handle semicolons inside string literals, versus outside ones
which start comments. This change reuses the same function for
reading string literals in normal and raw modes, also handling:

- Commas in strings versus between macro args
- Character escapes
- {Interpolations} and \1-\9 args inside vs. outside strings
- Multi-line string literals

Macro args now allow escaping '\', '"', and '\\'.

A consistent model for expanding macro args and interpolations,
within macro args, string literals, and normal context:

- "{S}" should always equal the contents of S
- "\1" should always act like quoting the value of \1
2021-02-16 22:44:25 -05:00

38 lines
687 B
NASM

printargs: MACRO
rept _NARG
println \1
shift
endr
ENDM
printlit: MACRO
rept _NARG
println "\1"
shift
endr
ENDM
NUM EQU 42
STR EQUS "str\"ing"
printargs NUM
printargs "{d:NUM}"
printargs "{STR}", 16 ; comment 1
printargs "\"literal \\\"\\\\\\\"\""
printargs "literal \"\\\"", \ ; comment 2
"""multi-"line"
""string"" arg"""
printargs MUL(2.0\, 3.0)
printargs "unclosed
printlit NUM
printlit "{d:NUM}"
printlit "{STR}", 16 ; comment 3
printlit "\"literal \\\"\\\\\\\"\""
printlit "literal \"\\\"", \ ; comment 4
"""multi-"line"
""string"" arg"""
printlit MUL(2.0\, 3.0)
printlit this\n is\, \{not\} a\\n syntax\" error
printlit "unclosed
printlit """EOF