Skip to content

Commit

Permalink
Move non-parametric rules from block_body_rules
Browse files Browse the repository at this point in the history
Move pipe_element and pipe_element_last away from block_body_rules
because they do not depend on terminator parameter
  • Loading branch information
NotLebedev committed Aug 25, 2023
1 parent e6d2a14 commit 29f5222
Show file tree
Hide file tree
Showing 3 changed files with 47,726 additions and 47,724 deletions.
44 changes: 23 additions & 21 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,28 @@ module.exports = grammar({
KEYWORD().return,
),

/// Pipelines

pipe_element: $ => seq(
choice(
prec.right(69, $._expression),
$._ctrl_expression,
$.where_command,
$.command,
),
// Allow for empty pipeline elements like `ls | | print`
repeat1(seq(
optional('\n'),
PUNC().pipe,
)),
),

pipe_element_last: $ => choice(
prec.right(69, $._expression),
$._ctrl_expression,
$.where_command,
$.command,
),

/// Scope Statements

Expand Down Expand Up @@ -955,6 +977,7 @@ function block_body_rules(suffix, terminator) {
return alias($[rule_name + suffix], $[rule_name])
}
}

return {
['_block_body_statement' + suffix]: $ => choice(
$['_declaration' + suffix],
Expand Down Expand Up @@ -1026,27 +1049,6 @@ function block_body_rules(suffix, terminator) {
alias($.pipe_element_last, $.pipe_element),
terminator($),
)),

pipe_element: $ => seq(
choice(
prec.right(69, $._expression),
$._ctrl_expression,
$.where_command,
$.command,
),
// Allow for empty pipeline elements like `ls | | print`
repeat1(seq(
optional('\n'),
PUNC().pipe,
)),
),

pipe_element_last: $ => choice(
prec.right(69, $._expression),
$._ctrl_expression,
$.where_command,
$.command,
),
}
}

Expand Down
158 changes: 79 additions & 79 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,85 +302,6 @@
]
}
},
"pipe_element": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "PREC_RIGHT",
"value": 69,
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "SYMBOL",
"name": "_ctrl_expression"
},
{
"type": "SYMBOL",
"name": "where_command"
},
{
"type": "SYMBOL",
"name": "command"
}
]
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "|"
}
]
}
}
]
},
"pipe_element_last": {
"type": "CHOICE",
"members": [
{
"type": "PREC_RIGHT",
"value": 69,
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "SYMBOL",
"name": "_ctrl_expression"
},
{
"type": "SYMBOL",
"name": "where_command"
},
{
"type": "SYMBOL",
"name": "command"
}
]
},
"_block_body_statement_last": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -2662,6 +2583,85 @@
}
]
},
"pipe_element": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "PREC_RIGHT",
"value": 69,
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "SYMBOL",
"name": "_ctrl_expression"
},
{
"type": "SYMBOL",
"name": "where_command"
},
{
"type": "SYMBOL",
"name": "command"
}
]
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "\n"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "|"
}
]
}
}
]
},
"pipe_element_last": {
"type": "CHOICE",
"members": [
{
"type": "PREC_RIGHT",
"value": 69,
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "SYMBOL",
"name": "_ctrl_expression"
},
{
"type": "SYMBOL",
"name": "where_command"
},
{
"type": "SYMBOL",
"name": "command"
}
]
},
"stmt_source": {
"type": "SEQ",
"members": [
Expand Down
Loading

0 comments on commit 29f5222

Please sign in to comment.