Skip to content

Commit

Permalink
feat: add fields to class_decl, module_decl, interface_decl
Browse files Browse the repository at this point in the history
  • Loading branch information
joker1007 committed Dec 7, 2023
1 parent 5f29849 commit 3ede36e
Show file tree
Hide file tree
Showing 4 changed files with 5,354 additions and 4,786 deletions.
38 changes: 22 additions & 16 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,23 @@ module.exports = grammar({
class_decl: $ => choice(
seq(
"class",
$.class_name,
optional($.module_type_parameters),
optional($.superclass),
alias(repeat(choice($.member, $._nestable_decls)), $.members),
field("name", $.class_name),
field("type_parameters", optional($.module_type_parameters)),
field("superclass", optional($.superclass)),
field("body", alias(repeat(choice($.member, $._nestable_decls)), $.members)),
"end"
)
),

superclass: $ => seq("<", $.class_name, optional($.type_arguments)),
superclass: $ => seq("<", field("name", $.class_name), field("type_arguments", optional($.type_arguments))),

module_decl: $ => choice(
seq(
"module",
alias($.class_name, $.module_name),
optional($.module_type_parameters),
optional($.module_self_type_binds),
alias(repeat(choice($.member, $._nestable_decls)), $.members),
field("name", alias($.class_name, $.module_name)),
field("type_parameters", optional($.module_type_parameters)),
field("self_type_binds", optional($.module_self_type_binds)),
field("body", alias(repeat(choice($.member, $._nestable_decls)), $.members)),
"end"
)
),
Expand All @@ -227,15 +227,21 @@ module.exports = grammar({
seq($.interface_name, optional($.type_arguments), optional(seq(",", $.module_self_types))),
),

interface_decl: $ => seq("interface", $.interface_name, optional($.module_type_parameters), alias(repeat($.interface_member), $.interface_members), "end"),
interface_decl: $ => seq(
"interface",
field("name", $.interface_name),
field("type_parameters", optional($.module_type_parameters)),
field("body", alias(repeat($.interface_member), $.interface_members)),
"end"
),

interface_member: $ => seq(
alias(repeat($.annotation), $.annotations),
choice(
field("annotations", alias(repeat($.annotation), $.annotations)),
field("body", choice(
$.method_member,
$.include_member,
$.alias_member,
)
))
),

type_alias_decl: $ => seq("type", $.alias_name, optional($.module_type_parameters), "=", $.type),
Expand Down Expand Up @@ -331,8 +337,8 @@ module.exports = grammar({
),

member: $ => seq(
alias(repeat($.annotation), $.annotations),
choice(
field("annotations", alias(repeat($.annotation), $.annotations)),
field("body", choice(
$.ivar_member,
$.method_member,
prec.right($.attribute_member),
Expand All @@ -341,7 +347,7 @@ module.exports = grammar({
$.prepend_member,
$.alias_member,
prec.left($.visibility_member),
)
))
),

ivar_member: $ => choice(
Expand Down
Loading

0 comments on commit 3ede36e

Please sign in to comment.