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, #format, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ RegexpBeg

Returns a new instance of RegexpBeg.



8972
8973
8974
8975
# File 'lib/syntax_tree/node.rb', line 8972

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

Instance Attribute Details

#valueObject (readonly)

String

the beginning of the regular expression



8970
8971
8972
# File 'lib/syntax_tree/node.rb', line 8970

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



8998
8999
9000
# File 'lib/syntax_tree/node.rb', line 8998

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

#accept(visitor) ⇒ Object



8977
8978
8979
# File 'lib/syntax_tree/node.rb', line 8977

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

#child_nodesObject Also known as: deconstruct



8981
8982
8983
# File 'lib/syntax_tree/node.rb', line 8981

def child_nodes
  []
end

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



8985
8986
8987
8988
8989
8990
# File 'lib/syntax_tree/node.rb', line 8985

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

#deconstruct_keys(_keys) ⇒ Object



8994
8995
8996
# File 'lib/syntax_tree/node.rb', line 8994

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