Class: Stupidedi::Parser::InterchangeState
Instance Attribute Summary collapse
Instance Method Summary
collapse
interleaved_sequence, #leaf?, lsequence, mkcomposite, mkelement, mkrepeated, mksegment, mksimple, #pretty_print, sequence, tsequence
Methods included from Inspect
#inspect
Constructor Details
#initialize(separators, segment_dict, instructions, zipper, children) ⇒ InterchangeState
Returns a new instance of InterchangeState.
22
23
24
25
|
# File 'lib/stupidedi/parser/states/interchange_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
20
21
22
|
# File 'lib/stupidedi/parser/states/interchange_state.rb', line 20
def children
@children
end
|
14
15
16
|
# File 'lib/stupidedi/parser/states/interchange_state.rb', line 14
def instructions
@instructions
end
|
11
12
13
|
# File 'lib/stupidedi/parser/states/interchange_state.rb', line 11
def segment_dict
@segment_dict
end
|
8
9
10
|
# File 'lib/stupidedi/parser/states/interchange_state.rb', line 8
def separators
@separators
end
|
17
18
19
|
# File 'lib/stupidedi/parser/states/interchange_state.rb', line 17
def zipper
@zipper
end
|
Class Method Details
.push(zipper, parent, segment_tok, segment_use, config) ⇒ Zipper::AbstractCursor
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/stupidedi/parser/states/interchange_state.rb', line 43
def push(zipper, parent, segment_tok, segment_use, config)
version = segment_tok.element_toks.at(11).try(:value)
unless config.interchange.defined_at?(version)
reason =
if config.interchange.empty?
Stupidedi::Exceptions::MissingGrammarError::DEFAULT_MESSAGE
else
"unknown interchange version #{version.inspect}"
end
return FailureState.push(zipper, parent, segment_tok, reason)
end
envelope_def = config.interchange.at(version)
envelope_val = envelope_def.empty(parent.separators)
segment_use = envelope_def.entry_segment_use
segment_val = mksegment(segment_tok, segment_use)
separators =
parent.separators.merge(envelope_def.separators(segment_val))
zipper.append_child new(
separators,
parent.segment_dict.push(envelope_val.segment_dict),
parent.instructions.push(instructions(envelope_def)),
parent.zipper.append(envelope_val).append_child(segment_val),
[])
end
|
Instance Method Details
28
29
30
31
32
33
34
35
|
# File 'lib/stupidedi/parser/states/interchange_state.rb', line 28
def copy(changes = {})
InterchangeState.new \
changes.fetch(:separators, @separators),
changes.fetch(:segment_dict, @segment_dict),
changes.fetch(:instructions, @instructions),
changes.fetch(:zipper, @zipper),
changes.fetch(:children, @children)
end
|