shithub: rgbds

Download patch

ref: a727a0f81f0e56706e13f1ee860116090d566564
parent: 7a587eb7d624d717d4af44682f59c4c39fc83392
author: Rangi <[email protected]>
date: Tue Apr 20 05:25:27 EDT 2021

Capture termination status is equivalent to not having reached EOF

This avoids the need for a separate `terminated` flag

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -2341,9 +2341,8 @@
 	capture->lineNo = lexer_GetLineNo();
 
 	char *captureStart = startCapture();
-	bool terminated = false;
 	unsigned int level = 0;
-	int c;
+	int c = EOF;
 
 	/*
 	 * Due to parser internals, it reads the EOL after the expression before calling this.
@@ -2373,7 +2372,6 @@
 					 * We know we have read exactly "ENDR", not e.g. an EQUS
 					 */
 					lexerState->captureSize -= strlen("ENDR");
-					terminated = true;
 					goto finish;
 				}
 				level--;
@@ -2401,7 +2399,9 @@
 	lexerState->disableMacroArgs = false;
 	lexerState->disableInterpolation = false;
 	lexerState->atLineStart = false;
-	return terminated;
+
+	/* Returns true if an ENDR terminated the block, false if it reached EOF first */
+	return c != EOF;
 }
 
 bool lexer_CaptureMacroBody(struct CaptureBody *capture)
@@ -2409,8 +2409,7 @@
 	capture->lineNo = lexer_GetLineNo();
 
 	char *captureStart = startCapture();
-	bool terminated = false;
-	int c;
+	int c = EOF;
 
 	/* If the file is `mmap`ed, we need not to unmap it to keep access to the macro */
 	if (lexerState->isMmapped)
@@ -2437,7 +2436,6 @@
 				 * We know we have read exactly "ENDM", not e.g. an EQUS
 				 */
 				lexerState->captureSize -= strlen("ENDM");
-				terminated = true;
 				goto finish;
 			}
 		}
@@ -2463,5 +2461,7 @@
 	lexerState->disableMacroArgs = false;
 	lexerState->disableInterpolation = false;
 	lexerState->atLineStart = false;
-	return terminated;
+
+	/* Returns true if an ENDM terminated the block, false if it reached EOF first */
+	return c != EOF;
 }