myco 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/myco/bootstrap/add_method.rb +38 -0
  3. data/lib/myco/bootstrap/component.rb +43 -21
  4. data/lib/myco/bootstrap/find_constant.rb +73 -25
  5. data/lib/myco/bootstrap/instance.rb +96 -25
  6. data/lib/myco/bootstrap/meme.rb +18 -12
  7. data/lib/myco/bootstrap/tuple.rb +13 -0
  8. data/lib/myco/bootstrap/undefined.rb +9 -0
  9. data/lib/myco/bootstrap/void.rb +5 -4
  10. data/lib/myco/bootstrap.my +24 -13
  11. data/lib/myco/bootstrap.my.rb +41 -4
  12. data/lib/myco/bootstrap.rb +4 -0
  13. data/lib/myco/code_loader.rb +11 -9
  14. data/lib/myco/code_tools/AST/Block.my.rb +2 -2
  15. data/lib/myco/code_tools/AST/ConstantAccess.my.rb +4 -4
  16. data/lib/myco/code_tools/AST/ConstantAssignment.my.rb +4 -4
  17. data/lib/myco/code_tools/AST/Invoke.my +1 -1
  18. data/lib/myco/code_tools/AST/Invoke.my.rb +1 -1
  19. data/lib/myco/code_tools/AST/Node.my +2 -4
  20. data/lib/myco/code_tools/AST/Node.my.rb +3 -3
  21. data/lib/myco/code_tools/AST/PipeOperator.my.rb +1 -1
  22. data/lib/myco/code_tools/AST/ToRuby.my.rb +8 -8
  23. data/lib/myco/code_tools/AST/misc.my.rb +1 -1
  24. data/lib/myco/code_tools/Parser.my +8 -15
  25. data/lib/myco/code_tools/Parser.my.rb +8 -14
  26. data/lib/myco/code_tools/parser/MycoBuilder.my +3 -4
  27. data/lib/myco/code_tools/parser/MycoBuilder.my.rb +5 -6
  28. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my +8 -4
  29. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my.rb +5 -5
  30. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my +2 -2
  31. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my.rb +12 -12
  32. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my +54 -44
  33. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my.rb +69 -83
  34. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my +18 -8
  35. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my.rb +24 -10
  36. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my.rb +1 -1
  37. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my +1 -1
  38. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my.rb +1 -2
  39. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my +1 -1
  40. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my.rb +1 -1
  41. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my +3 -3
  42. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my.rb +5 -6
  43. data/lib/myco/code_tools/parser/pegleromyces/spec/BasicSpec.my +35 -0
  44. data/lib/myco/code_tools/parser/pegleromyces/spec/BasicSpec.my.rb +35 -0
  45. data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my +10 -0
  46. data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my.rb +9 -0
  47. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my +10 -0
  48. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my.rb +9 -0
  49. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeParser.test.my +81 -0
  50. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeParser.test.my.rb +209 -0
  51. data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my +229 -0
  52. data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my.rb +663 -0
  53. data/lib/myco/code_tools/parser/pegleromyces/spec/Grammar.test.my +10 -0
  54. data/lib/myco/code_tools/parser/pegleromyces/spec/Grammar.test.my.rb +9 -0
  55. data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my +10 -0
  56. data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my.rb +9 -0
  57. data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my +13 -0
  58. data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my.rb +20 -0
  59. data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my +54 -0
  60. data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my.rb +215 -0
  61. data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my +156 -0
  62. data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my.rb +334 -0
  63. data/lib/myco/code_tools/parser/pegleromyces/spec/Processor.test.my +10 -0
  64. data/lib/myco/code_tools/parser/pegleromyces/spec/Processor.test.my.rb +9 -0
  65. data/lib/myco/code_tools/parser/pegleromyces/spec/run.my +20 -0
  66. data/lib/myco/code_tools/parser/pegleromyces/spec/run.my.rb +16 -0
  67. data/lib/myco/core/BasicDecorators.my +19 -11
  68. data/lib/myco/core/BasicDecorators.my.rb +24 -20
  69. data/lib/myco/core/BasicObject.my +12 -7
  70. data/lib/myco/core/BasicObject.my.rb +50 -44
  71. data/lib/myco/core/Category.my +12 -2
  72. data/lib/myco/core/Category.my.rb +15 -7
  73. data/lib/myco/core/Decorator.my +1 -1
  74. data/lib/myco/core/Decorator.my.rb +8 -10
  75. data/lib/myco/core/FileToplevel.my +3 -3
  76. data/lib/myco/core/FileToplevel.my.rb +4 -6
  77. data/lib/myco/core/Object.my +7 -10
  78. data/lib/myco/core/Object.my.rb +11 -17
  79. data/lib/myco/core/Ruby.my +6 -0
  80. data/lib/myco/core/Ruby.my.rb +16 -0
  81. data/lib/myco/core/Switch.my +1 -1
  82. data/lib/myco/core/Switch.my.rb +1 -1
  83. data/lib/myco/core.my +4 -0
  84. data/lib/myco/core.my.rb +7 -0
  85. data/lib/myco/dev/call_sites.rb +39 -0
  86. data/lib/myco/dev/counter.rb +26 -0
  87. data/lib/myco/dev.rb +3 -0
  88. data/lib/myco/eval.rb +1 -1
  89. data/lib/myco/tools/BasicCommand.my.rb +1 -1
  90. data/lib/myco/version.rb +1 -1
  91. data/lib/myco.rb +2 -3
  92. metadata +53 -20
  93. data/lib/myco/bootstrap/evaluator.rb +0 -58
