myco 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/lib/myco/bootstrap/instance.rb +13 -3
  3. data/lib/myco/code_tools/AST.my +0 -2
  4. data/lib/myco/code_tools/AST.my.rb +0 -1
  5. data/lib/myco/code_tools/AST/Block.my +15 -4
  6. data/lib/myco/code_tools/AST/Block.my.rb +16 -3
  7. data/lib/myco/code_tools/AST/DeclareMeme.my +44 -64
  8. data/lib/myco/code_tools/AST/DeclareMeme.my.rb +66 -74
  9. data/lib/myco/code_tools/AST/ToRuby.my +17 -20
  10. data/lib/myco/code_tools/AST/ToRuby.my.rb +24 -22
  11. data/lib/myco/code_tools/Parser.my +2 -1
  12. data/lib/myco/code_tools/Parser.my.rb +2 -1
  13. data/lib/myco/code_tools/parser/MycoBuilder.my +2 -2
  14. data/lib/myco/code_tools/parser/MycoBuilder.my.rb +2 -2
  15. data/lib/myco/code_tools/parser/MycoGrammar.my +28 -21
  16. data/lib/myco/code_tools/parser/MycoGrammar.my.rb +94 -56
  17. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces.my +10 -11
  18. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces.my.rb +10 -9
  19. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my +25 -3
  20. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my.rb +38 -0
  21. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Capture.my +152 -0
  22. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Capture.my.rb +189 -0
  23. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Common.my +84 -0
  24. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Common.my.rb +114 -0
  25. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Common/Parser.my +139 -0
  26. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/{BytecodeParser.my.rb → Common/Parser.my.rb} +17 -36
  27. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Composite.my +229 -0
  28. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Composite.my.rb +296 -0
  29. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my +8 -25
  30. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my.rb +9 -37
  31. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my +139 -37
  32. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my.rb +206 -36
  33. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my +21 -12
  34. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my.rb +45 -24
  35. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Stream.my +99 -0
  36. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Stream.my.rb +152 -0
  37. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Stream/Parser.my +37 -0
  38. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Stream/Parser.my.rb +57 -0
  39. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/String.my +136 -0
  40. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/String.my.rb +147 -0
  41. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/String/Parser.my +45 -0
  42. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/String/Parser.my.rb +85 -0
  43. data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my +31 -25
  44. data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my.rb +44 -25
  45. data/lib/myco/code_tools/parser/pegleromyces/spec/Stream/Parser.test.my +49 -0
  46. data/lib/myco/code_tools/parser/pegleromyces/spec/Stream/Parser.test.my.rb +119 -0
  47. data/lib/myco/code_tools/parser/pegleromyces/spec/Stream/Patterns.test.my +131 -0
  48. data/lib/myco/code_tools/parser/pegleromyces/spec/Stream/Patterns.test.my.rb +595 -0
  49. data/lib/myco/code_tools/parser/pegleromyces/spec/{BytecodeParser.test.my → String/Parser.test.my} +41 -2
  50. data/lib/myco/code_tools/parser/pegleromyces/spec/{BytecodeParser.test.my.rb → String/Parser.test.my.rb} +144 -3
  51. data/lib/myco/code_tools/parser/pegleromyces/spec/run.my +4 -10
  52. data/lib/myco/code_tools/parser/pegleromyces/spec/run.my.rb +4 -8
  53. data/lib/myco/core.my +1 -0
  54. data/lib/myco/core.my.rb +1 -0
  55. data/lib/myco/core/BasicObject.my +4 -2
  56. data/lib/myco/core/BasicObject.my.rb +2 -5
  57. data/lib/myco/core/Loop.my +5 -0
  58. data/lib/myco/core/Loop.my.rb +13 -0
  59. data/lib/myco/dev.rb +1 -0
  60. data/lib/myco/dev/profile.rb +12 -0
  61. data/lib/myco/version.rb +3 -3
  62. metadata +54 -59
  63. data/lib/myco/code_tools/AST/DeclareDecorator.my +0 -19
  64. data/lib/myco/code_tools/AST/DeclareDecorator.my.rb +0 -24
  65. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Builder.my +0 -4
  66. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Builder.my.rb +0 -5
  67. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my +0 -420
  68. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my.rb +0 -415
  69. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my +0 -147
  70. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Constructions.my +0 -183
  71. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Constructions.my.rb +0 -370
  72. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Instructions.my +0 -139
  73. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Instructions.my.rb +0 -284
  74. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my +0 -37
  75. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my.rb +0 -24
  76. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my +0 -123
  77. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my.rb +0 -164
  78. data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my +0 -10
  79. data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my.rb +0 -9
  80. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my +0 -10
  81. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my.rb +0 -9
  82. data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my +0 -229
  83. data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my.rb +0 -663
  84. data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my +0 -10
  85. data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my.rb +0 -9
  86. data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my +0 -13
  87. data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my.rb +0 -20
  88. data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my +0 -54
  89. data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my.rb +0 -215
