summary refs log tree commit diff
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
commit3b9ead6dd5043117e05e28b833b10bb589fcf9a5 (patch)
treec8cde1bebb6e346f218431d4d89661ec19b27649
parentHandle negative inputs to deg (diff)
downloadsrc-3b9ead6dd5043117e05e28b833b10bb589fcf9a5.tar.gz
src-3b9ead6dd5043117e05e28b833b10bb589fcf9a5.zip
Fix (hopefully) matching shell reserved words
To not conflict with matching closing command substitution parentheses
on their own lines.
-rw-r--r--bin/sh.l28
1 files changed, 14 insertions, 14 deletions
diff --git a/bin/sh.l b/bin/sh.l
index fcd5ce35..b27ecebc 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; }
 
c28c323a8eced868fd49050d7f&follow=1'>Rename project to catsitJune McEnroe 2020-08-15Use only LOG_NOTICE and LOG_WARNINGJune McEnroe 2020-08-15Make log messages consistentJune McEnroe 2020-08-15Remove closelog callJune McEnroe 2020-08-15Implement service statusJune McEnroe 2020-08-15Parse control commandsJune McEnroe 2020-08-15Read service pipesJune McEnroe 2020-08-15Implement non-blocking line-buffered readingJune McEnroe 2020-08-15Generate tags fileJune McEnroe 2020-08-15Just use CLOCK_MONOTONIC and clean up includesJune McEnroe 2020-08-15Reap childrenJune McEnroe 2020-08-14Implement serviceSignal, serviceStop, serviceRestartJune McEnroe 2020-08-14Reset restartInterval and restartDeadline on startJune McEnroe 2020-08-14Switch to timespec for timeoutsJune McEnroe 2020-08-14Implement serviceStartJune McEnroe 2020-08-14Flesh out Service structJune McEnroe 2020-08-14Build environment for servicesJune McEnroe 2020-08-14Implement spawntab parsingJune McEnroe 2020-08-14Open syslog, daemonize, write PIDJune McEnroe 2020-08-14Implement user and group lookupJune McEnroe 2020-08-14Add install targetJune McEnroe 2020-08-14Add spawnd skeletonJune McEnroe