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.



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

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

Instance Attribute Details

#beginningObject (readonly)

String

the opening of the regular expression



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

def beginning
  @beginning
end

#partsObject (readonly)

Array[ StringDVar | StringEmbExpr | TStringContent ]

the parts of the

regular expression



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

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



8988
8989
8990
8991
# File 'lib/syntax_tree/node.rb', line 8988

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

#accept(visitor) ⇒ Object



8966
8967
8968
# File 'lib/syntax_tree/node.rb', line 8966

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  parts
end

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



8974
8975
8976
8977
8978
8979
8980
# File 'lib/syntax_tree/node.rb', line 8974

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



8984
8985
8986
# File 'lib/syntax_tree/node.rb', line 8984

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