@@ -1,139 +0,0 @@
1
-
2
- Instructions < EmptyObject {
3
-
4
- ##
5
- # Basic Instructions
6
-
7
- # Test the character pointed to by the current index into the subject.
8
- # Continue if the character |code| is equal, otherwise fail.
9
- char: |code|
10
- (subject.at(idx) == code)
11
- &? (self.ip = ip + 1; self.idx = idx + 1)
12
- ?? (self.ip = null) # failure
13
-
14
- # Move the instruction pointer forward by |label| instructions.
15
- jump: |label|
16
- self.ip = ip + label
17
-
18
- # Create a backtrack entry on the stack, pointing |label| instructions ahead.
19
- choice: |label| {
20
- stack.push([ip + label, idx, captures.dup])
21
- self.ip = ip + 1
22
- }
23
-
24
- # Push two-part return address onto the stack and goto start of |new_ipk|
25
- call: |new_ipk| {
26
- stack.push([ip+1, ipk])
27
- self.ip = 0
28
- self.ipk = new_ipk
29
- }
30
-
31
- # Return from a call by popping the return address and jumping to it.
32
- # It is assumed that the top of the stack is a return address from a :call.
33
- return: {
34
- addr = stack.pop
35
- addr &? (
36
- self.ipk = addr.pop
37
- self.ip = addr.pop
38
- true
39
- ) ?? finish
40
- }
41
-
42
- # Pop and discard the backtrack entry from the stack and jump to |label|.
43
- # It is assumed that the top of the stack is a backtrack entry from a :choice.
44
- commit: |label| {
45
- stack.pop
46
- self.ip = ip + label
47
- }
48
-
49
- # Note the current subject index and the given metadata for post-processing.
50
- capture: |metadata| {
51
- captures.push([idx, metadata])
52
- self.ip = ip + 1
53
- }
54
-
55
- # Pop the backtrack entry off the stack and copy the state from it,
56
- # effectively pursuing the alternative posed by the last :choice.
57
- handle_fail:
58
- self.stack.empty?
59
- &? ErrorCondition.new
60
- ?? (
61
- entry = stack.pop
62
- size = entry.size
63
- size == 3 &? ( # backtrack
64
- self.captures = entry.pop
65
- self.idx = entry.pop
66
- self.ip = entry.pop
67
- true
68
- ) ?? ( # return and mark fail
69
- size == 2 &? (
70
- self.ipk = entry.pop
71
- self.ip = null
72
- ) ?? ErrorCondition.new
73
- )
74
- )
75
-
76
- # Signal a successful match at the end of the complete pattern
77
- finish:
78
- self.ip = true
79
-
80
- ##
81
- # Optimized Instructions
82
- #
83
- # These instructions could be expressed in terms of the Basic Instructions,
84
- # but are more efficiently executed if given special implementations.
85
-
86
- # Like char, but accept any char whose code is a valid key in |table|
87
- charset: |table|
88
- (code=subject.at(idx); code && table.key?(code))
89
- &? (self.ip = ip + 1; self.idx = idx + 1)
90
- ?? (self.ip = null) # failure
91
-
92
- # Like char, but accept any char whose code is between |start| and |stop|
93
- charrange: |start, stop|
94
- (code=subject.at(idx); code && code>=start && code<=stop)
95
- &? (self.ip = ip + 1; self.idx = idx + 1)
96
- ?? (self.ip = null) # failure
97
-
98
- # (Kleene star applied to a charset)
99
- span: |table| loop {
100
- (code=subject.at(idx); code && table.key?(code))
101
- &? (self.idx = idx + 1)
102
- ?? (self.ip = ip + 1; break)
103
- }
104
-
105
- # Match any character, |count| number of times.
106
- any: |count|
107
- (self.idx + count > subject.size)
108
- &? (self.ip = null; true) # failure
109
- ?? (
110
- self.ip = ip + 1
111
- self.idx = idx + count
112
- )
113
-
114
- # Update the state for the backtrack entry on the top of the stack
115
- # but don't change the fail address; then jump to |label|.
116
- partial_commit: |label| {
117
- entry = stack.pop
118
- stack.push([entry.first, idx, captures.dup])
119
- self.ip = ip + label
120
- }
121
-
122
- # Pop the backtrack entry and restore state but jump to |label|
123
- # instead of jumping to the popped fail address.
124
- back_commit: |label| {
125
- entry = stack.pop
126
- self.captures = entry.pop
127
- self.idx = entry.pop
128
- self.ip = ip + label
129
- }
130
-
131
- # Pop a backtrack entry off the stack and discard it, then fail.
132
- fail_twice: {
133
- self.stack.empty?
134
- &? ErrorCondition.new
135
- ?? stack.pop
136
- handle_fail
137
- }
138
-
139
- }
@@ -1,284 +0,0 @@
1
-
2
- ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.cscope.for_method_definition::Instructions = ::Myco::Component.new([::Myco.find_constant(:EmptyObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(
5
- declare_meme(:char, [], nil, ::Myco.cscope.dup) { |code| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.subject.at(self.idx).__send__(
6
- :==,
7
- code
8
- )) {(
9
- self.__send__(
10
- :ip=,
11
- self.ip.__send__(
12
- :+,
13
- 1
14
- )
15
- )
16
- self.__send__(
17
- :idx=,
18
- self.idx.__send__(
19
- :+,
20
- 1
21
- )
22
- )
23
- )}) {self.__send__(
24
- :ip=,
25
- nil
26
- )})}
27
- declare_meme(:jump, [], nil, ::Myco.cscope.dup) { |label| (self.__send__(
28
- :ip=,
29
- self.ip.__send__(
30
- :+,
31
- label
32
- )
33
- ))}
34
- declare_meme(:choice, [], nil, ::Myco.cscope.dup) { |label| (
35
- self.stack.push([
36
- self.ip.__send__(
37
- :+,
38
- label
39
- ),
40
- self.idx,
41
- self.captures.dup
42
- ])
43
- self.__send__(
44
- :ip=,
45
- self.ip.__send__(
46
- :+,
47
- 1
48
- )
49
- )
50
- )}
51
- declare_meme(:call, [], nil, ::Myco.cscope.dup) { |new_ipk| (
52
- self.stack.push([
53
- self.ip.__send__(
54
- :+,
55
- 1
56
- ),
57
- self.ipk
58
- ])
59
- self.__send__(
60
- :ip=,
61
- 0
62
- )
63
- self.__send__(
64
- :ipk=,
65
- new_ipk
66
- )
67
- )}
68
- declare_meme(:return, [], nil, ::Myco.cscope.dup) { |*| (
69
- addr = self.stack.pop
70
- ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", addr) {(
71
- self.__send__(
72
- :ipk=,
73
- addr.pop
74
- )
75
- self.__send__(
76
- :ip=,
77
- addr.pop
78
- )
79
- true
80
- )}) {self.finish}
81
- )}
82
- declare_meme(:commit, [], nil, ::Myco.cscope.dup) { |label| (
83
- self.stack.pop
84
- self.__send__(
85
- :ip=,
86
- self.ip.__send__(
87
- :+,
88
- label
89
- )
90
- )
91
- )}
92
- declare_meme(:capture, [], nil, ::Myco.cscope.dup) { |metadata| (
93
- self.captures.push([
94
- self.idx,
95
- metadata
96
- ])
97
- self.__send__(
98
- :ip=,
99
- self.ip.__send__(
100
- :+,
101
- 1
102
- )
103
- )
104
- )}
105
- declare_meme(:handle_fail, [], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.stack.__send__(:empty?)) {::Myco.find_constant(:ErrorCondition).new}) {(
106
- entry = self.stack.pop
107
- size = entry.size
108
- ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", size.__send__(
109
- :==,
110
- 3
111
- )) {(
112
- self.__send__(
113
- :captures=,
114
- entry.pop
115
- )
116
- self.__send__(
117
- :idx=,
118
- entry.pop
119
- )
120
- self.__send__(
121
- :ip=,
122
- entry.pop
123
- )
124
- true
125
- )}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", size.__send__(
126
- :==,
127
- 2
128
- )) {(
129
- self.__send__(
130
- :ipk=,
131
- entry.pop
132
- )
133
- self.__send__(
134
- :ip=,
135
- nil
136
- )
137
- )}) {::Myco.find_constant(:ErrorCondition).new}}
138
- )})}
139
- declare_meme(:finish, [], nil, ::Myco.cscope.dup) { |*| (self.__send__(
140
- :ip=,
141
- true
142
- ))}
143
- declare_meme(:charset, [], nil, ::Myco.cscope.dup) { |table| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", (
144
- code = self.subject.at(self.idx)
145
- ::Myco.branch_op(:"&&", code) {table.__send__(
146
- :key?,
147
- code
148
- )}
149
- )) {(
150
- self.__send__(
151
- :ip=,
152
- self.ip.__send__(
153
- :+,
154
- 1
155
- )
156
- )
157
- self.__send__(
158
- :idx=,
159
- self.idx.__send__(
160
- :+,
161
- 1
162
- )
163
- )
164
- )}) {self.__send__(
165
- :ip=,
166
- nil
167
- )})}
168
- declare_meme(:charrange, [], nil, ::Myco.cscope.dup) { |start, stop| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", (
169
- code = self.subject.at(self.idx)
170
- ::Myco.branch_op(:"&&", ::Myco.branch_op(:"&&", code) {code.__send__(
171
- :>=,
172
- start
173
- )}) {code.__send__(
174
- :<=,
175
- stop
176
- )}
177
- )) {(
178
- self.__send__(
179
- :ip=,
180
- self.ip.__send__(
181
- :+,
182
- 1
183
- )
184
- )
185
- self.__send__(
186
- :idx=,
187
- self.idx.__send__(
188
- :+,
189
- 1
190
- )
191
- )
192
- )}) {self.__send__(
193
- :ip=,
194
- nil
195
- )})}
196
- declare_meme(:span, [], nil, ::Myco.cscope.dup) { |table| (self.loop { || (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", (
197
- code = self.subject.at(self.idx)
198
- ::Myco.branch_op(:"&&", code) {table.__send__(
199
- :key?,
200
- code
201
- )}
202
- )) {self.__send__(
203
- :idx=,
204
- self.idx.__send__(
205
- :+,
206
- 1
207
- )
208
- )}) {(
209
- self.__send__(
210
- :ip=,
211
- self.ip.__send__(
212
- :+,
213
- 1
214
- )
215
- )
216
- self.__send__(:break)
217
- )})})}
218
- declare_meme(:any, [], nil, ::Myco.cscope.dup) { |count| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.idx.__send__(
219
- :+,
220
- count
221
- ).__send__(
222
- :>,
223
- self.subject.size
224
- )) {(
225
- self.__send__(
226
- :ip=,
227
- nil
228
- )
229
- true
230
- )}) {(
231
- self.__send__(
232
- :ip=,
233
- self.ip.__send__(
234
- :+,
235
- 1
236
- )
237
- )
238
- self.__send__(
239
- :idx=,
240
- self.idx.__send__(
241
- :+,
242
- count
243
- )
244
- )
245
- )})}
246
- declare_meme(:partial_commit, [], nil, ::Myco.cscope.dup) { |label| (
247
- entry = self.stack.pop
248
- self.stack.push([
249
- entry.first,
250
- self.idx,
251
- self.captures.dup
252
- ])
253
- self.__send__(
254
- :ip=,
255
- self.ip.__send__(
256
- :+,
257
- label
258
- )
259
- )
260
- )}
261
- declare_meme(:back_commit, [], nil, ::Myco.cscope.dup) { |label| (
262
- entry = self.stack.pop
263
- self.__send__(
264
- :captures=,
265
- entry.pop
266
- )
267
- self.__send__(
268
- :idx=,
269
- entry.pop
270
- )
271
- self.__send__(
272
- :ip=,
273
- self.ip.__send__(
274
- :+,
275
- label
276
- )
277
- )
278
- )}
279
- declare_meme(:fail_twice, [], nil, ::Myco.cscope.dup) { |*| (
280
- ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.stack.__send__(:empty?)) {::Myco.find_constant(:ErrorCondition).new}) {self.stack.pop}
281
- self.handle_fail
282
- )}
283
- )}}
284
- .tap { |__c__| __c__.__name__ = :Instructions })}}.instance
@@ -1,37 +0,0 @@
1
-
2
- Machine < BasicObject, Instructions {
3
- # The index of the next program instruction, or null indicating fail condition
4
- var ip: 0
5
-
6
- # The key name in the rule table of the next program instruction
7
- var ipk: :root
8
-
9
- # The current index into the subject string
10
- var idx: 0
11
-
12
- # A list of stack entries, each of which is either a:
13
- # return_address (the instruction index to return to)
14
- # or a list containing:
15
- # [fail_address, current_idx, current_capture_list] (a pending alternative)
16
- var stack: []
17
-
18
- # A list of tuples, each containing:
19
- # [idx, captor] (the index into the subject and the captor to notify)
20
- var captures: []
21
-
22
- # The subject string as an array of character codes
23
- var subject: []
24
-
25
- # The sequence of instructions to execute for each rule name
26
- var sequence_table: ::Ruby::Hash.new
27
-
28
-
29
- # Execute the root rule instruction sequence over the given subject
30
- execute: loop {
31
- ip |? handle_fail ?? (
32
- (ip==true) &? break ?? send(*sequence_table.fetch(ipk)[ip])
33
- )
34
- }
35
-
36
- had_failure: !ip
37
- }