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.



9056
9057
9058
9059
9060
# File 'lib/syntax_tree/node.rb', line 9056

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

Instance Attribute Details

#beginningObject (readonly)

String

the opening of the regular expression



9050
9051
9052
# File 'lib/syntax_tree/node.rb', line 9050

def beginning
  @beginning
end

#partsObject (readonly)

Array[ StringDVar | StringEmbExpr | TStringContent ]

the parts of the

regular expression



9054
9055
9056
# File 'lib/syntax_tree/node.rb', line 9054

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



9062
9063
9064
# File 'lib/syntax_tree/node.rb', line 9062

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

#child_nodesObject Also known as: deconstruct



9066
9067
9068
# File 'lib/syntax_tree/node.rb', line 9066

def child_nodes
  parts
end

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



9070
9071
9072
9073
9074
9075
9076
# File 'lib/syntax_tree/node.rb', line 9070

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



9080
9081
9082
# File 'lib/syntax_tree/node.rb', line 9080

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