Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of export const #38

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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