Skip to content

Commit

Permalink
Handle empty default value during variable expansion (#1)
Browse files Browse the repository at this point in the history
* Handle empty default value during variable expansion

* Make expression after colon optional

As suggested by @maxbrunsfeld
  • Loading branch information
mads-hartmann authored and Max Brunsfeld committed Feb 24, 2018
1 parent bda6939 commit 741cfce
Show file tree
Hide file tree
Showing 4 changed files with 9,387 additions and 8,962 deletions.
7 changes: 6 additions & 1 deletion corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ Variable expansions

echo ${abc}
echo ${abc:-def}
echo ${abc:- }
echo ${abc:
}

---

(program
(command (command_name (word)) (expansion (variable_name)))
(command (command_name (word)) (expansion (variable_name) (word))))
(command (command_name (word)) (expansion (variable_name) (word)))
(command (command_name (word)) (expansion (variable_name)))
(command (command_name (word)) (expansion (variable_name))))

===================================
Other variable expansion operators
Expand Down
2 changes: 1 addition & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ module.exports = grammar({
seq(
$._variable_name,
choice(':', ':?', '=', ':-', '%', '/'),
$._expression
optional($._expression)
)
),
'}'
Expand Down
12 changes: 10 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,16 @@
]
},
{
"type": "SYMBOL",
"name": "_expression"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "BLANK"
}
]
}
]
}
Expand Down
Loading

0 comments on commit 741cfce

Please sign in to comment.