@@ -1,8 +1,31 @@
1
1
 
2
2
  BytecodeParser < BasicObject {
3
- var grammar: Grammar { }
3
+ State < BasicObject {
4
+ var string
5
+ var start_idx
6
+ var end_idx
7
+ var rule
8
+ var result
9
+
10
+ var error_idx
11
+ var error_row
12
+ var error_col
13
+ var error_string
14
+
15
+ raise_error: self.error_idx && raise(SyntaxError
16
+ "Unexpected character with parser: "self.rule \
17
+ " near line: "self.error_row \
18
+ ", column: "self.error_col".\n" \
19
+ self.string.each_line.to_a[self.error_row - 1]"" \
20
+ (' ' * [(self.error_col - 1), 0].max)"^"
21
+ )
22
+ }
23
+
24
+ var grammar: Grammar.new
25
+ var builder: Builder.new
4
26
 
5
27
  new_worker: set_up_worker(prototype.new)
28
+ new_processor: Processor.new(builder: builder)
6
29
 
7
30
  var prototype: compile_prototype
8
31
 
@@ -20,8 +43,8 @@ BytecodeParser < BasicObject {
20
43
  compile_rule_into: |proto, name, rule| {
21
44
  construct = rule.construct_rule
22
45
 
23
- proto.dynamic_method(name, "(compiled parser)") |g| {
24
- instructor = BytecodeInstructions { }
46
+ Myco.add_dynamic_method(proto, name, "(compiled parser)") |g| {
47
+ instructor = BytecodeInstructions.new
25
48
  instructor.g = g
26
49
  g.extend(BytecodeHelpers)
27
50
 
@@ -80,58 +103,45 @@ BytecodeParser < BasicObject {
80
103
  }
81
104
 
82
105
  set_up_worker: |worker| {
83
- worker.instance_variable_set(:"@captures", [])
84
- worker.instance_variable_set(:"@highest_idx", 0)
106
+ worker.__set_ivar__(:"@captures", [])
107
+ worker.__set_ivar__(:"@highest_idx", 0)
85
108
  worker
86
109
  }
87
110
 
88
111
  captures_of_worker: |worker|
89
- worker.instance_variable_get(:"@captures")
112
+ worker.__get_ivar__(:"@captures")
90
113
 
91
114
  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
115
+ worker.__get_ivar__(:"@highest_idx")
96
116
 
97
117
 
98
118
  # 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
-
119
+ parse: |string, rule:"root", start_idx:0| {
120
+ worker = new_worker
109
121
  processor = new_processor
122
+ state = State.new(
123
+ string: string.to_s
124
+ rule: rule.to_sym
125
+ start_idx: start_idx.to_i
126
+ error_idx: null
127
+ error_row: null
128
+ error_col: null
129
+ error_string: null
130
+ result: null
131
+ )
132
+
133
+ state.end_idx = worker.__send__(state.rule, state.string, state.start_idx)
110
134
 
111
- if(end_idx) {
112
- processor.string = string
135
+ state.end_idx &? (
136
+ processor.string = state.string
113
137
  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
138
+ state.result = processor.process
139
+ ) ?? (
140
+ state.error_idx = highest_idx_of_worker(worker)
141
+ pos = processor.position_of(state.error_idx, state.string)
142
+ state.error_row = pos.first
143
+ state.error_col = pos.last
144
+ )
145
+ state
127
146
  }
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
147
  }
@@ -2,9 +2,42 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.cscope.for_method_definition::BytecodeParser = ::Myco::Component.new([::Myco.find_constant(:BasicObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
4
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
5
- declare_meme(:grammar, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Grammar)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
6
- .tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}.instance)}
5
+ ::Myco.cscope.for_method_definition::State = ::Myco::Component.new([::Myco.find_constant(:BasicObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
6
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(
7
+ declare_meme(:string, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
8
+ declare_meme(:start_idx, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
9
+ declare_meme(:end_idx, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
10
+ declare_meme(:rule, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
11
+ declare_meme(:result, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
12
+ declare_meme(:error_idx, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
13
+ declare_meme(:error_row, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
14
+ declare_meme(:error_col, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
15
+ declare_meme(:error_string, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
16
+ declare_meme(:raise_error, [], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"&&", self.error_idx) {self.raise(
17
+ ::Myco.find_constant(:SyntaxError),
18
+ "Unexpected character with parser: #{self.rule} near line: #{self.error_row}, column: #{self.error_col}.\n#{self.string.each_line.to_a.__send__(
19
+ :[],
20
+ self.error_row.__send__(
21
+ :-,
22
+ 1
23
+ )
24
+ )}#{" ".__send__(
25
+ :*,
26
+ [
27
+ self.error_col.__send__(
28
+ :-,
29
+ 1
30
+ ),
31
+ 0
32
+ ].max
33
+ )}^"
34
+ )})}
35
+ )}}
36
+ .tap { |__c__| __c__.__name__ = :State }
37
+ declare_meme(:grammar, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Grammar).new)}
38
+ declare_meme(:builder, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Builder).new)}
7
39
  declare_meme(:new_worker, [], nil, ::Myco.cscope.dup) { |*| (self.set_up_worker(self.prototype.new))}
40
+ declare_meme(:new_processor, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Processor).new({:builder => self.builder}))}
8
41
  declare_meme(:prototype, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (self.compile_prototype)}
9
42
  declare_meme(:refresh, [], nil, ::Myco.cscope.dup) { |*| (self.__send__(
10
43
  :prototype=,
@@ -22,12 +55,12 @@
22
55
  )}
23
56
  declare_meme(:compile_rule_into, [], nil, ::Myco.cscope.dup) { |proto, name, rule| (
24
57
  construct = rule.construct_rule
25
- proto.dynamic_method(
58
+ ::Myco.find_constant(:Myco).add_dynamic_method(
59
+ proto,
26
60
  name,
27
61
  "(compiled parser)"
28
62
  ) { |g| (
29
- instructor = ::Myco::Component.new([::Myco.find_constant(:BytecodeInstructions)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
30
- .tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}.instance
63
+ instructor = ::Myco.find_constant(:BytecodeInstructions).new
31
64
  instructor.__send__(
32
65
  :g=,
33
66
  g
@@ -120,118 +153,71 @@
120
153
  )
121
154
  )}
122
155
  declare_meme(:set_up_worker, [], nil, ::Myco.cscope.dup) { |worker| (
123
- worker.instance_variable_set(
156
+ worker.__set_ivar__(
124
157
  :@captures,
125
158
  []
126
159
  )
127
- worker.instance_variable_set(
160
+ worker.__set_ivar__(
128
161
  :@highest_idx,
129
162
  0
130
163
  )
131
164
  worker
132
165
  )}
133
- declare_meme(:captures_of_worker, [], nil, ::Myco.cscope.dup) { |worker| (worker.instance_variable_get(:@captures))}
134
- declare_meme(:highest_idx_of_worker, [], nil, ::Myco.cscope.dup) { |worker| (worker.instance_variable_get(:@highest_idx))}
135
- declare_meme(:new_processor, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Processor).new({:builder => self.new_builder}))}
136
- declare_meme(:new_builder, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Builder).new)}
137
- declare_meme(:parse, [], nil, ::Myco.cscope.dup) { |string| (
166
+ declare_meme(:captures_of_worker, [], nil, ::Myco.cscope.dup) { |worker| (worker.__get_ivar__(:@captures))}
167
+ declare_meme(:highest_idx_of_worker, [], nil, ::Myco.cscope.dup) { |worker| (worker.__get_ivar__(:@highest_idx))}
168
+ declare_meme(:parse, [], nil, ::Myco.cscope.dup) { |string, rule:"root", start_idx:0| (
138
169
  worker = self.new_worker
139
- self.__send__(
140
- :error_idx=,
141
- nil
142
- )
143
- self.__send__(
144
- :error_row=,
145
- nil
146
- )
147
- self.__send__(
148
- :error_col=,
149
- nil
150
- )
151
- self.__send__(
152
- :error_string=,
153
- nil
154
- )
155
- self.__send__(
156
- :result=,
157
- nil
158
- )
159
- self.__send__(
170
+ processor = self.new_processor
171
+ state = ::Myco.find_constant(:State).new({
172
+ :string => string.to_s,
173
+ :rule => rule.to_sym,
174
+ :start_idx => start_idx.to_i,
175
+ :error_idx => nil,
176
+ :error_row => nil,
177
+ :error_col => nil,
178
+ :error_string => nil,
179
+ :result => nil
180
+ })
181
+ state.__send__(
160
182
  :end_idx=,
161
- worker.root(
162
- string,
163
- 0
183
+ worker.__send__(
184
+ state.rule,
185
+ state.string,
186
+ state.start_idx
164
187
  )
165
188
  )
166
- processor = self.new_processor
167
- self.__send__(
168
- :if,
169
- self.end_idx
170
- ) { || (
189
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", state.end_idx) {(
171
190
  processor.__send__(
172
191
  :string=,
173
- string
192
+ state.string
174
193
  )
175
194
  processor.__send__(
176
195
  :capture_items=,
177
196
  self.captures_of_worker(worker)
178
197
  )
179
- self.__send__(
198
+ state.__send__(
180
199
  :result=,
181
200
  processor.process
182
201
  )
183
- )}
184
- self.__send__(
185
- :if,
186
- self.end_idx.__send__(:!)
187
- ) { || (
188
- self.__send__(
202
+ )}) {(
203
+ state.__send__(
189
204
  :error_idx=,
190
205
  self.highest_idx_of_worker(worker)
191
206
  )
192
207
  pos = processor.position_of(
193
- self.error_idx,
194
- string
208
+ state.error_idx,
209
+ state.string
195
210
  )
196
- self.__send__(
211
+ state.__send__(
197
212
  :error_row=,
198
213
  pos.first
199
214
  )
200
- self.__send__(
215
+ state.__send__(
201
216
  :error_col=,
202
217
  pos.last
203
218
  )
204
- self.__send__(
205
- :error_string=,
206
- "Unexpected character near line: #{self.error_row}, column: #{self.error_col}.\n#{string.each_line.to_a.__send__(
207
- :[],
208
- self.error_row.__send__(
209
- :-,
210
- 1
211
- )
212
- )}#{" ".__send__(
213
- :*,
214
- [
215
- self.error_col.__send__(
216
- :-,
217
- 1
218
- ),
219
- 0
220
- ].max
221
- )}^"
222
- )
223
219
  )}
224
- self.result
220
+ state
225
221
  )}
226
- declare_meme(:end_idx, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
227
- declare_meme(:result, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
228
- declare_meme(:error_idx, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
229
- declare_meme(:error_row, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
230
- declare_meme(:error_col, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
231
- declare_meme(:error_string, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
232
- declare_meme(:raise_error, [], nil, ::Myco.cscope.dup) { |*| (self.raise(
233
- ::Myco.find_constant(:SyntaxError),
234
- self.error_string
235
- ))}
236
222
  )}}
237
223
  .tap { |__c__| __c__.__name__ = :BytecodeParser })}}.instance
@@ -18,7 +18,13 @@ Grammar < BasicObject, Patterns::ShorthandMethods {
18
18
  # Force evaluation of the rule tree in a way that
19
19
  # doesn't get stuck in an infinite recursion.
20
20
  construct_all_rules: {
21
- rules.root.construct_rule
21
+ # Consider all rules with "root" in the name
22
+ rules.memes.each |name, meme| {
23
+ meme.name.to_s.include?("root") && (
24
+ meme.result_for(rules).construct_rule
25
+ )
26
+ }
27
+
22
28
  seen_keys = []
23
29
  loop {
24
30
  new_keys = rule_table.keys - seen_keys
@@ -32,8 +38,7 @@ Grammar < BasicObject, Patterns::ShorthandMethods {
32
38
 
33
39
  [decorators]
34
40
 
35
- # TODO: streamline syntax for this definition to make it more intuitive
36
- token: Decorator {
41
+ const token: Decorator {
37
42
  apply: |meme| {
38
43
  orig_meme = meme.dup
39
44
  meme.body = &{ orig_meme.result.token(:"t_"meme.name"") }
@@ -42,16 +47,21 @@ Grammar < BasicObject, Patterns::ShorthandMethods {
42
47
  cache: true
43
48
  }
44
49
 
45
- var rule: Decorator {
50
+ const rule: Decorator {
51
+ # TODO: remove need for helper method by adding parser aborts/continuations to pegleromyces
52
+ helper_method: |name, meme, outer_self| Rule {
53
+ name: name
54
+ inner: meme.result_for(outer_self)
55
+ blargy: [name, meme, outer_self]
56
+ }
57
+
46
58
  apply: |meme| {
47
59
  name = meme.name
60
+ meme_self = self
48
61
  # TODO: use some kind of Decorator#wrap mechanism instead
49
62
  meme.target.declare_meme(name, [:memoize]) {
50
63
  outer_self = self
51
- rule = Rule {
52
- name: name
53
- inner: meme.result_for(outer_self)
54
- }
64
+ rule = meme_self.helper_method(name, meme, outer_self)
55
65
  rule_table[name] = rule
56
66
  rule
57
67
  }
@@ -22,9 +22,12 @@
22
22
  declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (true)}
23
23
  )}}
24
24
  .tap { |__c__| __c__.__name__ = :RuleReference }
25
- declare_meme(:rule_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Ruby::Hash.new)}
25
+ declare_meme(:rule_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Object::Hash.new)}
26
26
  declare_meme(:construct_all_rules, [], nil, ::Myco.cscope.dup) { |*| (
27
- self.rules.root.construct_rule
27
+ self.rules.memes.each { |name, meme| (::Myco.branch_op(:"&&", meme.name.to_s.__send__(
28
+ :include?,
29
+ "root"
30
+ )) {meme.result_for(self.rules).construct_rule})}
28
31
  seen_keys = []
29
32
  self.loop { || (
30
33
  new_keys = self.rule_table.keys.__send__(
@@ -42,31 +45,42 @@
42
45
  )}
43
46
  )}
44
47
  __category__(:decorators).component_eval {(
45
- declare_meme(:token, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
48
+ declare_meme(:token, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
46
49
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
47
50
  declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (
48
51
  orig_meme = meme.dup
49
52
  meme.__send__(
50
53
  :body=,
51
- ::Proc.new { || (orig_meme.result.token(:"t_#{meme.name}"))}
54
+ ::Object::Proc.new { || (orig_meme.result.token(:"t_#{meme.name}"))}
52
55
  )
53
56
  )}
54
57
  __category__(:transforms).component_eval {(declare_meme(:cache, [], nil, ::Myco.cscope.dup) { |*| (true)})}
55
58
  )}}.instance)}
56
- declare_meme(:rule, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
59
+ declare_meme(:rule, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
57
60
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
61
+ declare_meme(:helper_method, [], nil, ::Myco.cscope.dup) { |name, meme, outer_self| (::Myco::Component.new([::Myco.find_constant(:Rule)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
62
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(
63
+ declare_meme(:name, [], nil, ::Myco.cscope.dup) { |*| (name)}
64
+ declare_meme(:inner, [], nil, ::Myco.cscope.dup) { |*| (meme.result_for(outer_self))}
65
+ declare_meme(:blargy, [], nil, ::Myco.cscope.dup) { |*| ([
66
+ name,
67
+ meme,
68
+ outer_self
69
+ ])}
70
+ )}}.instance)}
58
71
  declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (
59
72
  name = meme.name
73
+ meme_self = self
60
74
  meme.target.declare_meme(
61
75
  name,
62
76
  [:memoize]
63
77
  ) { || (
64
78
  outer_self = self
65
- rule = ::Myco::Component.new([::Myco.find_constant(:Rule)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
66
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(
67
- declare_meme(:name, [], nil, ::Myco.cscope.dup) { |*| (name)}
68
- declare_meme(:inner, [], nil, ::Myco.cscope.dup) { |*| (meme.result_for(outer_self))}
69
- )}}.instance
79
+ rule = meme_self.helper_method(
80
+ name,
81
+ meme,
82
+ outer_self
83
+ )
70
84
  self.rule_table.__send__(
71
85
  :[]=,
72
86
  name,
@@ -11,7 +11,7 @@
11
11
  declare_meme(:stack, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
12
12
  declare_meme(:captures, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
13
13
  declare_meme(:subject, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
14
- declare_meme(:sequence_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Ruby::Hash.new)}
14
+ declare_meme(:sequence_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Object::Hash.new)}
15
15
  declare_meme(:execute, [], nil, ::Myco.cscope.dup) { |*| (self.loop { || (::Myco.branch_op(:"??", ::Myco.branch_op(:"|?", self.ip) {self.handle_fail}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.ip.__send__(
16
16
  :==,
17
17
  true
@@ -1,7 +1,7 @@
1
1
 
2
2
  Parser < BasicObject {
3
3
 
4
- var grammar: Grammar { }
4
+ var grammar: Grammar.new
5
5
  var string: ""
6
6
 
7
7
  var result: null
@@ -2,8 +2,7 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.cscope.for_method_definition::Parser = ::Myco::Component.new([::Myco.find_constant(:BasicObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
4
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
5
- declare_meme(:grammar, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Grammar)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
6
- .tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}.instance)}
5
+ declare_meme(:grammar, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Grammar).new)}
7
6
  declare_meme(:string, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ("")}
8
7
  declare_meme(:result, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (nil)}
9
8
  declare_meme(:make_sequence_table, [[:memoize, []]], nil, ::Myco.cscope.dup) { |grammar| (
@@ -111,7 +111,7 @@ Patterns < EmptyObject {
111
111
  var builder # The fallback delegate for methods that are not capture names
112
112
 
113
113
  method_missing: |name, *args, &block|
114
- captures.fetch(name) { builder.send(name, *args, &block) }
114
+ captures.fetch(name) { builder.__send__(name, *args, &block) }
115
115
 
116
116
  # Implement the action for the reduction in the '!' method.
117
117
  # It will have access to the captures via method_missing.
@@ -150,7 +150,7 @@
150
150
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
151
151
  declare_meme(:captures, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
152
152
  declare_meme(:builder, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
153
- declare_meme(:method_missing, [], nil, ::Myco.cscope.dup) { |name, *args, &block| (self.captures.fetch(name) { || (self.builder.send(
153
+ declare_meme(:method_missing, [], nil, ::Myco.cscope.dup) { |name, *args, &block| (self.captures.fetch(name) { || (self.builder.__send__(
154
154
  name,
155
155
  *args,
156
156
  &block
@@ -27,7 +27,7 @@ Processor < BasicObject {
27
27
  # The environment for performing reduction actions to build an AST in the PEG.
28
28
  # It gives implicit access to both local captures and AST builder methods.
29
29
  var reduction_env:
30
- Patterns::Reduction::Environment { }
30
+ Patterns::Reduction::Environment.new
31
31
  var reduction_env_cscope:
32
32
  ::Rubinius::ConstantScope.new(Patterns::Reduction::Environment) # TODO: fix
33
33
 
@@ -43,7 +43,7 @@ Processor < BasicObject {
43
43
  idx_hash = ::Ruby::Hash.new
44
44
  idx_hash[0] = 0
45
45
  count = 0
46
- idx = 0
46
+ idx = -1
47
47
  loop {
48
48
  idx = string.index("\n", idx + 1)
49
49
  idx || break
@@ -56,7 +56,7 @@ Processor < BasicObject {
56
56
  # Given an index and string, return the row (line) and column numbers
57
57
  position_of: |idx, string| {
58
58
  nl_idx = string.rindex("\n", idx) || 0
59
- row = line_map_for(string).fetch(nl_idx) + 2
59
+ row = line_map_for(string).fetch(nl_idx) + 1
60
60
  col = idx - nl_idx
61
61
  [row, col]
62
62
  }
@@ -38,8 +38,7 @@
38
38
  ))}
39
39
  )}}
40
40
  .tap { |__c__| __c__.__name__ = :Token }
41
- declare_meme(:reduction_env, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Patterns)::Reduction::Environment], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
42
- .tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}.instance)}
41
+ declare_meme(:reduction_env, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Patterns)::Reduction::Environment.new)}
43
42
  declare_meme(:reduction_env_cscope, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Rubinius::ConstantScope.new(::Myco.find_constant(:Patterns)::Reduction::Environment))}
44
43
  declare_meme(:cidx_stack, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
45
44
  declare_meme(:sidx_stack, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
@@ -48,14 +47,14 @@
48
47
  declare_meme(:ridx_stack, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
49
48
  declare_meme(:capt_stack, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
50
49
  declare_meme(:line_map_for, [[:memoize, []]], nil, ::Myco.cscope.dup) { |string| (
51
- idx_hash = ::Ruby::Hash.new
50
+ idx_hash = ::Object::Hash.new
52
51
  idx_hash.__send__(
53
52
  :[]=,
54
53
  0,
55
54
  0
56
55
  )
57
56
  count = 0
58
- idx = 0
57
+ idx = -1
59
58
  self.loop { || (
60
59
  idx = string.index(
61
60
  "\n",
@@ -84,7 +83,7 @@
84
83
  )) {0}
85
84
  row = self.line_map_for(string).fetch(nl_idx).__send__(
86
85
  :+,
87
- 2
86
+ 1
88
87
  )
89
88
  col = idx.__send__(
90
89
  :-,
@@ -95,7 +94,7 @@
95
94
  col
96
95
  ]
97
96
  )}
98
- declare_meme(:push_layer, [], nil, ::Myco.cscope.dup) { |*| (self.capt_stack.push(::Ruby::Hash.new))}
97
+ declare_meme(:push_layer, [], nil, ::Myco.cscope.dup) { |*| (self.capt_stack.push(::Object::Hash.new))}
99
98
  declare_meme(:pop_layer, [], nil, ::Myco.cscope.dup) { |*| (self.capt_stack.pop)}
100
99
  declare_meme(:setup, [], nil, ::Myco.cscope.dup) { |*| (self.push_layer)}
101
100
  declare_meme(:final_captures, [], nil, ::Myco.cscope.dup) { |*| (self.pop_layer.select { |k, v| (k.__send__(
@@ -0,0 +1,35 @@
1
+
2
+ # Implementation from central Myco repository
3
+ # TODO: import instead of copying this code
4
+
5
+ BasicSpec < Object {
6
+ assert: |arg, message="expected "arg.inspect" to be truthy"|
7
+ arg || raise(message)
8
+
9
+ refute: |arg, message="expected "arg.inspect" to be falsey"|
10
+ arg && raise(message)
11
+
12
+ assert_equal: |a, b, message="expected "a.inspect" to equal "b.inspect""|
13
+ a == b || raise(message)
14
+
15
+ refute_equal: |a, b, message="expected "a.inspect" to not equal "b.inspect""|
16
+ a == b && raise(message)
17
+
18
+ assert_is_a: |a, b, message="expected "a.inspect" to be a "b.inspect""|
19
+ a.is_a?(b) || raise(message)
20
+
21
+ name: to_s
22
+
23
+ on creation: {
24
+ self.?tests && (
25
+ STDOUT.print(""self.name" ")
26
+ self.tests.memes.each |name, test| { test.result; STDOUT.print(".") }
27
+ STDOUT.print("\n")
28
+ )
29
+ }
30
+
31
+ [decorators]
32
+
33
+ const it: Decorator { }
34
+ const specify: Decorator { }
35
+ }
@@ -0,0 +1,35 @@
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::BasicSpec = ::Myco::Component.new([::Myco.find_constant(:Object)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(
5
+ declare_meme(:assert, [], nil, ::Myco.cscope.dup) { |arg, message="expected #{arg.inspect} to be truthy"| (::Myco.branch_op(:"||", arg) {self.raise(message)})}
6
+ declare_meme(:refute, [], nil, ::Myco.cscope.dup) { |arg, message="expected #{arg.inspect} to be falsey"| (::Myco.branch_op(:"&&", arg) {self.raise(message)})}
7
+ declare_meme(:assert_equal, [], nil, ::Myco.cscope.dup) { |a, b, message="expected #{a.inspect} to equal #{b.inspect}"| (::Myco.branch_op(:"||", a.__send__(
8
+ :==,
9
+ b
10
+ )) {self.raise(message)})}
11
+ declare_meme(:refute_equal, [], nil, ::Myco.cscope.dup) { |a, b, message="expected #{a.inspect} to not equal #{b.inspect}"| (::Myco.branch_op(:"&&", a.__send__(
12
+ :==,
13
+ b
14
+ )) {self.raise(message)})}
15
+ declare_meme(:assert_is_a, [], nil, ::Myco.cscope.dup) { |a, b, message="expected #{a.inspect} to be a #{b.inspect}"| (::Myco.branch_op(:"||", a.__send__(
16
+ :is_a?,
17
+ b
18
+ )) {self.raise(message)})}
19
+ declare_meme(:name, [], nil, ::Myco.cscope.dup) { |*| (self.to_s)}
20
+ declare_meme(:creation, [[:on, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"&&", (Rubinius::Type.object_respond_to?(self, :tests).false? ? ::Myco::Void : self.tests)) {(
21
+ ::Myco.find_constant(:STDOUT).print("#{self.name} ")
22
+ self.tests.memes.each { |name, test| (
23
+ test.result
24
+ ::Myco.find_constant(:STDOUT).print(".")
25
+ )}
26
+ ::Myco.find_constant(:STDOUT).print("\n")
27
+ )})}
28
+ __category__(:decorators).component_eval {(
29
+ declare_meme(:it, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
30
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}.instance)}
31
+ declare_meme(:specify, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
32
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}.instance)}
33
+ )}
34
+ )}}
35
+ .tap { |__c__| __c__.__name__ = :BasicSpec })}}.instance
@@ -0,0 +1,10 @@
1
+
2
+ BasicSpec {
3
+ name: "Builder"
4
+
5
+ new_builder: Builder { }
6
+
7
+ [tests]
8
+
9
+ it "exists": assert(new_builder)
10
+ }