myco 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/myco/bootstrap/find_constant.rb +4 -11
- data/lib/myco/code_loader.rb +2 -1
- data/lib/myco/code_tools/AST/ConstantAccess.my +47 -3
- data/lib/myco/code_tools/AST/ConstantAccess.my.rb +13 -9
- data/lib/myco/code_tools/AST/ConstantAssignment.my +1 -5
- data/lib/myco/code_tools/AST/ConstantAssignment.my.rb +3 -9
- data/lib/myco/code_tools/AST/ToRuby.my +5 -2
- data/lib/myco/code_tools/AST/ToRuby.my.rb +7 -3
- data/lib/myco/code_tools/AST.my +1 -0
- data/lib/myco/code_tools/AST.my.rb +9 -1
- data/lib/myco/code_tools/Parser.my +24 -0
- data/lib/myco/code_tools/Parser.my.rb +25 -0
- data/lib/myco/code_tools/parser/MycoBuilder.my +67 -0
- data/lib/myco/code_tools/parser/MycoBuilder.my.rb +99 -0
- data/lib/myco/code_tools/parser/MycoCharacterClasses.my +20 -0
- data/lib/myco/code_tools/parser/MycoCharacterClasses.my.rb +56 -0
- data/lib/myco/code_tools/parser/MycoGrammar.my +564 -0
- data/lib/myco/code_tools/parser/MycoGrammar.my.rb +1851 -0
- data/lib/myco/code_tools/parser/MycoTokens.my +78 -0
- data/lib/myco/code_tools/parser/MycoTokens.my.rb +170 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Builder.my +4 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Builder.my.rb +5 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my +142 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my.rb +181 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my +420 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my.rb +415 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my +137 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my.rb +237 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Constructions.my +183 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Constructions.my.rb +370 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my +65 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my.rb +83 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Instructions.my +139 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Instructions.my.rb +284 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my +37 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my.rb +24 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my +42 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my.rb +52 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my +123 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my.rb +164 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my +236 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my.rb +339 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces.my +15 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces.my.rb +14 -0
- data/lib/myco/code_tools.rb +1 -1
- data/lib/myco/version.rb +1 -1
- data/lib/myco.rb +2 -0
- metadata +44 -25
- data/lib/myco/code_tools/parser/peg_parser.rb +0 -7182
- data/lib/myco/code_tools/parser.rb +0 -39
@@ -0,0 +1,415 @@
|
|
1
|
+
|
2
|
+
::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
3
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
4
|
+
declare_meme(:"BytecodeHelpers.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
5
|
+
::Myco.cscope.for_method_definition.const_set(:BytecodeInstructions, ::Myco::Component.new([::Myco.find_constant(:BasicObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
6
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
7
|
+
::Myco.find_constant(:Constructions).component_eval {(
|
8
|
+
::Myco.find_constant(:AnyCharacter).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.any(1))})}
|
9
|
+
::Myco.find_constant(:Character).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.char(self.code.chr))})}
|
10
|
+
::Myco.find_constant(:CharacterString).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.char(self.codes.map(&:chr).join))})}
|
11
|
+
::Myco.find_constant(:CharacterSet).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.set(self.codes.map(&:chr).join))})}
|
12
|
+
::Myco.find_constant(:CharacterRange).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (
|
13
|
+
codes = ::Myco.find_constant(:Range).new(
|
14
|
+
self.start,
|
15
|
+
self.stop
|
16
|
+
)
|
17
|
+
m.set(codes.map(&:chr).join)
|
18
|
+
)})}
|
19
|
+
::Myco.find_constant(:NegativePredicate).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.neg_predicate(
|
20
|
+
::Proc.new { || (self.inner.bytecode(m))},
|
21
|
+
self.inner.bytecode_can_capture
|
22
|
+
))})}
|
23
|
+
::Myco.find_constant(:PositivePredicate).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.pos_predicate(
|
24
|
+
::Proc.new { || (self.inner.bytecode(m))},
|
25
|
+
self.inner.bytecode_can_capture
|
26
|
+
))})}
|
27
|
+
::Myco.find_constant(:OneOrMore).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.many(
|
28
|
+
::Proc.new { || (
|
29
|
+
self.inner.bytecode(m)
|
30
|
+
(self.inlaid.respond_to?(:call).false? ? ::Myco::Void : self.inlaid.call)
|
31
|
+
)},
|
32
|
+
self.inner.bytecode_can_capture
|
33
|
+
))})}
|
34
|
+
::Myco.find_constant(:ZeroOrOne).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.choice(
|
35
|
+
::Proc.new { || (self.inner.bytecode(m))},
|
36
|
+
::Proc.new { || nil},
|
37
|
+
self.inner.bytecode_can_capture
|
38
|
+
))})}
|
39
|
+
::Myco.find_constant(:ZeroOrMore).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.kleene(
|
40
|
+
::Proc.new { || (
|
41
|
+
self.inner.bytecode(m)
|
42
|
+
(self.inlaid.respond_to?(:call).false? ? ::Myco::Void : self.inlaid.call)
|
43
|
+
)},
|
44
|
+
self.inner.bytecode_can_capture
|
45
|
+
))})}
|
46
|
+
::Myco.find_constant(:OrderedChoice).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.choice(
|
47
|
+
::Proc.new { || (self.first.bytecode(m))},
|
48
|
+
::Proc.new { || (self.second.bytecode(m))},
|
49
|
+
self.first.bytecode_can_capture
|
50
|
+
))})}
|
51
|
+
::Myco.find_constant(:Concatenation).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (
|
52
|
+
self.first.bytecode(m)
|
53
|
+
self.second.bytecode(m)
|
54
|
+
)})}
|
55
|
+
::Myco.find_constant(:NamedCapture).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", ::Myco.branch_op(:"||", self.inner.__send__(
|
56
|
+
:is_a?,
|
57
|
+
::Myco.find_constant(:OneOrMore)
|
58
|
+
)) {self.inner.__send__(
|
59
|
+
:is_a?,
|
60
|
+
::Myco.find_constant(:ZeroOrMore)
|
61
|
+
)}) {(
|
62
|
+
self.inner.__send__(
|
63
|
+
:inlaid=,
|
64
|
+
::Proc.new { || (m.capture(
|
65
|
+
:m_split,
|
66
|
+
self.captargs
|
67
|
+
))}
|
68
|
+
)
|
69
|
+
m.capture(:m_start)
|
70
|
+
self.inner.bytecode(m)
|
71
|
+
m.capture(
|
72
|
+
:m_end,
|
73
|
+
self.captargs
|
74
|
+
)
|
75
|
+
)}) {(
|
76
|
+
m.capture(:c_start)
|
77
|
+
self.inner.bytecode(m)
|
78
|
+
m.capture(
|
79
|
+
:c_end,
|
80
|
+
self.captargs
|
81
|
+
)
|
82
|
+
)})})}
|
83
|
+
::Myco.find_constant(:NamedTextCapture).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (
|
84
|
+
m.capture(:s_start)
|
85
|
+
self.inner.bytecode(m)
|
86
|
+
m.capture(
|
87
|
+
:s_end,
|
88
|
+
self.captargs
|
89
|
+
)
|
90
|
+
)})}
|
91
|
+
::Myco.find_constant(:NamedTokenCapture).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (
|
92
|
+
m.capture(:t_start)
|
93
|
+
self.inner.bytecode(m)
|
94
|
+
m.capture(
|
95
|
+
:t_end,
|
96
|
+
self.captargs
|
97
|
+
)
|
98
|
+
)})}
|
99
|
+
::Myco.find_constant(:Reduction).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (
|
100
|
+
m.capture(:r_start)
|
101
|
+
self.inner.bytecode(m)
|
102
|
+
m.capture(
|
103
|
+
:r_end,
|
104
|
+
self.captargs
|
105
|
+
)
|
106
|
+
)})}
|
107
|
+
::Myco.find_constant(:AnyCharacter).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (false)})}
|
108
|
+
::Myco.find_constant(:Character).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (false)})}
|
109
|
+
::Myco.find_constant(:CharacterString).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (false)})}
|
110
|
+
::Myco.find_constant(:CharacterSet).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (false)})}
|
111
|
+
::Myco.find_constant(:CharacterRange).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (false)})}
|
112
|
+
::Myco.find_constant(:NegativePredicate).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (self.inner.bytecode_can_capture)})}
|
113
|
+
::Myco.find_constant(:PositivePredicate).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (self.inner.bytecode_can_capture)})}
|
114
|
+
::Myco.find_constant(:OneOrMore).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (self.inner.bytecode_can_capture)})}
|
115
|
+
::Myco.find_constant(:ZeroOrOne).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (self.inner.bytecode_can_capture)})}
|
116
|
+
::Myco.find_constant(:ZeroOrMore).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (self.inner.bytecode_can_capture)})}
|
117
|
+
::Myco.find_constant(:OrderedChoice).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"||", self.first.bytecode_can_capture) {self.second.bytecode_can_capture})})}
|
118
|
+
::Myco.find_constant(:Concatenation).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"||", self.first.bytecode_can_capture) {self.second.bytecode_can_capture})})}
|
119
|
+
::Myco.find_constant(:NamedCapture).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (true)})}
|
120
|
+
::Myco.find_constant(:NamedTextCapture).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (true)})}
|
121
|
+
::Myco.find_constant(:NamedTokenCapture).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (true)})}
|
122
|
+
::Myco.find_constant(:Reduction).component_eval {(declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (true)})}
|
123
|
+
)}
|
124
|
+
declare_meme(:g, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
125
|
+
declare_meme(:any, [], nil, ::Myco.cscope.dup) { |count| (
|
126
|
+
self.g.push_idx
|
127
|
+
self.g.push_int(count)
|
128
|
+
self.g.send(
|
129
|
+
:+,
|
130
|
+
1
|
131
|
+
)
|
132
|
+
self.g.push_subject
|
133
|
+
self.g.send(
|
134
|
+
:size,
|
135
|
+
0
|
136
|
+
)
|
137
|
+
self.g.send(
|
138
|
+
:<=,
|
139
|
+
1
|
140
|
+
)
|
141
|
+
self.g.goto_if_false(self.g.overall_fail)
|
142
|
+
self.g.push_int(count)
|
143
|
+
self.g.increment_idx
|
144
|
+
)}
|
145
|
+
declare_meme(:char, [], nil, ::Myco.cscope.dup) { |string| (
|
146
|
+
self.g.setup_unwind(
|
147
|
+
self.g.overall_fail,
|
148
|
+
0
|
149
|
+
)
|
150
|
+
self.g.push_literal(string)
|
151
|
+
self.g.push_subject
|
152
|
+
self.g.push_idx
|
153
|
+
self.g.push_int(string.size)
|
154
|
+
self.g.send(
|
155
|
+
:compare_substring,
|
156
|
+
3
|
157
|
+
)
|
158
|
+
self.g.__send__(:meta_push_0)
|
159
|
+
self.g.pop_unwind
|
160
|
+
self.g.goto_if_not_equal(self.g.overall_fail)
|
161
|
+
self.g.push_int(string.size)
|
162
|
+
self.g.increment_idx
|
163
|
+
)}
|
164
|
+
declare_meme(:set, [], nil, ::Myco.cscope.dup) { |string| (
|
165
|
+
local_done = self.g.new_label
|
166
|
+
local_early_fail = self.g.new_label
|
167
|
+
self.g.push_literal(string)
|
168
|
+
self.g.push_subject_at_idx
|
169
|
+
self.g.dup_top
|
170
|
+
self.g.goto_if_false(local_early_fail)
|
171
|
+
self.g.__send__(:meta_push_0)
|
172
|
+
self.g.send(
|
173
|
+
:find_string,
|
174
|
+
2
|
175
|
+
)
|
176
|
+
self.g.goto_if_false(self.g.overall_fail)
|
177
|
+
self.g.goto(local_done)
|
178
|
+
local_early_fail.__send__(:set!)
|
179
|
+
self.g.pop
|
180
|
+
self.g.pop
|
181
|
+
self.g.goto(self.g.overall_fail)
|
182
|
+
local_done.__send__(:set!)
|
183
|
+
self.g.__send__(:meta_push_1)
|
184
|
+
self.g.increment_idx
|
185
|
+
)}
|
186
|
+
declare_meme(:choice, [], nil, ::Myco.cscope.dup) { |first, second, first_can_capture| (
|
187
|
+
local_done = self.g.new_label
|
188
|
+
local_fail = self.g.new_label
|
189
|
+
old_fail = self.g.overall_fail
|
190
|
+
self.g.__send__(
|
191
|
+
:overall_fail=,
|
192
|
+
local_fail
|
193
|
+
)
|
194
|
+
self.__send__(
|
195
|
+
:if,
|
196
|
+
first_can_capture
|
197
|
+
) { || (self.g.push_temp_captures)}
|
198
|
+
self.g.push_idx
|
199
|
+
first.call
|
200
|
+
self.g.pop
|
201
|
+
self.__send__(
|
202
|
+
:if,
|
203
|
+
first_can_capture
|
204
|
+
) { || (self.g.pop_to_accept_captures)}
|
205
|
+
self.g.__send__(
|
206
|
+
:overall_fail=,
|
207
|
+
old_fail
|
208
|
+
)
|
209
|
+
self.g.goto(local_done)
|
210
|
+
local_fail.__send__(:set!)
|
211
|
+
self.g.pop_to_set_idx
|
212
|
+
self.__send__(
|
213
|
+
:if,
|
214
|
+
first_can_capture
|
215
|
+
) { || (self.g.pop_to_reject_captures)}
|
216
|
+
self.g.__send__(
|
217
|
+
:overall_fail=,
|
218
|
+
old_fail
|
219
|
+
)
|
220
|
+
second.call
|
221
|
+
local_done.__send__(:set!)
|
222
|
+
)}
|
223
|
+
declare_meme(:many, [], nil, ::Myco.cscope.dup) { |inner, inner_can_capture| (
|
224
|
+
local_retry = self.g.new_label
|
225
|
+
local_fail = self.g.new_label
|
226
|
+
old_fail = self.g.overall_fail
|
227
|
+
self.g.__send__(
|
228
|
+
:overall_fail=,
|
229
|
+
local_fail
|
230
|
+
)
|
231
|
+
self.g.push_false
|
232
|
+
local_retry.__send__(:set!)
|
233
|
+
self.__send__(
|
234
|
+
:if,
|
235
|
+
inner_can_capture
|
236
|
+
) { || (self.g.push_temp_captures)}
|
237
|
+
inner.call
|
238
|
+
self.__send__(
|
239
|
+
:if,
|
240
|
+
inner_can_capture
|
241
|
+
) { || (self.g.pop_to_accept_captures)}
|
242
|
+
self.g.pop
|
243
|
+
self.g.push_true
|
244
|
+
self.g.goto(local_retry)
|
245
|
+
local_fail.__send__(:set!)
|
246
|
+
self.__send__(
|
247
|
+
:if,
|
248
|
+
inner_can_capture
|
249
|
+
) { || (self.g.pop_to_reject_captures)}
|
250
|
+
self.g.__send__(
|
251
|
+
:overall_fail=,
|
252
|
+
old_fail
|
253
|
+
)
|
254
|
+
self.g.goto_if_false(self.g.overall_fail)
|
255
|
+
)}
|
256
|
+
declare_meme(:kleene, [], nil, ::Myco.cscope.dup) { |inner, inner_can_capture| (
|
257
|
+
local_retry = self.g.new_label
|
258
|
+
local_fail = self.g.new_label
|
259
|
+
old_fail = self.g.overall_fail
|
260
|
+
self.g.__send__(
|
261
|
+
:overall_fail=,
|
262
|
+
local_fail
|
263
|
+
)
|
264
|
+
local_retry.__send__(:set!)
|
265
|
+
self.__send__(
|
266
|
+
:if,
|
267
|
+
inner_can_capture
|
268
|
+
) { || (self.g.push_temp_captures)}
|
269
|
+
inner.call
|
270
|
+
self.__send__(
|
271
|
+
:if,
|
272
|
+
inner_can_capture
|
273
|
+
) { || (self.g.pop_to_accept_captures)}
|
274
|
+
self.g.goto(local_retry)
|
275
|
+
local_fail.__send__(:set!)
|
276
|
+
self.__send__(
|
277
|
+
:if,
|
278
|
+
inner_can_capture
|
279
|
+
) { || (self.g.pop_to_reject_captures)}
|
280
|
+
self.g.__send__(
|
281
|
+
:overall_fail=,
|
282
|
+
old_fail
|
283
|
+
)
|
284
|
+
)}
|
285
|
+
declare_meme(:pos_predicate, [], nil, ::Myco.cscope.dup) { |inner, inner_can_capture| (
|
286
|
+
local_done = self.g.new_label
|
287
|
+
local_fail = self.g.new_label
|
288
|
+
old_fail = self.g.overall_fail
|
289
|
+
self.g.__send__(
|
290
|
+
:overall_fail=,
|
291
|
+
local_fail
|
292
|
+
)
|
293
|
+
self.__send__(
|
294
|
+
:if,
|
295
|
+
inner_can_capture
|
296
|
+
) { || (self.g.push_temp_captures)}
|
297
|
+
self.g.push_idx
|
298
|
+
inner.call
|
299
|
+
self.g.pop_to_set_idx
|
300
|
+
self.__send__(
|
301
|
+
:if,
|
302
|
+
inner_can_capture
|
303
|
+
) { || (self.g.pop_to_accept_captures)}
|
304
|
+
self.g.__send__(
|
305
|
+
:overall_fail=,
|
306
|
+
old_fail
|
307
|
+
)
|
308
|
+
self.g.goto(local_done)
|
309
|
+
local_fail.__send__(:set!)
|
310
|
+
self.g.pop_to_set_idx
|
311
|
+
self.__send__(
|
312
|
+
:if,
|
313
|
+
inner_can_capture
|
314
|
+
) { || (self.g.pop_to_reject_captures)}
|
315
|
+
self.g.__send__(
|
316
|
+
:overall_fail=,
|
317
|
+
old_fail
|
318
|
+
)
|
319
|
+
self.g.goto(self.g.overall_fail)
|
320
|
+
local_done.__send__(:set!)
|
321
|
+
)}
|
322
|
+
declare_meme(:neg_predicate, [], nil, ::Myco.cscope.dup) { |inner, inner_can_capture| (
|
323
|
+
local_fail = self.g.new_label
|
324
|
+
old_fail = self.g.overall_fail
|
325
|
+
self.g.__send__(
|
326
|
+
:overall_fail=,
|
327
|
+
local_fail
|
328
|
+
)
|
329
|
+
self.__send__(
|
330
|
+
:if,
|
331
|
+
inner_can_capture
|
332
|
+
) { || (self.g.push_temp_captures)}
|
333
|
+
self.g.push_idx
|
334
|
+
inner.call
|
335
|
+
self.g.pop_to_set_idx
|
336
|
+
self.__send__(
|
337
|
+
:if,
|
338
|
+
inner_can_capture
|
339
|
+
) { || (self.g.pop_to_reject_captures)}
|
340
|
+
self.g.__send__(
|
341
|
+
:overall_fail=,
|
342
|
+
old_fail
|
343
|
+
)
|
344
|
+
self.g.goto(self.g.overall_fail)
|
345
|
+
local_fail.__send__(:set!)
|
346
|
+
self.g.pop_to_set_idx
|
347
|
+
self.__send__(
|
348
|
+
:if,
|
349
|
+
inner_can_capture
|
350
|
+
) { || (self.g.pop_to_accept_captures)}
|
351
|
+
self.g.__send__(
|
352
|
+
:overall_fail=,
|
353
|
+
old_fail
|
354
|
+
)
|
355
|
+
)}
|
356
|
+
declare_meme(:call, [], nil, ::Myco.cscope.dup) { |name, memoize=true| (
|
357
|
+
result_check = self.g.new_label
|
358
|
+
memo_result_check = self.g.new_label
|
359
|
+
local_success = self.g.new_label
|
360
|
+
local_fail = self.g.new_label
|
361
|
+
self.g.push_temp_captures
|
362
|
+
self.__send__(
|
363
|
+
:if,
|
364
|
+
memoize
|
365
|
+
) { || (
|
366
|
+
self.g.memo_or_eq_new_hash(name)
|
367
|
+
self.g.goto_if_memo_for_idx(
|
368
|
+
name,
|
369
|
+
memo_result_check
|
370
|
+
)
|
371
|
+
)}
|
372
|
+
self.g.push_self
|
373
|
+
self.g.push_subject
|
374
|
+
self.g.push_idx
|
375
|
+
self.g.send(
|
376
|
+
name,
|
377
|
+
2
|
378
|
+
)
|
379
|
+
result_check.__send__(:set!)
|
380
|
+
self.g.copy_result_to_memo(name)
|
381
|
+
self.g.dup_top
|
382
|
+
self.g.goto_if_true(local_success)
|
383
|
+
self.g.goto(local_fail)
|
384
|
+
self.__send__(
|
385
|
+
:if,
|
386
|
+
memoize
|
387
|
+
) { || (
|
388
|
+
memo_result_check.__send__(:set!)
|
389
|
+
self.g.dup_top
|
390
|
+
self.g.goto_if_true(local_success)
|
391
|
+
self.g.goto(local_fail)
|
392
|
+
)}
|
393
|
+
local_fail.__send__(:set!)
|
394
|
+
self.g.pop
|
395
|
+
self.g.pop_to_reject_captures
|
396
|
+
self.g.goto(self.g.overall_fail)
|
397
|
+
local_success.__send__(:set!)
|
398
|
+
self.g.pop_to_set_idx
|
399
|
+
self.g.pop_to_accept_captures
|
400
|
+
)}
|
401
|
+
declare_meme(:capture, [], nil, ::Myco.cscope.dup) { |*metadata| (
|
402
|
+
self.g.push_captures
|
403
|
+
self.g.push_idx
|
404
|
+
self.g.push_literal_or_array(metadata)
|
405
|
+
self.g.make_array(2)
|
406
|
+
self.g.make_array(1)
|
407
|
+
self.g.send(
|
408
|
+
:concat,
|
409
|
+
1
|
410
|
+
)
|
411
|
+
self.g.pop
|
412
|
+
)}
|
413
|
+
)}})
|
414
|
+
.tap { |__c__| __c__.__name__ = :BytecodeInstructions }
|
415
|
+
)}}.instance
|
@@ -0,0 +1,137 @@
|
|
1
|
+
|
2
|
+
BytecodeParser < BasicObject {
|
3
|
+
var grammar: Grammar { }
|
4
|
+
|
5
|
+
new_worker: set_up_worker(prototype.new)
|
6
|
+
|
7
|
+
var prototype: compile_prototype
|
8
|
+
|
9
|
+
refresh: self.prototype = compile_prototype
|
10
|
+
|
11
|
+
compile_prototype: {
|
12
|
+
proto = Component.new
|
13
|
+
grammar.construct_all_rules
|
14
|
+
grammar.rule_table.each |name, rule| {
|
15
|
+
compile_rule_into(proto, name, rule)
|
16
|
+
}
|
17
|
+
proto
|
18
|
+
}
|
19
|
+
|
20
|
+
compile_rule_into: |proto, name, rule| {
|
21
|
+
construct = rule.construct_rule
|
22
|
+
|
23
|
+
proto.dynamic_method(name, "(compiled parser)") |g| {
|
24
|
+
instructor = BytecodeInstructions { }
|
25
|
+
instructor.g = g
|
26
|
+
g.extend(BytecodeHelpers)
|
27
|
+
|
28
|
+
g.rule_start
|
29
|
+
construct.bytecode(instructor)
|
30
|
+
g.rule_finish
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
compile_generator: |name, file, line=1, &block| {
|
35
|
+
g = Myco::ToolSet::Generator.new
|
36
|
+
g.name = name
|
37
|
+
g.file = file
|
38
|
+
g.set_line(line)
|
39
|
+
|
40
|
+
block.call(g)
|
41
|
+
|
42
|
+
g.ret
|
43
|
+
g.close
|
44
|
+
g.use_detected
|
45
|
+
g
|
46
|
+
}
|
47
|
+
|
48
|
+
compile_code: |name, file, line=1, &block| {
|
49
|
+
g = compile_generator(name, file, line, &block)
|
50
|
+
g.encode
|
51
|
+
g.package(Rubinius::CompiledCode)
|
52
|
+
}
|
53
|
+
|
54
|
+
save_prototype: |filename| {
|
55
|
+
code = compile_code(:__script__, :"(snippet)") |g| {
|
56
|
+
g.push_cpath_top; g.find_const(:"Class")
|
57
|
+
g.create_block(compile_generator(:__block__, :"(snippet)") |g| {
|
58
|
+
prototype.instance_methods.each |name| {
|
59
|
+
code = prototype.instance_method(name).executable
|
60
|
+
if(code.is_a?(Rubinius::CompiledCode)) {
|
61
|
+
g.push_rubinius
|
62
|
+
g.push_literal(name)
|
63
|
+
g.push_literal(code)
|
64
|
+
g.push_scope
|
65
|
+
g.push_variables; g.send(:method_visibility, 0)
|
66
|
+
g.send(:add_defn_method, 4)
|
67
|
+
}
|
68
|
+
}
|
69
|
+
})
|
70
|
+
g.send_with_block(:new, 0)
|
71
|
+
}
|
72
|
+
|
73
|
+
Myco::ToolSet::CompiledFile.dump(code, filename, Rubinius::Signature, Rubinius::RUBY_LIB_VERSION)
|
74
|
+
}
|
75
|
+
|
76
|
+
load_prototype: |filename| {
|
77
|
+
loader = Myco::CodeLoader::BytecodeLoader.new(filename)
|
78
|
+
loader.bind_to(call_depth:1)
|
79
|
+
self.prototype = loader.load
|
80
|
+
}
|
81
|
+
|
82
|
+
set_up_worker: |worker| {
|
83
|
+
worker.instance_variable_set(:"@captures", [])
|
84
|
+
worker.instance_variable_set(:"@highest_idx", 0)
|
85
|
+
worker
|
86
|
+
}
|
87
|
+
|
88
|
+
captures_of_worker: |worker|
|
89
|
+
worker.instance_variable_get(:"@captures")
|
90
|
+
|
91
|
+
highest_idx_of_worker: |worker|
|
92
|
+
worker.instance_variable_get(:"@highest_idx")
|
93
|
+
|
94
|
+
new_processor: Processor.new(builder: new_builder)
|
95
|
+
new_builder: Builder.new
|
96
|
+
|
97
|
+
|
98
|
+
# Match and process the given string using the current grammar
|
99
|
+
parse: |string| {
|
100
|
+
worker = new_worker
|
101
|
+
|
102
|
+
self.error_idx = null
|
103
|
+
self.error_row = null
|
104
|
+
self.error_col = null
|
105
|
+
self.error_string = null
|
106
|
+
self.result = null
|
107
|
+
self.end_idx = worker.root(string, 0)
|
108
|
+
|
109
|
+
processor = new_processor
|
110
|
+
|
111
|
+
if(end_idx) {
|
112
|
+
processor.string = string
|
113
|
+
processor.capture_items = captures_of_worker(worker)
|
114
|
+
self.result = processor.process
|
115
|
+
}
|
116
|
+
if(!end_idx) {
|
117
|
+
self.error_idx = highest_idx_of_worker(worker)
|
118
|
+
pos = processor.position_of(error_idx, string)
|
119
|
+
self.error_row = pos.first
|
120
|
+
self.error_col = pos.last
|
121
|
+
self.error_string = \
|
122
|
+
"Unexpected character near line: "error_row", column: "error_col".\n" \
|
123
|
+
string.each_line.to_a[error_row - 1]"" \
|
124
|
+
(' ' * [(error_col - 1), 0].max)"^"
|
125
|
+
}
|
126
|
+
self.result
|
127
|
+
}
|
128
|
+
|
129
|
+
var end_idx
|
130
|
+
var result
|
131
|
+
|
132
|
+
var error_idx
|
133
|
+
var error_row
|
134
|
+
var error_col
|
135
|
+
var error_string
|
136
|
+
raise_error: raise(SyntaxError, error_string)
|
137
|
+
}
|