Skip to content

Commit

Permalink
Merge pull request #38 from kit494way/fix-export-const
Browse files Browse the repository at this point in the history
Fix parsing of export const
  • Loading branch information
fdncred authored Dec 21, 2023
2 parents b0b330f + 80993e1 commit a0b80b2
Show file tree
Hide file tree
Showing 4 changed files with 130,759 additions and 130,493 deletions.
36 changes: 36 additions & 0 deletions corpus/stmt/const.nu
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,39 @@ const x = 42 | math sin
(command
(cmd_identifier)
(val_string))))))

=====
const-004-exported
=====

export const x = 42

----

(nu_script
(stmt_const
(identifier)
(pipeline
(pipe_element
(val_number)))))

=====
const-005-exported-multiple
=====

export const GAMMA = 0.5772156649015329
export const E = 2.718281828459045

----

(nu_script
(stmt_const
(identifier)
(pipeline
(pipe_element
(val_number))))
(stmt_const
(identifier)
(pipeline
(pipe_element
(val_number)))))
11 changes: 9 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ module.exports = grammar({
/// To correctly parse these situations distinct rules for different types of
/// statements are needed. These rules are differentiated by suffix, and only
/// difference between them is terminator parameter used in pipeline rule that
/// is terminating statements. This function automaticaly generates all rules
/// is terminating statements. This function automatically generates all rules
/// for a given terminator and names them with specified suffix.
function block_body_rules(suffix, terminator) {
function alias_for_suffix($, rule_name, suffix) {
Expand Down Expand Up @@ -995,7 +995,14 @@ function block_body_rules(suffix, terminator) {
prec.right(1, seq(KEYWORD().mut, $["_assignment_pattern" + suffix])),

["stmt_const" + suffix]: ($) =>
prec.right(1, seq(KEYWORD().const, $["_assignment_pattern" + suffix])),
prec.right(
1,
seq(
optional(MODIFIER().visibility),
KEYWORD().const,
$["_assignment_pattern" + suffix],
),
),

["_assignment_pattern" + suffix]: ($) =>
seq(
Expand Down
24 changes: 24 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "export"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "const"
Expand Down Expand Up @@ -444,6 +456,18 @@
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "export"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "const"
Expand Down
Loading

0 comments on commit a0b80b2

Please sign in to comment.