Class: Hocon::Impl::Parser::TokenWithComments
- Inherits:
-
Object
- Object
- Hocon::Impl::Parser::TokenWithComments
- Defined in:
- lib/hocon/impl/parser.rb
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #append_comments(origin) ⇒ Object
-
#initialize(token, comments = []) ⇒ TokenWithComments
constructor
A new instance of TokenWithComments.
- #prepend(earlier) ⇒ Object
- #prepend_comments(origin) ⇒ Object
- #remove_all ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(token, comments = []) ⇒ TokenWithComments
Returns a new instance of TokenWithComments.
24 25 26 27 |
# File 'lib/hocon/impl/parser.rb', line 24 def initialize(token, comments = []) @token = token @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
29 30 31 |
# File 'lib/hocon/impl/parser.rb', line 29 def comments @comments end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
29 30 31 |
# File 'lib/hocon/impl/parser.rb', line 29 def token @token end |
Instance Method Details
#append_comments(origin) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/hocon/impl/parser.rb', line 61 def append_comments(origin) if @comments.empty? origin else new_comments = @comments.map { |c| Tokens.comment_text(c) } origin.append_comments(new_comments) end end |
#prepend(earlier) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hocon/impl/parser.rb', line 39 def prepend(earlier) if earlier.empty? self elsif @comments.empty? TokenWithComments.new(@token, earlier) else merged = [] merged.concat(earlier) merged.concat(@comments) TokenWithComments.new(@token, merged) end end |
#prepend_comments(origin) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/hocon/impl/parser.rb', line 52 def prepend_comments(origin) if @comments.empty? origin else new_comments = @comments.map { |c| Tokens.comment_text(c) } origin.prepend_comments(new_comments) end end |
#remove_all ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/hocon/impl/parser.rb', line 31 def remove_all if @comments.empty? self else TokenWithComments.new(@token) end end |
#to_s ⇒ Object
70 71 72 73 74 |
# File 'lib/hocon/impl/parser.rb', line 70 def to_s # this ends up in user-visible error messages, so we don't want the # comments @token.to_s end |