From 3b9ead6dd5043117e05e28b833b10bb589fcf9a5 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 19 Feb 2021 21:30:07 -0500 Subject: Fix (hopefully) matching shell reserved words To not conflict with matching closing command substitution parentheses on their own lines. --- bin/sh.l | 28 ++++++++++++++-------------- 1 file 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 +#include #include #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; } -{ +{ "$"[*@#?$!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; } -{ - [[: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; } } -"#".* { return Comment; } +"#".* { return Comment; } -{word} { return Normal; } +{word} { + first = false; + return Normal; +} .|\n { return Normal; } -- cgit 1.4.1