Skip to content

Commit

Permalink
Merge pull request #46 from nickel-lang/fix/enum-variant-types
Browse files Browse the repository at this point in the history
Add support for enum variant in types
  • Loading branch information
yannham authored Jun 4, 2024
2 parents da030eb + 170db27 commit 9b15abb
Show file tree
Hide file tree
Showing 7 changed files with 20,814 additions and 19,242 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ Cargo.lock
package-lock.json
target/
result*

# tree-sitter now generates a bunch of object files in the repository
*.a
*.so
*.o
*.pc
7 changes: 6 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ module.exports = grammar({
field("arg", $.record_operand),
)),

enum: $ => choice(
$.enum_tag,
$.enum_variant,
),

//grammar.lalrpop: 503
//See NOTE[scanner].
chunk_literal_single: $ => choice(
Expand Down Expand Up @@ -613,7 +618,7 @@ module.exports = grammar({
"_",
seq(
"[|",
field("rows", commaSep($.enum_tag)),
field("rows", commaSep($.enum)),
field("tail", optional(seq(";", $.ident))),
"|]",
),
Expand Down
17 changes: 15 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,19 @@
]
}
},
"enum": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "enum_tag"
},
{
"type": "SYMBOL",
"name": "enum_variant"
}
]
},
"chunk_literal_single": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -2558,7 +2571,7 @@
"members": [
{
"type": "SYMBOL",
"name": "enum_tag"
"name": "enum"
},
{
"type": "REPEAT",
Expand All @@ -2571,7 +2584,7 @@
},
{
"type": "SYMBOL",
"name": "enum_tag"
"name": "enum"
}
]
}
Expand Down
21 changes: 20 additions & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,25 @@
}
}
},
{
"type": "enum",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "enum_tag",
"named": true
},
{
"type": "enum_variant",
"named": true
}
]
}
},
{
"type": "enum_pattern",
"named": true,
Expand Down Expand Up @@ -1596,7 +1615,7 @@
"named": false
},
{
"type": "enum_tag",
"type": "enum",
"named": true
}
]
Expand Down
Loading

0 comments on commit 9b15abb

Please sign in to comment.