Class: SyntaxTree::RBS::Formatter

Inherits:
PrettierPrint
  • Object
show all
Defined in:
lib/syntax_tree/rbs.rb

Overview

A slight extension to the default PrettierPrint formatter that keeps track of the source (so that it can be referenced by annotations if they need it) and keeps track of the level of intersections and unions so that parentheses can be forced if necessary.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, *rest) ⇒ Formatter

Returns a new instance of Formatter.



24
25
26
27
28
# File 'lib/syntax_tree/rbs.rb', line 24

def initialize(source, *rest)
  super(*rest)
  @source = source
  @force_parens = false
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



22
23
24
# File 'lib/syntax_tree/rbs.rb', line 22

def source
  @source
end

Instance Method Details

#force_parensObject



30
31
32
33
34
35
36
# File 'lib/syntax_tree/rbs.rb', line 30

def force_parens
  old_force_parens = @force_parens
  @force_parens = true
  yield
ensure
  @force_parens = old_force_parens
end

#force_parens?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/syntax_tree/rbs.rb', line 38

def force_parens?
  @force_parens
end