44require "rbs"
55require "syntax_tree"
66
7- require_relative "rbs/declarations"
8- require_relative "rbs/members"
97require_relative "rbs/shims"
10- require_relative "rbs/types"
11- require_relative "rbs/utils"
128require_relative "rbs/version"
139
1410module 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 )
9166end
67+
68+ require_relative "rbs/entrypoints"
69+ require_relative "rbs/format"
70+ require_relative "rbs/pretty_print"
0 commit comments