Skip to content

Commit

Permalink
Add support for extend primop
Browse files Browse the repository at this point in the history
Nickel has change some primops to contain a forward slash `/`, which
wasn't supported by the parser (they would be parsed as modulo instead).

This commit extend the `builtin` rule to accepts a larger class of valid
builtin names, including those new ones, and hopefully potential future
ones as well.
  • Loading branch information
yannham committed Jun 4, 2024
1 parent 9b15abb commit 71e702b
Show file tree
Hide file tree
Showing 6 changed files with 1,702 additions and 1,621 deletions.
10 changes: 8 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,15 @@ module.exports = grammar({
//grammar.lalrpop: 509
// Different from lalrpop grammar, we parse all possible builtins, not just
// the defined ones.
builtin: $ => seq(
builtin: _ => seq(
"%",
$.ident,
// We are a bit more liberal with what can go in a builtin function than
// for identifiers, because builtins are properly delimited by `%`.
// Upstream Nickel added `/` as a valid character already, so there's a
// precendent for extensions (although it's not very likely), so we try to
// be a bit future-proof. We just make sure the builtin starts with either
// a letter or an undescore, to ensure reasonable names.
/_*[a-zA-Z][a-zA-Z0-9./_'-]*/,
"%",
),

Expand Down
4 changes: 2 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1909,8 +1909,8 @@
"value": "%"
},
{
"type": "SYMBOL",
"name": "ident"
"type": "PATTERN",
"value": "_*[a-zA-Z][a-zA-Z0-9./_'-]*"
},
{
"type": "STRING",
Expand Down
12 changes: 1 addition & 11 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,7 @@
{
"type": "builtin",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "ident",
"named": true
}
]
}
"fields": {}
},
{
"type": "chunk_expr",
Expand Down
Loading

0 comments on commit 71e702b

Please sign in to comment.