ref: fe3521c7a4d8681fe68ea3b139761780c630a563
parent: b0f8d75d1dbabc354aafb56d9a3d37b99e9209c5
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Tue Apr 20 06:02:39 EDT 2021
Switch from parentheses to angle brackets `\(` is more likely to be a valid escape sequence in the future (as is `\[`) and `\{` is already taken.
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -717,10 +717,10 @@
static bool isMacroChar(char c)
{
- return c == '@' || c == '#' || c == '(' || (c >= '0' && c <= '9');
+ return c == '@' || c == '#' || c == '<' || (c >= '0' && c <= '9');
}
-/* forward declarations for readParentheticMacroArgNum */
+/* forward declarations for readBracketedMacroArgNum */
static int peek(void);
static void shiftChar(void);
static uint32_t readNumber(int radix, uint32_t baseValue);
@@ -727,9 +727,9 @@
static bool startsIdentifier(int c);
static bool continuesIdentifier(int c);
-static uint32_t readParentheticMacroArgNum(void)
+static uint32_t readBracketedMacroArgNum(void)
{
- dbgPrint("Reading parenthetic macro arg\n");
+ dbgPrint("Reading bracketed macro arg\n");
bool disableMacroArgs = lexerState->disableMacroArgs;
bool disableInterpolation = lexerState->disableInterpolation;
@@ -761,9 +761,9 @@
struct Symbol const *sym = sym_FindScopedSymbol(symName);
if (!sym)
- fatalerror("Parenthetic symbol \"%s\" does not exist\n", symName);
+ fatalerror("Bracketed symbol \"%s\" does not exist\n", symName);
else if (!sym_IsNumeric(sym))
- fatalerror("Parenthetic symbol \"%s\" is not numeric\n", symName);
+ fatalerror("Bracketed symbol \"%s\" is not numeric\n", symName);
num = sym_GetConstantSymValue(sym);
} else {
@@ -771,12 +771,12 @@
}
c = peek();
- if (c != ')')
- fatalerror("Invalid character in parenthetic macro argument %s\n", printChar(c));
+ if (c != '>')
+ fatalerror("Invalid character in bracketed macro argument %s\n", printChar(c));
else if (empty)
- fatalerror("Empty parenthetic macro argument\n");
+ fatalerror("Empty bracketed macro argument\n");
else if (num == 0)
- fatalerror("Invalid parenthetic macro argument '\\(0)'\n");
+ fatalerror("Invalid bracketed macro argument '\\<0>'\n");
shiftChar();
@@ -793,12 +793,12 @@
str = macro_GetUniqueIDStr();
} else if (name == '#') {
str = macro_GetAllArgs();
- } else if (name == '(') {
- uint32_t num = readParentheticMacroArgNum();
+ } else if (name == '<') {
+ uint32_t num = readBracketedMacroArgNum();
str = macro_GetArg(num);
if (!str)
- fatalerror("Macro argument '\\(%" PRIu32 ")' not defined\n", num);
+ fatalerror("Macro argument '\\<%" PRIu32 ">' not defined\n", num);
} else if (name == '0') {
fatalerror("Invalid macro argument '\\0'\n");
} else {
@@ -1569,7 +1569,7 @@
case '7':
case '8':
case '9':
- case '(':
+ case '<':
shiftChar();
char const *str = readMacroArg(c);
@@ -1715,7 +1715,7 @@
case '7':
case '8':
case '9':
- case '(':
+ case '<':
shiftChar();
char const *str = readMacroArg(c);
--- a/src/asm/rgbasm.5
+++ b/src/asm/rgbasm.5
@@ -1567,30 +1567,30 @@
does not need to be escaped because string literals also work as usual inside macro arguments.
.Pp
Since there are only nine digits, you can only access the first nine macro arguments like this.
-To use the rest, you need to put the multi-digit argument number in parentheses, like
-.Ql \[rs](10) .
-This parenthetic syntax supports decimal numbers and numeric symbol names.
+To use the rest, you need to put the multi-digit argument number in angle brackets, like
+.Ql \[rs]<10> .
+This bracketed syntax supports decimal numbers and numeric symbol names.
For example,
-.Ql \[rs](_NARG)
+.Ql \[rs]<_NARG>
will get the last argument.
.Pp
-Other macro arguments and symbol interpolations will be expanded inside the parentheses.
+Other macro arguments and symbol interpolations will be expanded inside the angle brackets.
For example, if
.Ql \[rs]1
is
.Ql 13 ,
then
-.Ql \[rs](\[rs]1)
+.Ql \[rs]<\[rs]1>
will expand to
-.Ql \[rs](13) .
+.Ql \[rs]<13> .
Or if
.Ql v10 = 42
and
.Ql x = 10 ,
then
-.Ql \[rs](v{d:x})
+.Ql \[rs]<v{d:x}>
will expand to
-.Ql \[rs](42) .
+.Ql \[rs]<42> .
.Pp
Another way to access more than nine macro arguments is the
.Ic SHIFT
--- /dev/null
+++ b/test/asm/bracketed-macro-args.asm
@@ -1,0 +1,19 @@
+MACRO printargs
+ PRINTLN "first = \<1>"
+ FOR I, 2, _NARG
+ PRINTLN "next = \<{d:I}>"
+ ENDR
+ PRINTLN "last = \<{d:_NARG}>"
+ENDM
+
+ printargs A, B, C, D
+
+MACRO mac
+ println \<2__> + \<1_2> + \<\1>
+x = 2
+ println \<{d:x}> + \<1_{d:x}> + \<\<\<13>>>
+y equs "NARG"
+ println \<x> + \<1_{d:x}_> + \<\<\<_{y}>>>
+ENDM
+
+ mac 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 1
--- /dev/null
+++ b/test/asm/bracketed-macro-args.out
@@ -1,0 +1,7 @@
+first = A
+next = B
+next = C
+last = D
+$F0
+$F0
+$F0
--- a/test/asm/invalid-empty-macro-arg.asm
+++ b/test/asm/invalid-empty-macro-arg.asm
@@ -1,1 +1,1 @@
-\()
+\<>
--- a/test/asm/invalid-empty-macro-arg.err
+++ b/test/asm/invalid-empty-macro-arg.err
@@ -1,2 +1,2 @@
FATAL: invalid-empty-macro-arg.asm(1):
- Empty parenthetic macro argument
+ Empty bracketed macro argument
--- a/test/asm/invalid-macro-arg-character.asm
+++ b/test/asm/invalid-macro-arg-character.asm
@@ -1,1 +1,1 @@
-\(10!)
+\<10!>
--- a/test/asm/invalid-macro-arg-character.err
+++ b/test/asm/invalid-macro-arg-character.err
@@ -1,2 +1,2 @@
FATAL: invalid-macro-arg-character.asm(1):
- Invalid character in parenthetic macro argument '!'
+ Invalid character in bracketed macro argument '!'
--- a/test/asm/invalid-macro-arg-symbol.asm
+++ b/test/asm/invalid-macro-arg-symbol.asm
@@ -1,1 +1,1 @@
-\(foo)
+\<foo>
--- a/test/asm/invalid-macro-arg-symbol.err
+++ b/test/asm/invalid-macro-arg-symbol.err
@@ -1,2 +1,2 @@
FATAL: invalid-macro-arg-symbol.asm(1):
- Parenthetic symbol "foo" does not exist
+ Bracketed symbol "foo" does not exist
--- a/test/asm/parenthetic-macro-args.asm
+++ /dev/null
@@ -1,19 +1,0 @@
-MACRO printargs
- PRINTLN "first = \(1)"
- FOR I, 2, _NARG
- PRINTLN "next = \({d:I})"
- ENDR
- PRINTLN "last = \({d:_NARG})"
-ENDM
-
- printargs A, B, C, D
-
-MACRO mac
- println \(2__) + \(1_2) + \(\1)
-x = 2
- println \({d:x}) + \(1_{d:x}) + \(\(\(13)))
-y equs "NARG"
- println \(x) + \(1_{d:x}_) + \(\(\(_{y})))
-ENDM
-
- mac 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 1
--- a/test/asm/parenthetic-macro-args.out
+++ /dev/null
@@ -1,7 +1,0 @@
-first = A
-next = B
-next = C
-last = D
-$F0
-$F0
-$F0
--- a/test/asm/quine.asm
+++ b/test/asm/quine.asm
@@ -1,6 +1,6 @@
MACRO N
FOR R,1,_NARG+1
-PRINT STRSUB("\n\"\\ PR1NT,ABCDEFGHIMnOSU2_+-()",\(R)+1,1)
+PRINT STRSUB("\n\"\\ PR1NT,ABCDEFGHIMnOSU2_+-()<>",\<R>+1,1)
ENDR
REPT R-2
PRINT"\1,"
@@ -8,4 +8,4 @@
ENDR
PRINT"\1\n"
ENDM
- N 19,10,12,5,21,3,7,0,15,21,5,3,5,9,6,9,25,7,10,5,16,26,6,0,4,5,18,7,8,3,22,8,5,22,23,11,28,1,2,20,2,1,2,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,1,9,2,28,5,29,26,6,9,6,29,0,14,7,13,5,0,5,14,4,8,3,5,27,24,0,4,5,18,7,8,1,2,6,9,1,0,22,17,18,15,8,0,14,7,13,5,0,4,5,18,7,8,1,2,6,2,20,1,0,14,7,13,19,0,3,7,3
+ N 19,10,12,5,21,3,7,0,15,21,5,3,5,9,6,9,25,7,10,5,16,26,6,0,4,5,18,7,8,3,22,8,5,22,23,11,28,1,2,20,2,1,2,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,1,9,2,30,5,31,26,6,9,6,29,0,14,7,13,5,0,5,14,4,8,3,5,27,24,0,4,5,18,7,8,1,2,6,9,1,0,22,17,18,15,8,0,14,7,13,5,0,4,5,18,7,8,1,2,6,2,20,1,0,14,7,13,19,0,3,7,3
--- a/test/asm/quine.out
+++ b/test/asm/quine.out
@@ -1,6 +1,6 @@
MACRO N
FOR R,1,_NARG+1
-PRINT STRSUB("\n\"\\ PR1NT,ABCDEFGHIMnOSU2_+-()",\(R)+1,1)
+PRINT STRSUB("\n\"\\ PR1NT,ABCDEFGHIMnOSU2_+-()<>",\<R>+1,1)
ENDR
REPT R-2
PRINT"\1,"
@@ -8,4 +8,4 @@
ENDR
PRINT"\1\n"
ENDM
- N 19,10,12,5,21,3,7,0,15,21,5,3,5,9,6,9,25,7,10,5,16,26,6,0,4,5,18,7,8,3,22,8,5,22,23,11,28,1,2,20,2,1,2,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,1,9,2,28,5,29,26,6,9,6,29,0,14,7,13,5,0,5,14,4,8,3,5,27,24,0,4,5,18,7,8,1,2,6,9,1,0,22,17,18,15,8,0,14,7,13,5,0,4,5,18,7,8,1,2,6,2,20,1,0,14,7,13,19,0,3,7,3
+ N 19,10,12,5,21,3,7,0,15,21,5,3,5,9,6,9,25,7,10,5,16,26,6,0,4,5,18,7,8,3,22,8,5,22,23,11,28,1,2,20,2,1,2,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,1,9,2,30,5,31,26,6,9,6,29,0,14,7,13,5,0,5,14,4,8,3,5,27,24,0,4,5,18,7,8,1,2,6,9,1,0,22,17,18,15,8,0,14,7,13,5,0,4,5,18,7,8,1,2,6,2,20,1,0,14,7,13,19,0,3,7,3