Class: Stupidedi::Builder::BuilderDsl
- Inherits:
-
Object
- Object
- Stupidedi::Builder::BuilderDsl
show all
- Includes:
- Tokenization, Inspect
- Defined in:
- lib/stupidedi/builder/builder_dsl.rb
Constant Summary
collapse
- SEGMENT_ID =
/^[A-Z][A-Z0-9]{1,2}$/
Instance Attribute Summary collapse
Instance Method Summary
collapse
#blank, #composite, #default, #not_used, #repeated
Methods included from Inspect
#inspect
Constructor Details
#initialize(machine, strict = true) ⇒ BuilderDsl
Returns a new instance of BuilderDsl.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/stupidedi/builder/builder_dsl.rb', line 98
def method_missing(name, *args)
if SEGMENT_ID =~ name.to_s
segment!(name, Reader::Position.caller(2), *args)
else
super
end
end
|
Instance Attribute Details
16
17
18
|
# File 'lib/stupidedi/builder/builder_dsl.rb', line 16
def machine
@machine
end
|
#strict=(value) ⇒ Boolean
19
20
21
|
# File 'lib/stupidedi/builder/builder_dsl.rb', line 19
def strict=(value)
@strict = value
end
|
Class Method Details
.build(config, strict = true) ⇒ BuilderDsl
254
255
256
|
# File 'lib/stupidedi/builder/builder_dsl.rb', line 254
def build(config, strict = true)
new(StateMachine.build(config), strict)
end
|
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/stupidedi/builder/builder_dsl.rb', line 30
def respond_to_missing?(name, include_private = false)
SEGMENT_ID =~ name.to_s || super
end
|
#segment!(name, position, *elements) ⇒ BuilderDsl
39
40
41
42
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/stupidedi/builder/builder_dsl.rb', line 39
def segment!(name, position, *elements)
segment_tok = mksegment_tok(@reader.segment_dict, name, elements, position)
machine, reader = @machine.insert(segment_tok, @reader)
if @strict
unless machine.deterministic?
matches = machine.active.map do |m|
segment_def = m.node.zipper.node.definition
"#{segment_def.id} #{segment_def.name}"
end.join(", ")
raise Exceptions::ParseError,
"non-deterministic machine state: #{matches}"
end
machine.active.each{|m| critique(m.node.zipper) }
machine.prev.tap do |prev|
prev.active.zip(machine.active) do |p, q|
qancestors = Set.new
q = q.node.zipper
p = p.node.zipper
while q.respond_to?(:parent)
qancestors << q.parent
q = q.parent
end
while p.respond_to?(:parent)
break if qancestors.include?(p)
critique(p)
p = p.parent
end
end
end
end
@machine = machine
@reader = reader
self
end
|
#strict? ⇒ Boolean
34
35
36
|
# File 'lib/stupidedi/builder/builder_dsl.rb', line 34
def strict?
@strict
end
|