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) ⇒ Formatter

Returns a new instance of Formatter.



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

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

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#force_parensObject



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

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

#force_parens?Boolean

Returns:

  • (Boolean)


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

def force_parens?
  @force_parens
end