shithub: rgbds

Download patch

ref: 8f287eeef94454eafe411a168f53bc5f606bab02
parent: 3a1b47129ef80e6344e90303bae55f53b57b6e74
author: dbrotz <43593771+dbrotz@users.noreply.github.com>
date: Thu Aug 29 08:37:59 EDT 2019

Fix nested if statements that don't have following whitespace
When trying to skip over nested if statements, if there was no whitespace
after an "if", then that "if" would not be recognized. That's a problem since
"if(" and "if{" are also valid ways to start an if statement. This change
will make it so that they are recognized correctly.

--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -9,6 +9,7 @@
 %{
 #include <ctype.h>
 #include <errno.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -289,16 +290,21 @@
 	yyskipbytes(ulNewMacroSize + 4);
 }
 
+static bool endsIf(char c)
+{
+	return isWhiteSpace(c) || c == '(' || c == '{';
+}
+
 static uint32_t isIf(char *s)
 {
 	return (strncasecmp(s, "IF", 2) == 0)
-		&& isWhiteSpace(s[-1]) && isWhiteSpace(s[2]);
+		&& isWhiteSpace(s[-1]) && endsIf(s[2]);
 }
 
 static uint32_t isElif(char *s)
 {
 	return (strncasecmp(s, "ELIF", 4) == 0)
-		&& isWhiteSpace(s[-1]) && isWhiteSpace(s[4]);
+		&& isWhiteSpace(s[-1]) && endsIf(s[4]);
 }
 
 static uint32_t isElse(char *s)
--- /dev/null
+++ b/test/asm/nested-if.asm
@@ -1,0 +1,18 @@
+if 0
+	if(1)
+	endc
+	if 1
+	endc
+	if{x}
+	endc
+endc
+
+if 1
+else
+	if(1)
+	endc
+	if 1
+	endc
+	if{x}
+	endc
+endc