Class: Ibex::Runtime::CST::TypedNode

Inherits:
Object
  • Object
show all
Defined in:
lib/json5/generated_parser.rb

Overview

Grammar-generated typed view over one Red syntax node.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ TypedNode

Returns a new instance of TypedNode.

RBS:

  • (SyntaxNode node) -> void



1623
1624
1625
1626
# File 'lib/json5/generated_parser.rb', line 1623

def initialize(node)
  @node = node
  freeze
end

Instance Attribute Details

#nodeObject (readonly)

RBS:



1620
1621
1622
# File 'lib/json5/generated_parser.rb', line 1620

def node
  @node
end

Instance Method Details

#child_at_slot(index) ⇒ Object

RBS:

  • (Integer index) -> element



1635
# File 'lib/json5/generated_parser.rb', line 1635

def child_at_slot(index) = @node.child_at(index)

#deconstructObject

RBS:

  • () -> Array[element]



1654
# File 'lib/json5/generated_parser.rb', line 1654

def deconstruct = @node.deconstruct

#deconstruct_keys(keys) ⇒ Object

RBS:

  • (Array[Symbol]?) -> Hash[Symbol, Object?]



1657
# File 'lib/json5/generated_parser.rb', line 1657

def deconstruct_keys(keys) = @node.deconstruct_keys(keys)

#kindObject

RBS:

  • () -> Integer



1629
# File 'lib/json5/generated_parser.rb', line 1629

def kind = @node.kind

#kind_nameObject

RBS:

  • () -> String



1632
# File 'lib/json5/generated_parser.rb', line 1632

def kind_name = @node.kind_name

#node_at_slot(index) ⇒ Object

RBS:

  • (Integer index) -> SyntaxNode

Raises:

  • (TypeError)


1638
1639
1640
1641
1642
1643
# File 'lib/json5/generated_parser.rb', line 1638

def node_at_slot(index)
  child = child_at_slot(index)
  return child if child.is_a?(SyntaxNode)

  raise TypeError, "CST slot #{index} is not a syntax node"
end

#to_sourceObject

RBS:

  • () -> String



1660
# File 'lib/json5/generated_parser.rb', line 1660

def to_source = @node.to_source

#token_at_slot(index) ⇒ Object

RBS:

  • (Integer index) -> SyntaxToken

Raises:

  • (TypeError)


1646
1647
1648
1649
1650
1651
# File 'lib/json5/generated_parser.rb', line 1646

def token_at_slot(index)
  child = child_at_slot(index)
  return child if child.is_a?(SyntaxToken)

  raise TypeError, "CST slot #{index} is not a syntax token"
end