diff --git a/src/asm/parser.y b/src/asm/parser.y index abf530dd..b46bc9d3 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -949,10 +949,14 @@ rept : T_POP_REPT uconst T_NEWLINE { } ; -for : T_POP_FOR T_ID T_COMMA for_args T_NEWLINE { +for : T_POP_FOR { + lexer_ToggleStringExpansion(false); + } T_ID { + lexer_ToggleStringExpansion(true); + } T_COMMA for_args T_NEWLINE { lexer_CaptureRept(&captureBody); } T_NEWLINE { - fstk_RunFor($2, $4.start, $4.stop, $4.step, captureBody.lineNo, + fstk_RunFor($3, $6.start, $6.stop, $6.step, captureBody.lineNo, captureBody.body, captureBody.size); } @@ -979,10 +983,14 @@ break : T_POP_BREAK T_NEWLINE { } ; -macrodef : T_POP_MACRO T_ID T_NEWLINE { +macrodef : T_POP_MACRO { + lexer_ToggleStringExpansion(false); + } T_ID { + lexer_ToggleStringExpansion(true); + } T_NEWLINE { lexer_CaptureMacroBody(&captureBody); } T_NEWLINE { - sym_AddMacro($2, captureBody.lineNo, captureBody.body, captureBody.size); + sym_AddMacro($3, captureBody.lineNo, captureBody.body, captureBody.size); } | T_LABEL T_COLON T_POP_MACRO T_NEWLINE { lexer_CaptureMacroBody(&captureBody); diff --git a/src/asm/rgbasm.5 b/src/asm/rgbasm.5 index 333e6c7b..a4e9cc2c 100644 --- a/src/asm/rgbasm.5 +++ b/src/asm/rgbasm.5 @@ -1094,7 +1094,7 @@ will treat it as a macro invocation. Furthermore, without the .Ql DEF keyword, -string equates may expanded for the name. +string symbols may be expanded for the name. This can lead to surprising results: .Bd -literal -offset indent X EQUS "Y" @@ -1118,6 +1118,7 @@ ENDM The example above defines .Ql MyMacro as a new macro. +String symbols are not expanded within the name of the macro. You may use the older syntax .Ql MyMacro: MACRO instead of @@ -1125,6 +1126,7 @@ instead of with a single colon .Ql \&: following the macro's name. +With the older syntax, string symbols may be expanded for the name. .Pp Macros can't be exported or imported. .Pp @@ -1632,6 +1634,7 @@ Everything between and the matching .Ic ENDR will be repeated for each value of a given symbol. +String symbols are not expanded within the symbol name. For example, this code will produce a table of squared values from 0 to 255: .Bd -literal -offset indent FOR N, 256 diff --git a/test/asm/for.asm b/test/asm/for.asm index e2cc5258..65a11634 100644 --- a/test/asm/for.asm +++ b/test/asm/for.asm @@ -33,7 +33,7 @@ endr println "-> {d:q}" s EQUS "x" -for s, 3, 30, 3 +for {s}, 3, 30, 3 print "{d:x} " endr println "-> {d:x}"