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,

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": {
"type": "PREC_LEFT",
"value": 0,
@ -729,8 +630,35 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_expression"
"type": "CHOICE",
"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",
"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": {
"type": "SEQ",
"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",
"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