Class: Stupidedi::Parser::FailureState

Inherits:
AbstractState show all
Defined in:
lib/stupidedi/parser/states/failure_state.rb

Instance Attribute Summary collapse

Constructors collapse

Instance Method Summary collapse

Methods inherited from AbstractState

#leaf?, lsequence, mkcomposite, mkelement, mkrepeated, mksimple, #pretty_print, sequence, tsequence

Methods included from Inspect

#inspect

Constructor Details

#initialize(separators, segment_dict, instructions, zipper, children) ⇒ FailureState

Returns a new instance of FailureState.



22
23
24
25
# File 'lib/stupidedi/parser/states/failure_state.rb', line 22

def initialize(separators, segment_dict, instructions, zipper, children)
  @separators, @segment_dict, @instructions, @zipper, @children =
    separators, segment_dict, instructions, zipper, children
end

Instance Attribute Details

#childrenArray<FailureState> (readonly)

Returns:



20
21
22
# File 'lib/stupidedi/parser/states/failure_state.rb', line 20

def children
  @children
end

#instructionsInstructionTable (readonly)

Returns:



17
18
19
# File 'lib/stupidedi/parser/states/failure_state.rb', line 17

def instructions
  @instructions
end

#segment_dictReader::SegmentDict (readonly)

Returns:



11
12
13
# File 'lib/stupidedi/parser/states/failure_state.rb', line 11

def segment_dict
  @segment_dict
end

#separatorsReader::Separators (readonly)

Returns:



8
9
10
# File 'lib/stupidedi/parser/states/failure_state.rb', line 8

def separators
  @separators
end

#zipperZipper::AbstractCursor (readonly)



14
15
16
# File 'lib/stupidedi/parser/states/failure_state.rb', line 14

def zipper
  @zipper
end

Class Method Details

.mksegment(segment_tok, parent)



54
55
56
57
58
59
60
61
62
63
# File 'lib/stupidedi/parser/states/failure_state.rb', line 54

def mksegment(segment_tok, parent)
  segment_val = Values::InvalidSegmentVal.new \
    "cannot occur here", segment_tok, parent.separators

  new(parent.separators,
      parent.segment_dict,
      parent.instructions,
      parent.zipper.append(segment_val),
      [])
end

.push(zipper, parent, segment_tok, reason) ⇒ Zipper::AbstractCursor



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/stupidedi/parser/states/failure_state.rb', line 42

def push(zipper, parent, segment_tok, reason)
  envelope_val = Values::InvalidEnvelopeVal.new([])
  segment_val  = Values::InvalidSegmentVal.new(reason, segment_tok, parent.separators)

  zipper.append_child new(
    parent.separators,
    parent.segment_dict,
    parent.instructions.push([]),
    parent.zipper.append(envelope_val).append_child(segment_val),
    [])
end

Instance Method Details

#copy(changes = {})



27
28
29
30
31
32
33
34
# File 'lib/stupidedi/parser/states/failure_state.rb', line 27

def copy(changes = {})
  FailureState.new \
    changes.fetch(:separators, @separators),
    changes.fetch(:segment_dict, @segment_dict),
    changes.fetch(:instructions, @instructions),
    changes.fetch(:zipper, @zipper),
    changes.fetch(:children, @children)
end