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.



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

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

Instance Attribute Details

#beginningObject (readonly)

String

the opening of the regular expression



8928
8929
8930
# File 'lib/syntax_tree/node.rb', line 8928

def beginning
  @beginning
end

#partsObject (readonly)

Array[ StringDVar | StringEmbExpr | TStringContent ]

the parts of the

regular expression



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

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



8962
8963
8964
8965
# File 'lib/syntax_tree/node.rb', line 8962

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

#accept(visitor) ⇒ Object



8940
8941
8942
# File 'lib/syntax_tree/node.rb', line 8940

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

#child_nodesObject Also known as: deconstruct



8944
8945
8946
# File 'lib/syntax_tree/node.rb', line 8944

def child_nodes
  parts
end

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



8948
8949
8950
8951
8952
8953
8954
# File 'lib/syntax_tree/node.rb', line 8948

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



8958
8959
8960
# File 'lib/syntax_tree/node.rb', line 8958

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