Skip to content

Parse visibility modifiers as trees #143

Open
@Morriar

Description

#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.

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions