Skip to content
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

Parse visibility modifiers as trees #143

Open
Morriar opened this issue Jan 12, 2023 · 0 comments
Open

Parse visibility modifiers as trees #143

Morriar opened this issue Jan 12, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@Morriar
Copy link
Collaborator

Morriar commented Jan 12, 2023

#142 showed that parsing visibility modifiers as simple nodes causes problems when sorting.

Instead we should parse the visibility modifiers as a composite node of nodes so we can maintain their content when sorting.

To do this we could change Visibility to inherit Tree then open the tree when we find the visibility modifier and finally close the tree when we encounter another visibility modifier or the end of the current scope.

The trees would look like this:

class Foo
  public # start of the public tree: because we encountered a visibility modifier: `public`
  
  def foo; end
  def bar; end

  # end of the public tree: because we encountered a visibility modifier: `private`

  private # start of the private tree: because we encountered a visibility modifier: `private`

  def baz; end

  # end of the private tree: because we encountered the end of the current scope
end

This would simplify the sorting mechanism since sorting the properties inside of a visibility tree would just be a recursive call to sort! on the visibility tree.

@Morriar Morriar changed the title Parse visibility modifiers as blocks Parse visibility modifiers as trees Jan 12, 2023
@Morriar Morriar added the enhancement New feature or request label Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant