Skip to content

Commit

Permalink
replace command_call with left associativity (Wilfred#2)
Browse files Browse the repository at this point in the history
This fits the definition of how command call is evaluated perfectly!
  • Loading branch information
alaviss authored Aug 28, 2022
1 parent 20c0878 commit 5976424
Show file tree
Hide file tree
Showing 3 changed files with 3,553 additions and 3,165 deletions.
22 changes: 8 additions & 14 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ module.exports = grammar({

extras: $ => [' ', $._spaces_before_comment, $.comment],

conflicts: $ => [
[$._expression_argument_list, $._command_argument_list]
],

rules: {
source_file: $ => seq(
$._indent_start,
Expand All @@ -64,8 +60,7 @@ module.exports = grammar({

_statement: $ => choice(
$._declaration,
$._expression,
alias($._command_call, $.call)
$._expression
),

_command_call: $ => seq(
Expand Down Expand Up @@ -186,15 +181,12 @@ module.exports = grammar({

call: $ => seq(
field('function', $.identifier),
field('arguments', $._expression_argument_list)
field('arguments', $.argument_list)
),

_expression_argument_list: $ => alias(
choice(
$._paren_argument_list,
$._expression
),
$.argument_list
argument_list: $ => choice(
$._paren_argument_list,
$._command_argument_list
),

_paren_argument_list: $ => seq(
Expand All @@ -203,7 +195,9 @@ module.exports = grammar({
')'
),

_command_argument_list: $ => repeatSepInd1($, ',', $._expression),
_command_argument_list: $ => prec.left(
repeatSepInd1($, ',', $._expression)
),

_literal: $ => choice(
$.boolean_literal,
Expand Down
129 changes: 57 additions & 72 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_command_call"
},
"named": true,
"value": "call"
}
]
},
Expand Down Expand Up @@ -890,28 +881,23 @@
"name": "arguments",
"content": {
"type": "SYMBOL",
"name": "_expression_argument_list"
"name": "argument_list"
}
}
]
},
"_expression_argument_list": {
"type": "ALIAS",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_paren_argument_list"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
},
"named": true,
"value": "argument_list"
"argument_list": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_paren_argument_list"
},
{
"type": "SYMBOL",
"name": "_command_argument_list"
}
]
},
"_paren_argument_list": {
"type": "SEQ",
Expand Down Expand Up @@ -977,46 +963,50 @@
]
},
"_command_argument_list": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_indent_ge"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_indent_ge"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
}
}
]
]
}
},
"_literal": {
"type": "CHOICE",
Expand Down Expand Up @@ -2001,12 +1991,7 @@
"name": "comment"
}
],
"conflicts": [
[
"_expression_argument_list",
"_command_argument_list"
]
],
"conflicts": [],
"precedences": [],
"externals": [
{
Expand Down
Loading

0 comments on commit 5976424

Please sign in to comment.