Skip to content

Commit

Permalink
feat: add fields to class_decl, module_decl, interface_decl, method_type
Browse files Browse the repository at this point in the history
  • Loading branch information
joker1007 committed Dec 7, 2023
1 parent 5f29849 commit 44b2eab
Show file tree
Hide file tree
Showing 4 changed files with 5,532 additions and 4,915 deletions.
49 changes: 29 additions & 20 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ module.exports = grammar({
),

decl: $ => seq(
alias(repeat($.annotation), $.annotations),
choice(
field("annotations", alias(repeat($.annotation), $.annotations)),
field("body", choice(
$.class_decl,
$.module_decl,
$.class_alias_decl,
Expand All @@ -180,7 +180,7 @@ module.exports = grammar({
$.type_alias_decl,
$.const_decl,
$.global_decl,
)
))
),

_nestable_decls: $ => choice(
Expand All @@ -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 All @@ -356,7 +362,10 @@ module.exports = grammar({
seq("def", $.self, "?.", $.method_name, ":", $.method_types),
),

method_type: $ => seq(optional($.method_type_parameters), alias(repeat($.annotation), $.annotations), $.method_type_body),
method_type: $ => seq(
field("type_parameters", optional($.method_type_parameters)),
field("annotations", alias(repeat($.annotation), $.annotations)),
field("body", $.method_type_body)),

method_types: $ => choice(
sep1($.method_type, "|"),
Expand Down
Loading

0 comments on commit 44b2eab

Please sign in to comment.