Skip to content

feat(grammar): Refactor modifiers for better querying #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lightless233
Copy link

Addresses #204.

Right now, modifiers like public or static are just anonymous keywords in the AST. This makes it a pain to write queries for them without matching on text.

This PR makes them actual nodes, similar to how tree-sitter-typescript handles it.

Changes:

  1. New (visibility) node:

    • public, protected, private are now grouped under this node.
    • Makes it easy to find declarations with specific visibility.
    ; e.g., find public methods
    (method_declaration (modifiers (visibility) @v) (#eq? @v "public"))
  2. New (modifier) node:

    • static, final, abstract, etc., now all produce a (modifier) node.
    • This provides a single node type for all these other keywords.
    ; e.g., find static fields
    (field_declaration (modifiers (modifier) @m) (#eq? @m "static"))

Resulting AST:

For public static class..., the AST is now much cleaner:

- (modifiers (KEYWORD) (KEYWORD))
+ (modifiers
+   (visibility)
+   (modifier)
+ )

Closes #204.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No visibility node
1 participant