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

297
src/grammar.json vendored
View File

@ -601,105 +601,6 @@
] ]
} }
}, },
"bracket_command": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "REPEAT1",
"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": "STRING",
"value": "]"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "[["
},
{
"type": "REPEAT1",
"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": "STRING",
"value": "]]"
}
]
}
]
},
"command": { "command": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 0, "value": 0,
@ -729,8 +630,35 @@
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL", "type": "CHOICE",
"name": "_expression" "members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "=~"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "regex"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
]
}
]
} }
}, },
{ {
@ -760,6 +688,130 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "_expression" "name": "_expression"
}, },
"bracket_command": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "REPEAT1",
"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": "STRING",
"value": "]"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "[["
},
{
"type": "REPEAT1",
"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": "STRING",
"value": "]]"
}
]
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "file_redirect"
},
{
"type": "SYMBOL",
"name": "heredoc_redirect"
},
{
"type": "SYMBOL",
"name": "herestring_redirect"
}
]
}
}
]
},
"variable_assignment": { "variable_assignment": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -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", "type": "REPEAT",
"content": { "content": {
@ -1480,10 +1565,6 @@
"type": "STRING", "type": "STRING",
"value": "%" "value": "%"
}, },
{
"type": "STRING",
"value": "/"
},
{ {
"type": "STRING", "type": "STRING",
"value": "-" "value": "-"
@ -1662,7 +1743,11 @@
}, },
"regex": { "regex": {
"type": "PATTERN", "type": "PATTERN",
"value": "\\S+" "value": "([^\\s]|\\\\.)+"
},
"regex_without_right_brace": {
"type": "PATTERN",
"value": "([^\\s}]|\\\\.)+"
}, },
"_terminator": { "_terminator": {
"type": "CHOICE", "type": "CHOICE",

153296
src/parser.c vendored

File diff suppressed because it is too large Load Diff