Class: SyntaxTree::Comment
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Comment
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Comment represents a comment in the source.
Instance Attribute Summary collapse
-
#inline ⇒ Object
(also: #inline?)
readonly
- boolean
-
whether or not there is code on the same line as this comment.
-
#value ⇒ Object
readonly
- String
-
the contents of the comment.
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, inline:, location:) ⇒ Comment
Returns a new instance of Comment.
3731
3732
3733
3734
3735
3736
3737
3738
|
# File 'lib/syntax_tree/node.rb', line 3731
def initialize(value:, inline:, location:)
@value = value
@inline = inline
@location = location
@leading = false
@trailing = false
end
|
Instance Attribute Details
#inline ⇒ Object
Also known as:
inline?
- boolean
-
whether or not there is code on the same line as this comment.
If there is, then inline will be true.
3728
3729
3730
|
# File 'lib/syntax_tree/node.rb', line 3728
def inline
@inline
end
|
#value ⇒ Object
- String
-
the contents of the comment
3724
3725
3726
|
# File 'lib/syntax_tree/node.rb', line 3724
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
3790
3791
3792
|
# File 'lib/syntax_tree/node.rb', line 3790
def ===(other)
other.is_a?(Comment) && value === other.value && inline === other.inline
end
|
#accept(visitor) ⇒ Object
3764
3765
3766
|
# File 'lib/syntax_tree/node.rb', line 3764
def accept(visitor)
visitor.(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
3768
3769
3770
|
# File 'lib/syntax_tree/node.rb', line 3768
def child_nodes
[]
end
|
3760
3761
3762
|
# File 'lib/syntax_tree/node.rb', line 3760
def
[]
end
|
#copy(value: nil, inline: nil, location: nil) ⇒ Object
3772
3773
3774
3775
3776
3777
3778
|
# File 'lib/syntax_tree/node.rb', line 3772
def copy(value: nil, inline: nil, location: nil)
Comment.new(
value: value || self.value,
inline: inline || self.inline,
location: location || self.location
)
end
|
#deconstruct_keys(_keys) ⇒ Object
3782
3783
3784
|
# File 'lib/syntax_tree/node.rb', line 3782
def deconstruct_keys(_keys)
{ value: value, inline: inline, location: location }
end
|
3786
3787
3788
|
# File 'lib/syntax_tree/node.rb', line 3786
def format(q)
q.text(value)
end
|
#ignore? ⇒ Boolean
3756
3757
3758
|
# File 'lib/syntax_tree/node.rb', line 3756
def ignore?
value.match?(/\A#\s*stree-ignore\s*\z/)
end
|
#leading! ⇒ Object
3740
3741
3742
|
# File 'lib/syntax_tree/node.rb', line 3740
def leading!
@leading = true
end
|
#leading? ⇒ Boolean
3744
3745
3746
|
# File 'lib/syntax_tree/node.rb', line 3744
def leading?
@leading
end
|
#trailing! ⇒ Object
3748
3749
3750
|
# File 'lib/syntax_tree/node.rb', line 3748
def trailing!
@trailing = true
end
|
#trailing? ⇒ Boolean
3752
3753
3754
|
# File 'lib/syntax_tree/node.rb', line 3752
def trailing?
@trailing
end
|