Class: SyntaxTree::RegexpBeg

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

Overview

RegexpBeg represents the start of a regular expression literal.

/.+/

In the example above, RegexpBeg represents the first / token. Regular expression literals can also be declared using the %r syntax, as in:

%r{.+}

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #format, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ RegexpBeg

Returns a new instance of RegexpBeg.



9136
9137
9138
9139
# File 'lib/syntax_tree/node.rb', line 9136

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

Instance Attribute Details

#valueObject (readonly)

String

the beginning of the regular expression



9134
9135
9136
# File 'lib/syntax_tree/node.rb', line 9134

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



9162
9163
9164
# File 'lib/syntax_tree/node.rb', line 9162

def ===(other)
  other.is_a?(RegexpBeg) && value === other.value
end

#accept(visitor) ⇒ Object



9141
9142
9143
# File 'lib/syntax_tree/node.rb', line 9141

def accept(visitor)
  visitor.visit_regexp_beg(self)
end

#child_nodesObject Also known as: deconstruct



9145
9146
9147
# File 'lib/syntax_tree/node.rb', line 9145

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



9149
9150
9151
9152
9153
9154
# File 'lib/syntax_tree/node.rb', line 9149

def copy(value: nil, location: nil)
  RegexpBeg.new(
    value: value || self.value,
    location: location || self.location
  )
end

#deconstruct_keys(_keys) ⇒ Object



9158
9159
9160
# File 'lib/syntax_tree/node.rb', line 9158

def deconstruct_keys(_keys)
  { value: value, location: location }
end