From 1b43cc7aed8a4062ee1ed779ad4d1fcba1d4f894 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 10 Jun 2022 21:54:10 -0400 Subject: Handle subshells (and functions) inside substitutions --- bin/sh.l | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/sh.l b/bin/sh.l index 9664b009..8f0f7723 100644 --- a/bin/sh.l +++ b/bin/sh.l @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 C. McEnroe +/* Copyright (C) 2021 June McEnroe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -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; } -{ +{ "$"[*@#?$!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; + } } "}" | ")" | @@ -81,6 +85,10 @@ reserved [!{}]|else|do|elif|for|done|fi|then|until|while|if|case|esac BEGIN(pop()); return Subst; } +")" { + BEGIN(pop()); + return Normal; +} "\n" { first = true; -- cgit 1.4.1