gleam-lang / tree-sitter-gleam

🌳 A tree-sitter grammar for the Gleam programming language
Apache License 2.0
71 stars 13 forks source link

Add visibility and opacity modifiers #17

Closed J3RN closed 2 years ago

J3RN commented 2 years ago

Gleam features a pub modifier for constants, types, functions (internal and external), type definitions, and type aliases. Additionally, it also features an opaque modifier for type definitions and type aliases.

Presently, an construct with a modifier is represented as a different base AST node than the same construct without a modifier. For example:

const foo = "bar"

is represented as

(constant
 name: (identifier)
 value: (string
  (quoted_content)))

and the version with the public modifier:

pub const foo = "bar"

is represented as

(public_constant
 name: (identifier)
 value: (string
  (quoted_content)))

In the interest of usability, we should move to make constructs with and without a modifier share the same base AST node while the construct with the modifier should have an additional child node for the modifier.

e.g.

pub const foo = "bar"

should be represented as

(constant
 (visiblity_modifier)
 name: (identifier)
 value: (string
  (quoted_content)))

This behavior also exists in tree-sitter-rust.