Class: SyntaxTree::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

Comment represents a comment in the source.

# comment

Defined Under Namespace

Classes: List

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, inline:, location:) ⇒ Comment

Returns a new instance of Comment.



4059
4060
4061
4062
4063
4064
4065
4066
# File 'lib/syntax_tree.rb', line 4059

def initialize(value:, inline:, location:)
  @value = value
  @inline = inline
  @location = location

  @leading = false
  @trailing = false
end

Instance Attribute Details

#inlineObject (readonly) 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.



4053
4054
4055
# File 'lib/syntax_tree.rb', line 4053

def inline
  @inline
end

#locationObject (readonly)

Location

the location of this node



4057
4058
4059
# File 'lib/syntax_tree.rb', line 4057

def location
  @location
end

#valueObject (readonly)

String

the contents of the comment



4049
4050
4051
# File 'lib/syntax_tree.rb', line 4049

def value
  @value
end

Instance Method Details

#child_nodesObject



4092
4093
4094
# File 'lib/syntax_tree.rb', line 4092

def child_nodes
  []
end

#commentsObject



4088
4089
4090
# File 'lib/syntax_tree.rb', line 4088

def comments
  []
end

#format(q) ⇒ Object



4096
4097
4098
# File 'lib/syntax_tree.rb', line 4096

def format(q)
  q.text(value)
end

#ignore?Boolean

Returns:

  • (Boolean)


4084
4085
4086
# File 'lib/syntax_tree.rb', line 4084

def ignore?
  value[1..-1].strip == "stree-ignore"
end

#leading!Object



4068
4069
4070
# File 'lib/syntax_tree.rb', line 4068

def leading!
  @leading = true
end

#leading?Boolean

Returns:

  • (Boolean)


4072
4073
4074
# File 'lib/syntax_tree.rb', line 4072

def leading?
  @leading
end

#pretty_print(q) ⇒ Object



4100
4101
4102
4103
4104
4105
4106
4107
# File 'lib/syntax_tree.rb', line 4100

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("comment")

    q.breakable
    q.pp(value)
  end
end

#to_json(*opts) ⇒ Object



4109
4110
4111
4112
4113
4114
4115
4116
# File 'lib/syntax_tree.rb', line 4109

def to_json(*opts)
  {
    type: :comment,
    value: value.force_encoding("UTF-8"),
    inline: inline,
    loc: location
  }.to_json(*opts)
end

#trailing!Object



4076
4077
4078
# File 'lib/syntax_tree.rb', line 4076

def trailing!
  @trailing = true
end

#trailing?Boolean

Returns:

  • (Boolean)


4080
4081
4082
# File 'lib/syntax_tree.rb', line 4080

def trailing?
  @trailing
end