File tree Expand file tree Collapse file tree 4 files changed +784
-267
lines changed Expand file tree Collapse file tree 4 files changed +784
-267
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,11 @@ script "one or more statements separated by control operators"
5
5
spaceNL *
6
6
7
7
statement
8
- = statement :(command / conditionalLoop / ifBlock ) space * next :chainedStatement ?
8
+ = statement :( command
9
+ / conditionalLoop
10
+ / ifBlock
11
+ )
12
+ space * next :chainedStatement ?
9
13
10
14
chainedStatement
11
15
= operator :('&&' / '||' ) spaceNL * statement :statement
@@ -35,18 +39,22 @@ ifBlock
35
39
elifBlock
36
40
= "elif" spaceNL + test :script "then" spaceNL + body :script
37
41
42
+ condition
43
+ = '[' test :script ']'
44
+
38
45
variableAssignment
39
46
= writableVariableName '=' argument
40
47
41
48
commandName "command name"
42
- = ! redirect ! keyword name :concatenation
49
+ = ! redirect ! keyword name :( concatenation / '[' )
43
50
44
51
argument "command argument"
45
52
= commandName
46
53
/ commandSubstitution
47
54
48
55
concatenation
49
- = pieces :( bareword
56
+ = pieces :( glob
57
+ / bareword
50
58
/ environmentVariable
51
59
/ variableSubstitution
52
60
/ subshell
@@ -63,6 +71,14 @@ barewordChar
63
71
64
72
barewordMeta = [$"';&<>\n ()\[\] *?|` ]
65
73
74
+ glob = (barewordChar * ('*' / '?' / characterRange / braceExpansion )+ barewordChar * )+
75
+
76
+ characterRange =
77
+ $('[' ! '-' . '-' ! '-' . ']' )
78
+
79
+ braceExpansion =
80
+ (.? ! '$' ) '{' barewordChar + '}'
81
+
66
82
singleQuote = "'" inner :$([^']* ) "'"
67
83
68
84
doubleQuote = '"' contents :(expandsInQuotes / doubleQuoteChar + )* '"'
Original file line number Diff line number Diff line change @@ -108,6 +108,10 @@ rules.elifBlock = function (test, body) {
108
108
}
109
109
}
110
110
111
+ rules . condition = function ( test ) {
112
+ return test
113
+ }
114
+
111
115
rules . statement = function ( statement , next ) {
112
116
if ( next ) {
113
117
statement . control = next [ 0 ]
@@ -181,6 +185,13 @@ rules.writableVariableName = function () { return text() }
181
185
182
186
rules . bareword = function ( cs ) { return literal ( cs ) }
183
187
188
+ rules . glob = function ( cs ) {
189
+ return {
190
+ type : 'glob' ,
191
+ pattern : text ( )
192
+ }
193
+ }
194
+
184
195
rules . escapedMetaChar = function ( character ) { return character }
185
196
186
197
rules . concatenation = function ( pieces ) {
You can’t perform that action at this time.
0 commit comments