Skip to content

Commit

Permalink
feat(grammar): better separation of enum/variant body, cases and case
Browse files Browse the repository at this point in the history
This allows for context base operations on the different elements. For
enums, this diviates slightly from the language spec where enum-case is
not defined while it is for variants.

As a side effect, this fixes highlighting for enums which was only
highlighting the first field properly.
  • Loading branch information
w31mann authored and liamwh committed Jul 4, 2024
1 parent 57e31a6 commit 7351db0
Show file tree
Hide file tree
Showing 7 changed files with 2,278 additions and 2,477 deletions.
17 changes: 11 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,10 @@ module.exports = grammar({
seq("variant", field("name", $.id), field("body", $.variant_body)),

variant_body: ($) =>
seq(
"{",
field("variant_cases", optionalCommaSeparatedList($.variant_case)),
"}",
),
seq("{", $.variant_cases, "}",),

variant_cases: ($) =>
commaSeparatedList($.variant_case),

variant_case: ($) =>
choice(
Expand All @@ -199,7 +198,13 @@ module.exports = grammar({
enum_items: ($) => seq("enum", field("name", $.id), $.enum_body),

enum_body: ($) =>
seq("{", field("enum_cases", optionalCommaSeparatedList($.id)), "}"),
seq("{", $.enum_cases, "}"),

enum_cases: ($) =>
commaSeparatedList($.enum_case),

enum_case: ($) =>
field("name", $.id),

resource_item: ($) =>
seq(
Expand Down
4 changes: 2 additions & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
(enum_items
name: (id) @type)

(enum_body
enum_cases: (id) @constant)
(enum_case
name: (id) @constant)

(resource_item
name: (id) @type)
Expand Down
156 changes: 74 additions & 82 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 58 additions & 22 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7351db0

Please sign in to comment.