Skip to content

Commit

Permalink
Add support for enum variant in types
Browse files Browse the repository at this point in the history
Add support for enum variants inside static enum types, i.e. types of
the form `'<Tag> <Type>`, which were seemingly forgotten during the
update of the grammar for enum variants previously.
  • Loading branch information
yannham committed May 30, 2024
1 parent 0a796f3 commit 9d5b4c8
Show file tree
Hide file tree
Showing 5 changed files with 20,709 additions and 19,260 deletions.
15 changes: 9 additions & 6 deletions corpus/examples/record-contract.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,15 @@ let metadata_ = {
(record_operand
(atom
(type_atom
(enum_tag
(raw_enum_tag))
(enum_tag
(raw_enum_tag))
(enum_tag
(raw_enum_tag)))))))))
(enum
(enum_tag
(raw_enum_tag)))
(enum
(enum_tag
(raw_enum_tag)))
(enum
(enum_tag
(raw_enum_tag))))))))))
(annot_atom
(static_string
(chunk_literal_single
Expand Down
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 9d5b4c8

Please sign in to comment.