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 re-export and unquoted string in list #70

Merged
merged 2 commits into from
Jan 19, 2024
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
18 changes: 18 additions & 0 deletions corpus/decl/module.nu
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ export module iter {}
(decl_module
(cmd_identifier)
(block)))

=====
module-004-re-export
=====

export module another.nu
export module 'other.nu'
export module others

----

(nu_script
(decl_module
(cmd_identifier))
(decl_module
(val_string))
(decl_module
(cmd_identifier)))
27 changes: 27 additions & 0 deletions corpus/expr/list.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=====
list-001-item-string
=====

[
unquoted
'single quoted'
"double quoted"
unquoted.nu
-u
-unquoted
--unquoted-string
]

-----

(nu_script
(pipeline
(pipe_element
(val_list
(val_string)
(val_string)
(val_string)
(val_string)
(val_string)
(val_string)
(val_string)))))
12 changes: 9 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = grammar({
[$.block, $.val_closure],
[$.ctrl_if_parenthesized],
[$.ctrl_try_parenthesized],
[$.decl_module],
],

rules: {
Expand Down Expand Up @@ -49,7 +50,7 @@ module.exports = grammar({
// for simplicity, i used the `rust` definition of an identifier and some symbols
// but in `nu` the rule is way more relaxed than this

cmd_identifier: ($) => token(/[_\p{XID_Start}][_\-\p{XID_Continue}!?]*/),
cmd_identifier: ($) => token(/[_\p{XID_Start}][_\-\p{XID_Continue}!?.]*/),

identifier: ($) => token(/[_\p{XID_Start}][_\p{XID_Continue}]*/),

Expand Down Expand Up @@ -101,7 +102,7 @@ module.exports = grammar({
optional(MODIFIER().visibility),
KEYWORD().module,
field("name", $._command_name),
field("body", $.block),
optional(field("body", $.block)),
),

decl_use: ($) =>
Expand Down Expand Up @@ -893,7 +894,12 @@ module.exports = grammar({
field(
"item",
seq(
choice($._expression, alias($.cmd_identifier, $.val_string)),
choice(
$._expression,
alias($.cmd_identifier, $.val_string),
alias($.short_flag, $.val_string),
alias($.long_flag, $.val_string),
),
optional(PUNC().comma),
),
),
Expand Down
43 changes: 36 additions & 7 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "[_\\p{XID_Start}][_\\-\\p{XID_Continue}!?]*"
"value": "[_\\p{XID_Start}][_\\-\\p{XID_Continue}!?.]*"
}
},
"identifier": {
Expand Down Expand Up @@ -1560,12 +1560,20 @@
}
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "block"
}
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "block"
}
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down Expand Up @@ -7580,6 +7588,24 @@
},
"named": true,
"value": "val_string"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "short_flag"
},
"named": true,
"value": "val_string"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "long_flag"
},
"named": true,
"value": "val_string"
}
]
},
Expand Down Expand Up @@ -8746,6 +8772,9 @@
],
[
"ctrl_try_parenthesized"
],
[
"decl_module"
]
],
"precedences": [],
Expand Down
2 changes: 1 addition & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@
"fields": {
"body": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "block",
Expand Down
Loading