Class: Prism::LexCompat::Heredoc::DashHeredoc
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/prism/lex_compat.rb |
Overview
Dash heredocs are a little more complicated. They are a list of tokens that need to be split on “\n” to mimic Ripper’s behavior. We also need to keep track of the state that the heredoc was opened in.
Class Method Summary
-
.new(split) ⇒ DashHeredoc
constructor
: (bool split) -> void.
Instance Attribute Summary
Instance Method Summary
-
#<<(token)
: (lex_compat_token token) -> void.
-
#to_a
: () -> Array.
Constructor Details
.new(split) ⇒ DashHeredoc
: (bool split) -> void
Instance Attribute Details
#split (readonly)
[ GitHub ]# File 'lib/prism/lex_compat.rb', line 263
attr_reader :split #: bool
#tokens (readonly)
: Array
# File 'lib/prism/lex_compat.rb', line 264
attr_reader :tokens #: Array[lex_compat_token]
Instance Method Details
#<<(token)
: (lex_compat_token token) -> void
# File 'lib/prism/lex_compat.rb', line 273
def <<(token) tokens << token end
#to_a
: () -> Array
# File 'lib/prism/lex_compat.rb', line 278
def to_a embexpr_balance = 0 tokens.each_with_object([]) do |token, results| #$ Array[lex_compat_token] case token[1] when :on_embexpr_beg embexpr_balance += 1 results << token when :on_embexpr_end embexpr_balance -= 1 results << token when :on_tstring_content if embexpr_balance == 0 lineno = token[0][0] column = token[0][1] if split # Split on "\\\n" to mimic Ripper's behavior. Use a lookbehind # to keep the delimiter in the result. token[2].split(/(?<=[^\\]\\\n)|(?<=[^\\]\\\r\n)/).each_with_index do |value, index| column = 0 if index > 0 results << [[lineno, column], :on_tstring_content, value, token[3]] lineno += value.count("\n") end else results << token end else results << token end else results << token end end end