Skip to content

Commit 1454f55

Browse files
committed
Refactor into visitors
1 parent a5d9a07 commit 1454f55

File tree

9 files changed

+1708
-1398
lines changed

9 files changed

+1708
-1398
lines changed

lib/syntax_tree/rbs.rb

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
require "rbs"
55
require "syntax_tree"
66

7-
require_relative "rbs/declarations"
8-
require_relative "rbs/members"
97
require_relative "rbs/shims"
10-
require_relative "rbs/types"
11-
require_relative "rbs/utils"
128
require_relative "rbs/version"
139

1410
module SyntaxTree
1511
module RBS
12+
# This is the parent class of any of the visitors that we define in this
13+
# module. It is used to walk through the tree.
14+
class Visitor
15+
def visit(node)
16+
node&.accept(self)
17+
end
18+
end
19+
1620
# A slight extension to the default PrettierPrint formatter that keeps track
1721
# of the source (so that it can be referenced by annotations if they need
1822
# it) and keeps track of the level of intersections and unions so that
@@ -39,35 +43,6 @@ def force_parens?
3943
end
4044
end
4145

42-
# This is the root node of the entire tree. It contains all of the top-level
43-
# declarations within the file.
44-
class Root
45-
attr_reader :declarations
46-
47-
def initialize(declarations)
48-
@declarations = declarations
49-
end
50-
51-
def format(q)
52-
separator =
53-
lambda do
54-
q.breakable(force: true)
55-
q.breakable(force: true)
56-
end
57-
58-
q.seplist(declarations, separator) { |declaration| declaration.format(q) }
59-
q.breakable(force: true)
60-
end
61-
62-
def pretty_print(q)
63-
q.group(2, "(root", ")") do
64-
q.breakable
65-
q.text("declarations=")
66-
q.pp(declarations)
67-
end
68-
end
69-
end
70-
7146
class << self
7247
def format(source, maxwidth = 80)
7348
formatter = Formatter.new(source, [], maxwidth)
@@ -89,3 +64,7 @@ def read(filepath)
8964

9065
register_handler(".rbs", RBS)
9166
end
67+
68+
require_relative "rbs/entrypoints"
69+
require_relative "rbs/format"
70+
require_relative "rbs/pretty_print"

lib/syntax_tree/rbs/declarations.rb

Lines changed: 0 additions & 226 deletions
This file was deleted.

0 commit comments

Comments
 (0)