Skip to content

Commit

Permalink
Fix assignment with pipeline as rhs (#135)
Browse files Browse the repository at this point in the history
This PR fixes #121 
Related test cases reverted to pre #28 state, which is more aligned with
current nushell language.
  • Loading branch information
blindFS authored Nov 7, 2024
1 parent 60de625 commit 24f9e41
Show file tree
Hide file tree
Showing 5 changed files with 403,648 additions and 445,714 deletions.
52 changes: 27 additions & 25 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,28 +683,6 @@ module.exports = grammar({
BRACK().close_brack,
),

/// Assignment Statement

assignment: ($) => {
const opr = [
PUNC().eq,
OPR().assign_add,
OPR().assign_sub,
OPR().assign_mul,
OPR().assign_div,
OPR().assign_append,
];

return prec.left(
PREC().assignment,
seq(
field("lhs", $.val_variable),
field("opr", choice(...opr)),
field("rhs", $._expression),
),
);
},

/// Block

block: ($) =>
Expand Down Expand Up @@ -1433,7 +1411,7 @@ function _block_body_rules(suffix) {

["stmt_let" + suffix]: (/** @type {{ [x: string]: RuleOrLiteral; }} */ $) =>
prec.right(
1,
PREC().assignment,
seq(
choice(KEYWORD().let, KEYWORD().let_env),
$["_assignment_pattern" + suffix],
Expand All @@ -1447,14 +1425,19 @@ function _block_body_rules(suffix) {
/** @type {{ [x: string]: RuleOrLiteral; }} */ $,
) =>
prec.right(
1,
PREC().assignment,
seq(
optional(MODIFIER().visibility),
KEYWORD().const,
$["_assignment_pattern" + suffix],
),
),

["assignment" + suffix]: (
/** @type {{ [x: string]: RuleOrLiteral; }} */ $,
) =>
prec.right(PREC().assignment, $["_mutable_assignment_pattern" + suffix]),

["_assignment_pattern" + suffix]: (
/** @type {{ [x: string]: string; _variable_name?: any; param_type?: any; }} */ $,
) =>
Expand All @@ -1465,6 +1448,25 @@ function _block_body_rules(suffix) {
field("value", alias_for_suffix($, "pipeline", suffix)),
),

["_mutable_assignment_pattern" + suffix]: (
/** @type {{ [x: string]: string; _variable_name?: any; param_type?: any; }} */ $,
) =>
seq(
field("lhs", $.val_variable),
field(
"opr",
choice(
PUNC().eq,
OPR().assign_add,
OPR().assign_sub,
OPR().assign_mul,
OPR().assign_div,
OPR().assign_append,
),
),
field("rhs", alias_for_suffix($, "pipeline", suffix)),
),

/// Statements

["_statement" + suffix]: (
Expand All @@ -1476,7 +1478,7 @@ function _block_body_rules(suffix) {
$._stmt_overlay,
$.stmt_register,
$.stmt_source,
$.assignment,
alias_for_suffix($, "assignment", suffix),
alias_for_suffix($, "stmt_let", suffix),
alias_for_suffix($, "stmt_mut", suffix),
alias_for_suffix($, "stmt_const", suffix),
Expand Down
Loading

0 comments on commit 24f9e41

Please sign in to comment.