Skip to content

Commit d48ab83

Browse files
committed
Globs
1 parent 1aff887 commit d48ab83

File tree

4 files changed

+784
-267
lines changed

4 files changed

+784
-267
lines changed

grammar.pegjs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ script "one or more statements separated by control operators"
55
spaceNL*
66

77
statement
8-
= statement:(command / conditionalLoop / ifBlock) space* next:chainedStatement?
8+
= statement:( command
9+
/ conditionalLoop
10+
/ ifBlock
11+
)
12+
space* next:chainedStatement?
913

1014
chainedStatement
1115
= operator:('&&' / '||') spaceNL* statement:statement
@@ -35,18 +39,22 @@ ifBlock
3539
elifBlock
3640
= "elif" spaceNL+ test:script "then" spaceNL+ body:script
3741

42+
condition
43+
= '[' test:script ']'
44+
3845
variableAssignment
3946
= writableVariableName '=' argument
4047

4148
commandName "command name"
42-
= !redirect !keyword name:concatenation
49+
= !redirect !keyword name:(concatenation / '[')
4350

4451
argument "command argument"
4552
= commandName
4653
/ commandSubstitution
4754

4855
concatenation
49-
= pieces:( bareword
56+
= pieces:( glob
57+
/ bareword
5058
/ environmentVariable
5159
/ variableSubstitution
5260
/ subshell
@@ -63,6 +71,14 @@ barewordChar
6371

6472
barewordMeta = [$"';&<>\n()\[\]*?|` ]
6573

74+
glob = (barewordChar* ('*' / '?' / characterRange / braceExpansion)+ barewordChar*)+
75+
76+
characterRange =
77+
$('[' !'-' . '-' !'-' . ']')
78+
79+
braceExpansion =
80+
(.? !'$') '{' barewordChar+ '}'
81+
6682
singleQuote = "'" inner:$([^']*) "'"
6783

6884
doubleQuote = '"' contents:(expandsInQuotes / doubleQuoteChar+)* '"'

overrides.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ rules.elifBlock = function (test, body) {
108108
}
109109
}
110110

111+
rules.condition = function (test) {
112+
return test
113+
}
114+
111115
rules.statement = function (statement, next) {
112116
if (next) {
113117
statement.control = next[0]
@@ -181,6 +185,13 @@ rules.writableVariableName = function () { return text() }
181185

182186
rules.bareword = function (cs) { return literal(cs) }
183187

188+
rules.glob = function (cs) {
189+
return {
190+
type: 'glob',
191+
pattern: text()
192+
}
193+
}
194+
184195
rules.escapedMetaChar = function (character) { return character }
185196

186197
rules.concatenation = function (pieces) {

0 commit comments

Comments
 (0)