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
- #add(after) ⇒ Object
- #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.
31 32 33 34 |
# File 'lib/hocon/impl/parser.rb', line 31 def initialize(token, comments = []) @token = token @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
36 37 38 |
# File 'lib/hocon/impl/parser.rb', line 36 def comments @comments end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
36 37 38 |
# File 'lib/hocon/impl/parser.rb', line 36 def token @token end |
Instance Method Details
#add(after) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/hocon/impl/parser.rb', line 59 def add(after) if @comments.empty? TokenWithComments.new(@token, [after]) else merged = Array.new merged += @comments merged.push(after) TokenWithComments.new(@token, merged) end end |
#append_comments(origin) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/hocon/impl/parser.rb', line 79 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
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hocon/impl/parser.rb', line 46 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
70 71 72 73 74 75 76 77 |
# File 'lib/hocon/impl/parser.rb', line 70 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
38 39 40 41 42 43 44 |
# File 'lib/hocon/impl/parser.rb', line 38 def remove_all if @comments.empty? self else TokenWithComments.new(@token) end end |
#to_s ⇒ Object
88 89 90 91 92 |
# File 'lib/hocon/impl/parser.rb', line 88 def to_s # this ends up in user-visible error messages, so we don't want the # comments @token.to_s end |