Class: SyntaxTree::Heredoc
Overview
Heredoc represents a heredoc string literal.
"contents\n"
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- HeredocBeg
-
the opening of the heredoc.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#dedent ⇒ Object
readonly
- Integer
-
how far to dedent the heredoc.
-
#ending ⇒ Object
readonly
- HeredocEnd
-
the ending of the heredoc.
-
#parts ⇒ Object
readonly
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the heredoc string literal.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, ending: nil, dedent: 0, parts: [], location:, comments: []) ⇒ Heredoc
constructor
A new instance of Heredoc.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(beginning:, ending: nil, dedent: 0, parts: [], location:, comments: []) ⇒ Heredoc
Returns a new instance of Heredoc.
4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 |
# File 'lib/syntax_tree/node.rb', line 4840 def initialize( beginning:, ending: nil, dedent: 0, parts: [], location:, comments: [] ) @beginning = beginning @ending = ending @dedent = dedent @parts = parts @location = location @comments = comments end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- HeredocBeg
-
the opening of the heredoc
4825 4826 4827 |
# File 'lib/syntax_tree/node.rb', line 4825 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4838 4839 4840 |
# File 'lib/syntax_tree/node.rb', line 4838 def comments @comments end |
#dedent ⇒ Object (readonly)
- Integer
-
how far to dedent the heredoc
4831 4832 4833 |
# File 'lib/syntax_tree/node.rb', line 4831 def dedent @dedent end |
#ending ⇒ Object (readonly)
- HeredocEnd
-
the ending of the heredoc
4828 4829 4830 |
# File 'lib/syntax_tree/node.rb', line 4828 def ending @ending end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
heredoc string literal
4835 4836 4837 |
# File 'lib/syntax_tree/node.rb', line 4835 def parts @parts end |
Instance Method Details
#accept(visitor) ⇒ Object
4856 4857 4858 |
# File 'lib/syntax_tree/node.rb', line 4856 def accept(visitor) visitor.visit_heredoc(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4860 4861 4862 |
# File 'lib/syntax_tree/node.rb', line 4860 def child_nodes [beginning, *parts, ending] end |
#deconstruct_keys(_keys) ⇒ Object
4866 4867 4868 4869 4870 4871 4872 4873 4874 |
# File 'lib/syntax_tree/node.rb', line 4866 def deconstruct_keys(_keys) { beginning: beginning, location: location, ending: ending, parts: parts, comments: comments } end |
#format(q) ⇒ Object
4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 |
# File 'lib/syntax_tree/node.rb', line 4876 def format(q) # This is a very specific behavior where you want to force a newline, but # don't want to force the break parent. breakable = -> { q.breakable(indent: false, force: :skip_break_parent) } q.group do q.format(beginning) q.line_suffix(priority: Formatter::HEREDOC_PRIORITY) do q.group do breakable.call parts.each do |part| if part.is_a?(TStringContent) texts = part.value.split(/\r?\n/, -1) q.seplist(texts, breakable) { |text| q.text(text) } else q.format(part) end end q.format(ending) end end end end |