Class: SyntaxTree::RegexpContent

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

Overview

RegexpContent represents the body of a regular expression.

/.+ #{pattern} .+/

In the example above, a RegexpContent node represents everything contained within the forward slashes.

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(beginning:, parts:, location:) ⇒ RegexpContent

Returns a new instance of RegexpContent.



9089
9090
9091
9092
9093
# File 'lib/syntax_tree/node.rb', line 9089

def initialize(beginning:, parts:, location:)
  @beginning = beginning
  @parts = parts
  @location = location
end

Instance Attribute Details

#beginningObject (readonly)

String

the opening of the regular expression



9083
9084
9085
# File 'lib/syntax_tree/node.rb', line 9083

def beginning
  @beginning
end

#partsObject (readonly)

Array[ StringDVar | StringEmbExpr | TStringContent ]

the parts of the

regular expression



9087
9088
9089
# File 'lib/syntax_tree/node.rb', line 9087

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



9117
9118
9119
9120
# File 'lib/syntax_tree/node.rb', line 9117

def ===(other)
  other.is_a?(RegexpContent) && beginning === other.beginning &&
    parts === other.parts
end

#accept(visitor) ⇒ Object



9095
9096
9097
# File 'lib/syntax_tree/node.rb', line 9095

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

#child_nodesObject Also known as: deconstruct



9099
9100
9101
# File 'lib/syntax_tree/node.rb', line 9099

def child_nodes
  parts
end

#copy(beginning: nil, parts: nil, location: nil) ⇒ Object



9103
9104
9105
9106
9107
9108
9109
# File 'lib/syntax_tree/node.rb', line 9103

def copy(beginning: nil, parts: nil, location: nil)
  RegexpContent.new(
    beginning: beginning || self.beginning,
    parts: parts || self.parts,
    location: location || self.location
  )
end

#deconstruct_keys(_keys) ⇒ Object



9113
9114
9115
# File 'lib/syntax_tree/node.rb', line 9113

def deconstruct_keys(_keys)
  { beginning: beginning, parts: parts, location: location }
end