Class: RBI::Printer
Instance Attribute Summary collapse
-
#current_indent ⇒ Object
readonly
: Integer.
-
#in_visibility_group ⇒ Object
: bool.
-
#max_line_length ⇒ Object
readonly
: Integer?.
-
#previous_node ⇒ Object
readonly
: Node?.
-
#print_locs ⇒ Object
: bool.
Instance Method Summary collapse
-
#dedent ⇒ Object
: -> void.
-
#indent ⇒ Object
: -> void.
-
#initialize(out: $stdout, indent: 0, print_locs: false, max_line_length: nil) ⇒ Printer
constructor
: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> void.
-
#print(string) ⇒ Object
Print a string without indentation nor ‘n` at the end.
-
#printl(string) ⇒ Object
Print a string with indentation and ‘n` at the end.
-
#printn(string = nil) ⇒ Object
Print a string without indentation but with a ‘n` at the end.
-
#printt(string = nil) ⇒ Object
Print a string with indentation but without a ‘n` at the end.
-
#visit_all(nodes) ⇒ Object
: (Array nodes) -> void.
-
#visit_file(file) ⇒ Object
: (File file) -> void.
Methods inherited from Visitor
Constructor Details
#initialize(out: $stdout, indent: 0, print_locs: false, max_line_length: nil) ⇒ Printer
: (?out: (IO | StringIO), ?indent: Integer, ?print_locs: bool, ?max_line_length: Integer?) -> void
21 22 23 24 25 26 27 28 29 |
# File 'lib/rbi/printer.rb', line 21 def initialize(out: $stdout, indent: 0, print_locs: false, max_line_length: nil) super() @out = out @current_indent = indent @print_locs = print_locs @in_visibility_group = T.let(false, T::Boolean) @previous_node = T.let(nil, T.nilable(Node)) @max_line_length = max_line_length end |
Instance Attribute Details
#current_indent ⇒ Object (readonly)
: Integer
15 16 17 |
# File 'lib/rbi/printer.rb', line 15 def current_indent @current_indent end |
#in_visibility_group ⇒ Object
: bool
9 10 11 |
# File 'lib/rbi/printer.rb', line 9 def in_visibility_group @in_visibility_group end |
#max_line_length ⇒ Object (readonly)
: Integer?
18 19 20 |
# File 'lib/rbi/printer.rb', line 18 def max_line_length @max_line_length end |
#previous_node ⇒ Object (readonly)
: Node?
12 13 14 |
# File 'lib/rbi/printer.rb', line 12 def previous_node @previous_node end |
#print_locs ⇒ Object
: bool
9 10 11 |
# File 'lib/rbi/printer.rb', line 9 def print_locs @print_locs end |
Instance Method Details
#dedent ⇒ Object
: -> void
39 40 41 |
# File 'lib/rbi/printer.rb', line 39 def dedent @current_indent -= 2 end |
#indent ⇒ Object
: -> void
34 35 36 |
# File 'lib/rbi/printer.rb', line 34 def indent @current_indent += 2 end |
#print(string) ⇒ Object
Print a string without indentation nor ‘n` at the end. : (String string) -> void
45 46 47 |
# File 'lib/rbi/printer.rb', line 45 def print(string) @out.print(string) end |
#printl(string) ⇒ Object
Print a string with indentation and ‘n` at the end. : (String string) -> void
65 66 67 68 |
# File 'lib/rbi/printer.rb', line 65 def printl(string) printt printn(string) end |
#printn(string = nil) ⇒ Object
Print a string without indentation but with a ‘n` at the end. : (?String? string) -> void
51 52 53 54 |
# File 'lib/rbi/printer.rb', line 51 def printn(string = nil) print(string) if string print("\n") end |
#printt(string = nil) ⇒ Object
Print a string with indentation but without a ‘n` at the end. : (?String? string) -> void
58 59 60 61 |
# File 'lib/rbi/printer.rb', line 58 def printt(string = nil) print(" " * @current_indent) print(string) if string end |
#visit_all(nodes) ⇒ Object
: (Array nodes) -> void
72 73 74 75 76 77 78 79 80 |
# File 'lib/rbi/printer.rb', line 72 def visit_all(nodes) previous_node = @previous_node @previous_node = nil nodes.each do |node| visit(node) @previous_node = node end @previous_node = previous_node end |
#visit_file(file) ⇒ Object
: (File file) -> void
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rbi/printer.rb', line 84 def visit_file(file) strictness = file.strictness if strictness printl("# typed: #{strictness}") end unless file.comments.empty? printn if strictness visit_all(file.comments) end unless file.root.empty? && file.root.comments.empty? printn if strictness || !file.comments.empty? visit(file.root) end end |