summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-02-19 21:30:07 -0500
committerJune McEnroe <june@causal.agency>2021-02-19 21:30:07 -0500
commit0b7a3c0c25a0ff85f83c4b6c7ae03b75d87b702c (patch)
tree71806f2a4ac0dcb115fe118f7e64b6aa68822ed6 /bin
parentHandle negative inputs to deg (diff)
downloadsrc-0b7a3c0c25a0ff85f83c4b6c7ae03b75d87b702c.tar.gz
src-0b7a3c0c25a0ff85f83c4b6c7ae03b75d87b702c.zip
Fix (hopefully) matching shell reserved words
To not conflict with matching closing command substitution parentheses
on their own lines.
Diffstat (limited to 'bin')
-rw-r--r--bin/sh.l28
1 files changed, 14 insertions, 14 deletions
diff --git a/bin/sh.l b/bin/sh.l
index 4579adbe..9fc241da 100644
--- a/bin/sh.l
+++ b/bin/sh.l
@@ -19,6 +19,7 @@
 
 %{
 #include <assert.h>
+#include <stdbool.h>
 #include <string.h>
 #include "hilex.h"
 
@@ -35,7 +36,6 @@ static int pop(void) {
 }
 %}
 
-%s First
 %s Param Command Arith Backtick
 %x DQuote HereDocDel HereDoc HereDocLit
 
@@ -44,13 +44,14 @@ param [^:=?+%#{}-]+
 reserved [!{}]|else|do|elif|for|done|fi|then|until|while|if|case|esac
 
 %%
+	static bool first;
 	static char *delimiter;
 
 [[:blank:]]+ { return Normal; }
 
 "\\". { return Escape; }
 
-<INITIAL,First,DQuote,HereDoc,Param,Command,Arith>{
+<INITIAL,DQuote,HereDoc,Param,Command,Arith>{
 	"$"[*@#?$!0-9-] |
 	"$"[_[:alpha:][_[:alnum:]]* |
 	"${"[#]?{param}"}" {
@@ -82,27 +83,23 @@ reserved [!{}]|else|do|elif|for|done|fi|then|until|while|if|case|esac
 }
 
 "\n" {
-	BEGIN(push(First));
+	first = true;
 	return Normal;
 }
 [&();|]|"&&"|";;"|"||" {
-	BEGIN(push(First));
+	first = true;
 	return Operator;
 }
 [0-9]?([<>]"&"?|">|"|">>"|"<>") {
 	return Operator;
 }
 
-<First>{
-	[[:blank:]]+ { return Normal; }
-	{reserved} {
-		BEGIN(pop());
+{reserved} {
+	if (first) {
+		first = false;
 		return Keyword;
 	}
-	{word} {
-		BEGIN(pop());
-		return Normal;
-	}
+	return Normal;
 }
 
 {word}/[[:blank:]]*"()" { return Ident; }
@@ -162,9 +159,12 @@ reserved [!{}]|else|do|elif|for|done|fi|then|until|while|if|case|esac
 	[^\\$`""]+|. { return String; }
 }
 
-<INITIAL,First,Command,Backtick,Arith>"#".* { return Comment; }
+<INITIAL,Command,Backtick,Arith>"#".* { return Comment; }
 
-{word} { return Normal; }
+{word} {
+	first = false;
+	return Normal;
+}
 
 .|\n { return Normal; }