summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-06-10 21:54:10 -0400
committerJune McEnroe <june@causal.agency>2022-06-10 21:57:20 -0400
commit9298fe810211ea3cd5bf6fdbb76b115f28ae2491 (patch)
tree71dcd2a48854a1d69af1204c9c0ade9b5ede2b14 /bin
parentSwitch to jorts Install script (diff)
downloadsrc-9298fe810211ea3cd5bf6fdbb76b115f28ae2491.tar.gz
src-9298fe810211ea3cd5bf6fdbb76b115f28ae2491.zip
Handle subshells (and functions) inside substitutions
Diffstat (limited to '')
-rw-r--r--bin/sh.l12
1 files changed, 10 insertions, 2 deletions
diff --git a/bin/sh.l b/bin/sh.l
index f26e3feb..8f0f7723 100644
--- a/bin/sh.l
+++ b/bin/sh.l
@@ -36,7 +36,7 @@ static int pop(void) {
 }
 %}
 
-%s Param Command Arith Backtick
+%s Param Command Arith Backtick Subshell
 %x DQuote HereDocDel HereDoc HereDocLit
 
 word [[:alnum:]_.-]+
@@ -51,7 +51,7 @@ reserved [!{}]|else|do|elif|for|done|fi|then|until|while|if|case|esac
 
 "\\". { return Escape; }
 
-<INITIAL,DQuote,HereDoc,Param,Command,Arith>{
+<INITIAL,DQuote,HereDoc,Param,Command,Arith,Subshell>{
 	"$"[*@#?$!0-9-] |
 	"$"[_[:alpha:][_[:alnum:]]* |
 	"${"[#]?{param}"}" {
@@ -73,6 +73,10 @@ reserved [!{}]|else|do|elif|for|done|fi|then|until|while|if|case|esac
 		BEGIN(push(Backtick));
 		return Subst;
 	}
+	"(" {
+		BEGIN(push(Subshell));
+		return Normal;
+	}
 }
 <Param>"}" |
 <Command>")" |
@@ -81,6 +85,10 @@ reserved [!{}]|else|do|elif|for|done|fi|then|until|while|if|case|esac
 	BEGIN(pop());
 	return Subst;
 }
+<Subshell>")" {
+	BEGIN(pop());
+	return Normal;
+}
 
 "\n" {
 	first = true;