Class: SyntaxTree::RBS::Formatter
- Inherits:
-
PrettierPrint
- Object
- PrettierPrint
- SyntaxTree::RBS::Formatter
- 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
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #force_parens ⇒ Object
- #force_parens? ⇒ Boolean
-
#initialize(source, *rest) ⇒ Formatter
constructor
A new instance of Formatter.
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
#source ⇒ Object (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_parens ⇒ Object
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
38 39 40 |
# File 'lib/syntax_tree/rbs.rb', line 38 def force_parens? @force_parens end |