Allow redirects after bracket commands

This commit is contained in:
Max Brunsfeld 2018-03-01 10:42:20 -08:00
parent 0791027596
commit 51b212b207
3 changed files with 89256 additions and 64382 deletions

View File

@ -180,21 +180,6 @@ module.exports = grammar({
$._statement
)),
bracket_command: $ => {
const contents = repeat1(choice(
$._expression,
seq('=~', choice(
$.regex,
$._expression
))
))
return choice(
seq('[', contents, ']'),
seq('[[', contents, ']]')
)
},
// Commands
command: $ => prec.left(seq(
@ -203,7 +188,13 @@ module.exports = grammar({
$.file_redirect
)),
$.command_name,
repeat($._expression),
repeat(choice(
$._expression,
seq('=~', choice(
$.regex,
$._expression
))
)),
repeat(choice(
$.file_redirect,
$.heredoc_redirect,
@ -213,6 +204,28 @@ module.exports = grammar({
command_name: $ => $._expression,
bracket_command: $ => {
const args = repeat1(choice(
$._expression,
seq('=~', choice(
$.regex,
$._expression
))
))
return seq(
choice(
seq('[', args, ']'),
seq('[[', args, ']]')
),
repeat(choice(
$.file_redirect,
$.heredoc_redirect,
$.herestring_redirect
))
)
},
variable_assignment: $ => seq(
choice(
$.variable_name,

171
src/grammar.json vendored
View File

@ -601,7 +601,97 @@
]
}
},
"command": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "variable_assignment"
},
{
"type": "SYMBOL",
"name": "file_redirect"
}
]
}
},
{
"type": "SYMBOL",
"name": "command_name"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "=~"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "regex"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
]
}
]
}
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "file_redirect"
},
{
"type": "SYMBOL",
"name": "heredoc_redirect"
},
{
"type": "SYMBOL",
"name": "herestring_redirect"
}
]
}
}
]
}
},
"command_name": {
"type": "SYMBOL",
"name": "_expression"
},
"bracket_command": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
@ -700,39 +790,6 @@
}
]
},
"command": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "variable_assignment"
},
{
"type": "SYMBOL",
"name": "file_redirect"
}
]
}
},
{
"type": "SYMBOL",
"name": "command_name"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "REPEAT",
"content": {
@ -754,11 +811,6 @@
}
}
]
}
},
"command_name": {
"type": "SYMBOL",
"name": "_expression"
},
"variable_assignment": {
"type": "SEQ",
@ -1451,6 +1503,39 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "/"
}
}
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "regex_without_right_brace"
},
"named": true,
"value": "regex"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
@ -1480,10 +1565,6 @@
"type": "STRING",
"value": "%"
},
{
"type": "STRING",
"value": "/"
},
{
"type": "STRING",
"value": "-"
@ -1662,7 +1743,11 @@
},
"regex": {
"type": "PATTERN",
"value": "\\S+"
"value": "([^\\s]|\\\\.)+"
},
"regex_without_right_brace": {
"type": "PATTERN",
"value": "([^\\s}]|\\\\.)+"
},
"_terminator": {
"type": "CHOICE",

153296
src/parser.c vendored

File diff suppressed because it is too large Load Diff