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

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

Overview

Lightweight construction tree flattened once when a parse completes.

Constant Summary collapse

EMPTY_CHILDREN =

: Array

empty_children.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Entry.



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) ⇒ Object



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