From 8f287eeef94454eafe411a168f53bc5f606bab02 Mon Sep 17 00:00:00 2001 From: dbrotz <43593771+dbrotz@users.noreply.github.com> Date: Thu, 29 Aug 2019 12:37:59 -0700 Subject: [PATCH] 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. --- src/asm/asmy.y | 10 ++++++++-- test/asm/nested-if.asm | 18 ++++++++++++++++++ test/asm/nested-if.out | 0 test/asm/nested-if.out.pipe | 0 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 test/asm/nested-if.asm create mode 100644 test/asm/nested-if.out create mode 100644 test/asm/nested-if.out.pipe diff --git a/src/asm/asmy.y b/src/asm/asmy.y index 7defba56..8cf48f8f 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -9,6 +9,7 @@ %{ #include #include +#include #include #include #include @@ -289,16 +290,21 @@ static void copymacro(void) 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) diff --git a/test/asm/nested-if.asm b/test/asm/nested-if.asm new file mode 100644 index 00000000..de34fb06 --- /dev/null +++ b/test/asm/nested-if.asm @@ -0,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 diff --git a/test/asm/nested-if.out b/test/asm/nested-if.out new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/nested-if.out.pipe b/test/asm/nested-if.out.pipe new file mode 100644 index 00000000..e69de29b