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) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(source) ⇒ Formatter
Returns a new instance of Formatter.
27 28 29 30 31 |
# File 'lib/syntax_tree/rbs.rb', line 27 def initialize(source, ...) super(...) @source = source @force_parens = false end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
25 26 27 |
# File 'lib/syntax_tree/rbs.rb', line 25 def source @source end |
Instance Method Details
#force_parens ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/syntax_tree/rbs.rb', line 33 def force_parens old_force_parens = @force_parens @force_parens = true yield ensure @force_parens = old_force_parens end |
#force_parens? ⇒ Boolean
41 42 43 |
# File 'lib/syntax_tree/rbs.rb', line 41 def force_parens? @force_parens end |