shithub: rgbds

Download patch

ref: fad48326f833b7b282d76d1b79f0dc3b3ecc8d04
parent: e7d6ddf5935196c598165afecdeac035a106dc17
author: Rangi <[email protected]>
date: Wed Feb 17 11:30:03 EST 2021

Support /* block comments */ in macro arguments

Fixes #746

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -903,7 +903,7 @@
 				char const *str = readMacroArg(c);
 
 				/*
-				 * If the argument is an empty string, it cannot be
+				 * If the macro arg is an empty string, it cannot be
 				 * expanded, so skip it and keep peeking.
 				 */
 				if (!str[0]) {
@@ -2163,6 +2163,16 @@
 			yylval.tzString[i] = '\0';
 			dbgPrint("Read raw string \"%s\"\n", yylval.tzString);
 			return T_STRING;
+
+		case '/': /* Block comments inside macro args */
+			shiftChars(1); /* Shift the slash */
+			if (peek(0) == '*') {
+				shiftChars(1);
+				discardBlockComment();
+				continue;
+			}
+			append_yylval_tzString(c); /* Append the slash */
+			break;
 
 		case '\\': /* Character escape */
 			shiftChars(1); /* Shift the backslash */
--- /dev/null
+++ b/test/asm/macro-arguments.asm
@@ -1,0 +1,16 @@
+mac: MACRO
+	println "'mac \#':"
+	for i, _NARG
+		println strfmt("\\%d: <\1>", i+1)
+		shift
+	endr
+	println
+ENDM
+
+	mac /* block
+		...comment */ ; comment
+	mac /*a*/ 1 , 2 /*b*/
+	mac \
+	c, d
+	mac 1, 2 + /* another ;
+		; comment */ 2, 3
--- /dev/null
+++ b/test/asm/macro-arguments.out
@@ -1,0 +1,15 @@
+'mac ':
+
+'mac  1,2':
+\1: < 1>
+\2: <2>
+
+'mac 	c,d':
+\1: <	c>
+\2: <d>
+
+'mac 1,2 +  2,3':
+\1: <1>
+\2: <2 +  2>
+\3: <3>
+