Class: Ibex::Runtime::CST::ParseMemo::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/runtime/cst/incremental/parse_memo.rb,
sig/ibex/runtime/cst/incremental/parse_memo.rbs

Overview

Lightweight construction tree flattened once when a parse completes.

Constant Summary collapse

EMPTY_CHILDREN =

Returns:

empty_children.freeze

Instance Method Summary collapse

Constructor Details

#initialize(state, children: EMPTY_CHILDREN, segment: nil) ⇒ Entry

Returns a new instance of Entry.

RBS:

  • (Integer? state, ?children: Array[Entry], ?segment: Array[Integer?]?) -> void

Parameters:

  • state (Integer, nil)
  • children: (Array[Entry]) (defaults to: EMPTY_CHILDREN)
  • segment: (Array[Integer?], nil) (defaults to: nil)


67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 67

def initialize(state, children: EMPTY_CHILDREN, segment: nil)
  @state = state
  @children = if children.empty?
                EMPTY_CHILDREN
              elsif children.frozen?
                children
              else
                children.dup.freeze
              end
  @segment = segment&.then { |values| values.frozen? ? values : values.dup.freeze }
  freeze
end

Instance Method Details

#append_to(output) ⇒ void

This method returns an undefined value.

RBS:

  • (Array[Integer?] output) -> void

Parameters:

  • output (Array[Integer?])


81
82
83
84
85
86
87
88
89
90
# File 'lib/ibex/runtime/cst/incremental/parse_memo.rb', line 81

def append_to(output)
  segment = @segment
  if segment
    output.concat(segment)
    return
  end

  output << @state
  @children.each { |child| child.append_to(output) }
end