aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/rc/syntax.y
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-10-19 10:53:45 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-10-19 10:53:45 -0700
commitaf3fa90e8bb41c306c5fe2d2cf105db6bbabd1d9 (patch)
tree807c8b5a18a1ff663808b5c369bf1262fdf03021 /sys/cmd/rc/syntax.y
parent47e3d475df6244a48b73421cd4210b64c392df8d (diff)
Feat: word operators and more robust crashing
Added the length and concatenate operators. Slightly improved the robustness on syntax errors.
Diffstat (limited to 'sys/cmd/rc/syntax.y')
-rw-r--r--sys/cmd/rc/syntax.y35
1 files changed, 24 insertions, 11 deletions
diff --git a/sys/cmd/rc/syntax.y b/sys/cmd/rc/syntax.y
index a580cb0..469260f 100644
--- a/sys/cmd/rc/syntax.y
+++ b/sys/cmd/rc/syntax.y
@@ -1,5 +1,5 @@
-%token Tword Tif Telse Tbang
-%token Targs
+%token Tword Twords Tif Telse Tbang
+%token Targs Tindex
%token Tbasic Tparen Tblock
%define parse.error verbose
@@ -12,18 +12,18 @@
%}
/* operator precendence: lowest first */
-%right Telse
-%left Twhile
+%left Twhile Telse
%left '\n'
%left Tbang
-%right '$'
+%right '$' Tcount Tflat
+%right Tindex
/* semantic types */
%union{
struct Tree *tree;
}
%type<tree> line cmds cmdsln body paren block ifbody assign;
-%type<tree> cmd basic executable nonkeyword keyword word atom arg args;
+%type<tree> cmd basic executable nonkeyword keyword word words wordsnl atom arg args;
%type<tree> Tbang;
%type<tree> Tword Tif Telse;
@@ -74,21 +74,21 @@ cmd:
basic:
executable
-| basic word { $$ = maketree2(Targs, $1, $2); }
+| basic word { $$ = maketree2(Targs, $1, $2); }
arg: word
args:
arg
-| args arg { $$ = maketree2(Targs, $1, $2); }
+| args arg { $$ = maketree2(Targs, $1, $2); }
atom:
nonkeyword
-| keyword { $$ = maketree1(Tword, $1); }
+| keyword { $$ = maketree1(Tword, $1); }
word:
atom
-| word '^' atom { $$ = maketree2('^', $1, $3); }
+| word '^' atom { $$ = maketree2('^', $1, $3); }
executable:
nonkeyword
@@ -96,11 +96,24 @@ executable:
nonkeyword:
Tword
-| '$' atom { $$ = maketree1('$', $2); }
+| '$' atom { $$ = maketree1('$', $2); }
+| '(' wordsnl ')' { $$ = $2; }
+| Tcount atom { $$ = maketree1(Tcount, $2); }
+| Tflat atom { $$ = maketree1(Tflat, $2); }
+//| '`' block { $$ = maketree1('`', $2); }
keyword:
Tif|Telse
+words:
+/* empty */ { $$ = nil; }
+| words word { $$ = maketree2(Twords, $1, $2); }
+
+wordsnl:
+/* empty */ { $$ = nil; }
+| wordsnl '\n' /* empty */
+| wordsnl word {$$ = (!$1) ? ((!$2) ? nil : $2) : ((!$2) ? $1 : maketree2(Twords, $1, $2)); }
+
nl:
/*empty*/
| nl '\n'