Class: YARP::PinnedExpressionNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents the use of the ‘^` operator for pinning an expression in a pattern matching expression.

foo in ^(bar)
       ^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression, operator_loc, lparen_loc, rparen_loc, location) ⇒ PinnedExpressionNode

def initialize: (expression: Node, operator_loc: Location, lparen_loc: Location, rparen_loc: Location, location: Location) -> void



7936
7937
7938
7939
7940
7941
7942
# File 'lib/yarp/node.rb', line 7936

def initialize(expression, operator_loc, lparen_loc, rparen_loc, location)
  @expression = expression
  @operator_loc = operator_loc
  @lparen_loc = lparen_loc
  @rparen_loc = rparen_loc
  @location = location
end

Instance Attribute Details

#expressionObject (readonly)

attr_reader expression: Node



7924
7925
7926
# File 'lib/yarp/node.rb', line 7924

def expression
  @expression
end

#lparen_locObject (readonly)

attr_reader lparen_loc: Location



7930
7931
7932
# File 'lib/yarp/node.rb', line 7930

def lparen_loc
  @lparen_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



7927
7928
7929
# File 'lib/yarp/node.rb', line 7927

def operator_loc
  @operator_loc
end

#rparen_locObject (readonly)

attr_reader rparen_loc: Location



7933
7934
7935
# File 'lib/yarp/node.rb', line 7933

def rparen_loc
  @rparen_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



7945
7946
7947
# File 'lib/yarp/node.rb', line 7945

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



7950
7951
7952
# File 'lib/yarp/node.rb', line 7950

def child_nodes
  [expression]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



7955
7956
7957
# File 'lib/yarp/node.rb', line 7955

def comment_targets
  [expression, operator_loc, lparen_loc, rparen_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> PinnedExpressionNode



7960
7961
7962
7963
7964
7965
7966
7967
7968
# File 'lib/yarp/node.rb', line 7960

def copy(**params)
  PinnedExpressionNode.new(
    params.fetch(:expression) { expression },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:lparen_loc) { lparen_loc },
    params.fetch(:rparen_loc) { rparen_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



7974
7975
7976
# File 'lib/yarp/node.rb', line 7974

def deconstruct_keys(keys)
  { expression: expression, operator_loc: operator_loc, lparen_loc: lparen_loc, rparen_loc: rparen_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



7993
7994
7995
7996
7997
7998
7999
8000
8001
# File 'lib/yarp/node.rb', line 7993

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── expression:\n"
  inspector << inspector.child_node(expression, "")
  inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n"
  inspector << "└── rparen_loc: #{inspector.location(rparen_loc)}\n"
  inspector.to_str
end

#lparenObject

def lparen: () -> String



7984
7985
7986
# File 'lib/yarp/node.rb', line 7984

def lparen
  lparen_loc.slice
end

#operatorObject

def operator: () -> String



7979
7980
7981
# File 'lib/yarp/node.rb', line 7979

def operator
  operator_loc.slice
end

#rparenObject

def rparen: () -> String



7989
7990
7991
# File 'lib/yarp/node.rb', line 7989

def rparen
  rparen_loc.slice
end