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

Constructor Details

#initialize(beginning:, parts:, location:) ⇒ RegexpContent

Returns a new instance of RegexpContent.



8925
8926
8927
8928
8929
# File 'lib/syntax_tree/node.rb', line 8925

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

Instance Attribute Details

#beginningObject (readonly)

String

the opening of the regular expression



8919
8920
8921
# File 'lib/syntax_tree/node.rb', line 8919

def beginning
  @beginning
end

#partsObject (readonly)

Array[ StringDVar | StringEmbExpr | TStringContent ]

the parts of the

regular expression



8923
8924
8925
# File 'lib/syntax_tree/node.rb', line 8923

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



8953
8954
8955
8956
# File 'lib/syntax_tree/node.rb', line 8953

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

#accept(visitor) ⇒ Object



8931
8932
8933
# File 'lib/syntax_tree/node.rb', line 8931

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

#child_nodesObject Also known as: deconstruct



8935
8936
8937
# File 'lib/syntax_tree/node.rb', line 8935

def child_nodes
  parts
end

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



8939
8940
8941
8942
8943
8944
8945
# File 'lib/syntax_tree/node.rb', line 8939

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



8949
8950
8951
# File 'lib/syntax_tree/node.rb', line 8949

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