myco 0.1.8 → 0.1.9
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/instance.rb +13 -3
- data/lib/myco/code_tools/AST.my +0 -2
- data/lib/myco/code_tools/AST.my.rb +0 -1
- data/lib/myco/code_tools/AST/Block.my +15 -4
- data/lib/myco/code_tools/AST/Block.my.rb +16 -3
- data/lib/myco/code_tools/AST/DeclareMeme.my +44 -64
- data/lib/myco/code_tools/AST/DeclareMeme.my.rb +66 -74
- data/lib/myco/code_tools/AST/ToRuby.my +17 -20
- data/lib/myco/code_tools/AST/ToRuby.my.rb +24 -22
- data/lib/myco/code_tools/Parser.my +2 -1
- data/lib/myco/code_tools/Parser.my.rb +2 -1
- data/lib/myco/code_tools/parser/MycoBuilder.my +2 -2
- data/lib/myco/code_tools/parser/MycoBuilder.my.rb +2 -2
- data/lib/myco/code_tools/parser/MycoGrammar.my +28 -21
- data/lib/myco/code_tools/parser/MycoGrammar.my.rb +94 -56
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces.my +10 -11
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces.my.rb +10 -9
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my +25 -3
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my.rb +38 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Capture.my +152 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Capture.my.rb +189 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Common.my +84 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Common.my.rb +114 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Common/Parser.my +139 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/{BytecodeParser.my.rb → Common/Parser.my.rb} +17 -36
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Composite.my +229 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Composite.my.rb +296 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my +8 -25
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my.rb +9 -37
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my +139 -37
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my.rb +206 -36
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my +21 -12
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my.rb +45 -24
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Stream.my +99 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Stream.my.rb +152 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Stream/Parser.my +37 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Stream/Parser.my.rb +57 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/String.my +136 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/String.my.rb +147 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/String/Parser.my +45 -0
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/String/Parser.my.rb +85 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my +31 -25
- data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my.rb +44 -25
- data/lib/myco/code_tools/parser/pegleromyces/spec/Stream/Parser.test.my +49 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Stream/Parser.test.my.rb +119 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Stream/Patterns.test.my +131 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Stream/Patterns.test.my.rb +595 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/{BytecodeParser.test.my → String/Parser.test.my} +41 -2
- data/lib/myco/code_tools/parser/pegleromyces/spec/{BytecodeParser.test.my.rb → String/Parser.test.my.rb} +144 -3
- data/lib/myco/code_tools/parser/pegleromyces/spec/run.my +4 -10
- data/lib/myco/code_tools/parser/pegleromyces/spec/run.my.rb +4 -8
- data/lib/myco/core.my +1 -0
- data/lib/myco/core.my.rb +1 -0
- data/lib/myco/core/BasicObject.my +4 -2
- data/lib/myco/core/BasicObject.my.rb +2 -5
- data/lib/myco/core/Loop.my +5 -0
- data/lib/myco/core/Loop.my.rb +13 -0
- data/lib/myco/dev.rb +1 -0
- data/lib/myco/dev/profile.rb +12 -0
- data/lib/myco/version.rb +3 -3
- metadata +54 -59
- data/lib/myco/code_tools/AST/DeclareDecorator.my +0 -19
- data/lib/myco/code_tools/AST/DeclareDecorator.my.rb +0 -24
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Builder.my +0 -4
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Builder.my.rb +0 -5
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my +0 -420
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my.rb +0 -415
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my +0 -147
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Constructions.my +0 -183
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Constructions.my.rb +0 -370
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Instructions.my +0 -139
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Instructions.my.rb +0 -284
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my +0 -37
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my.rb +0 -24
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my +0 -123
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my.rb +0 -164
- data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my +0 -10
- data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my.rb +0 -9
- data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my +0 -10
- data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my.rb +0 -9
- data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my +0 -229
- data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my.rb +0 -663
- data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my +0 -10
- data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my.rb +0 -9
- data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my +0 -13
- data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my.rb +0 -20
- data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my +0 -54
- data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my.rb +0 -215
@@ -0,0 +1,296 @@
|
|
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::Composite = ::Myco::Component.new([::Myco.find_constant(:EmptyObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
4
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
5
|
+
::Myco.cscope.for_method_definition::Patterns = ::Myco::Component.new([::Myco.find_constant(:EmptyObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
6
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
7
|
+
::Myco.cscope.for_method_definition::UnaryBase = ::Myco::Component.new([::Myco.find_constant(:Common)::Patterns::UnaryBase], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
8
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
9
|
+
.tap { |__c__| __c__.__name__ = :UnaryBase }
|
10
|
+
::Myco.cscope.for_method_definition::BinaryBase = ::Myco::Component.new([::Myco.find_constant(:Common)::Patterns::BinaryBase], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
11
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
12
|
+
.tap { |__c__| __c__.__name__ = :BinaryBase }
|
13
|
+
::Myco.cscope.for_method_definition::NegativePredicate = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
14
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:construct_type, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Constructions)::NegativePredicate)})}}
|
15
|
+
.tap { |__c__| __c__.__name__ = :NegativePredicate }
|
16
|
+
::Myco.cscope.for_method_definition::PositivePredicate = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
17
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:construct_type, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Constructions)::PositivePredicate)})}}
|
18
|
+
.tap { |__c__| __c__.__name__ = :PositivePredicate }
|
19
|
+
::Myco.cscope.for_method_definition::OneOrMore = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
20
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:construct_type, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Constructions)::OneOrMore)})}}
|
21
|
+
.tap { |__c__| __c__.__name__ = :OneOrMore }
|
22
|
+
::Myco.cscope.for_method_definition::ZeroOrOne = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
23
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:construct_type, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Constructions)::ZeroOrOne)})}}
|
24
|
+
.tap { |__c__| __c__.__name__ = :ZeroOrOne }
|
25
|
+
::Myco.cscope.for_method_definition::ZeroOrMore = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
26
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:construct_type, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Constructions)::ZeroOrMore)})}}
|
27
|
+
.tap { |__c__| __c__.__name__ = :ZeroOrMore }
|
28
|
+
::Myco.cscope.for_method_definition::OrderedChoice = ::Myco::Component.new([::Myco.find_constant(:BinaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
29
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:construct_type, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Constructions)::OrderedChoice)})}}
|
30
|
+
.tap { |__c__| __c__.__name__ = :OrderedChoice }
|
31
|
+
::Myco.cscope.for_method_definition::Concatenation = ::Myco::Component.new([::Myco.find_constant(:BinaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
32
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:construct_type, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Constructions)::Concatenation)})}}
|
33
|
+
.tap { |__c__| __c__.__name__ = :Concatenation }
|
34
|
+
)}}
|
35
|
+
.tap { |__c__| __c__.__name__ = :Patterns }
|
36
|
+
::Myco.cscope.for_method_definition::Constructions = ::Myco::Component.new([::Myco.find_constant(:EmptyObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
37
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
38
|
+
::Myco.cscope.for_method_definition::UnaryBase = ::Myco::Component.new([::Myco.find_constant(:Common)::Constructions::UnaryBase], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
39
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
40
|
+
.tap { |__c__| __c__.__name__ = :UnaryBase }
|
41
|
+
::Myco.cscope.for_method_definition::BinaryBase = ::Myco::Component.new([::Myco.find_constant(:Common)::Constructions::BinaryBase], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
42
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
43
|
+
.tap { |__c__| __c__.__name__ = :BinaryBase }
|
44
|
+
::Myco.cscope.for_method_definition::NegativePredicate = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
45
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
46
|
+
.tap { |__c__| __c__.__name__ = :NegativePredicate }
|
47
|
+
::Myco.cscope.for_method_definition::PositivePredicate = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
48
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
49
|
+
.tap { |__c__| __c__.__name__ = :PositivePredicate }
|
50
|
+
::Myco.cscope.for_method_definition::OneOrMore = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
51
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:inlaid, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil})}}
|
52
|
+
.tap { |__c__| __c__.__name__ = :OneOrMore }
|
53
|
+
::Myco.cscope.for_method_definition::ZeroOrOne = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
54
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
55
|
+
.tap { |__c__| __c__.__name__ = :ZeroOrOne }
|
56
|
+
::Myco.cscope.for_method_definition::ZeroOrMore = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
57
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:inlaid, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil})}}
|
58
|
+
.tap { |__c__| __c__.__name__ = :ZeroOrMore }
|
59
|
+
::Myco.cscope.for_method_definition::OrderedChoice = ::Myco::Component.new([::Myco.find_constant(:BinaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
60
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
61
|
+
.tap { |__c__| __c__.__name__ = :OrderedChoice }
|
62
|
+
::Myco.cscope.for_method_definition::Concatenation = ::Myco::Component.new([::Myco.find_constant(:BinaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
63
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
64
|
+
.tap { |__c__| __c__.__name__ = :Concatenation }
|
65
|
+
)}}
|
66
|
+
.tap { |__c__| __c__.__name__ = :Constructions }
|
67
|
+
::Myco.find_constant(:Patterns).component_eval {(
|
68
|
+
::Myco.find_constant(:NegativePredicate).component_eval {(declare_meme(:!, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:PositivePredicate).new({:inner => self.inner}))})}
|
69
|
+
::Myco.find_constant(:PositivePredicate).component_eval {(declare_meme(:!, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:NegativePredicate).new({:inner => self.inner}))})}
|
70
|
+
::Myco.find_constant(:OrderedChoice).component_eval {(declare_meme(:/, [], nil, ::Myco.cscope.dup) { |other| (self.private.binary_right_assoc(
|
71
|
+
self,
|
72
|
+
other,
|
73
|
+
::Myco.find_constant(:OrderedChoice)
|
74
|
+
))})}
|
75
|
+
::Myco.find_constant(:Concatenation).component_eval {(declare_meme(:+, [], nil, ::Myco.cscope.dup) { |other=false| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", other) {self.private.binary_right_assoc(
|
76
|
+
self,
|
77
|
+
other,
|
78
|
+
::Myco.find_constant(:Concatenation)
|
79
|
+
)}) {::Myco.find_constant(:OneOrMore).new({:inner => self})})})}
|
80
|
+
)}
|
81
|
+
::Myco.find_constant(:Constructions).component_eval {(
|
82
|
+
::Myco.find_constant(:NegativePredicate).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
83
|
+
local_fail = g.new_label
|
84
|
+
old_fail = g.overall_fail
|
85
|
+
g.__send__(
|
86
|
+
:overall_fail=,
|
87
|
+
local_fail
|
88
|
+
)
|
89
|
+
self.__send__(
|
90
|
+
:if,
|
91
|
+
self.inner.__send__(:bytecode_can_capture?)
|
92
|
+
) { || (g.push_temp_captures)}
|
93
|
+
g.push_idx
|
94
|
+
self.inner.bytecode(g)
|
95
|
+
g.pop_to_set_idx
|
96
|
+
self.__send__(
|
97
|
+
:if,
|
98
|
+
self.inner.__send__(:bytecode_can_capture?)
|
99
|
+
) { || (g.pop_to_reject_captures)}
|
100
|
+
g.__send__(
|
101
|
+
:overall_fail=,
|
102
|
+
old_fail
|
103
|
+
)
|
104
|
+
g.goto(g.overall_fail)
|
105
|
+
local_fail.__send__(:set!)
|
106
|
+
g.pop_to_set_idx
|
107
|
+
self.__send__(
|
108
|
+
:if,
|
109
|
+
self.inner.__send__(:bytecode_can_capture?)
|
110
|
+
) { || (g.pop_to_reject_captures)}
|
111
|
+
g.__send__(
|
112
|
+
:overall_fail=,
|
113
|
+
old_fail
|
114
|
+
)
|
115
|
+
)})}
|
116
|
+
::Myco.find_constant(:PositivePredicate).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
117
|
+
local_done = g.new_label
|
118
|
+
local_fail = g.new_label
|
119
|
+
old_fail = g.overall_fail
|
120
|
+
g.__send__(
|
121
|
+
:overall_fail=,
|
122
|
+
local_fail
|
123
|
+
)
|
124
|
+
self.__send__(
|
125
|
+
:if,
|
126
|
+
self.inner.__send__(:bytecode_can_capture?)
|
127
|
+
) { || (g.push_temp_captures)}
|
128
|
+
g.push_idx
|
129
|
+
self.inner.bytecode(g)
|
130
|
+
g.pop_to_set_idx
|
131
|
+
self.__send__(
|
132
|
+
:if,
|
133
|
+
self.inner.__send__(:bytecode_can_capture?)
|
134
|
+
) { || (g.pop_to_accept_captures)}
|
135
|
+
g.__send__(
|
136
|
+
:overall_fail=,
|
137
|
+
old_fail
|
138
|
+
)
|
139
|
+
g.goto(local_done)
|
140
|
+
local_fail.__send__(:set!)
|
141
|
+
g.pop_to_set_idx
|
142
|
+
self.__send__(
|
143
|
+
:if,
|
144
|
+
self.inner.__send__(:bytecode_can_capture?)
|
145
|
+
) { || (g.pop_to_reject_captures)}
|
146
|
+
g.__send__(
|
147
|
+
:overall_fail=,
|
148
|
+
old_fail
|
149
|
+
)
|
150
|
+
g.goto(g.overall_fail)
|
151
|
+
local_done.__send__(:set!)
|
152
|
+
)})}
|
153
|
+
::Myco.find_constant(:OneOrMore).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
154
|
+
local_retry = g.new_label
|
155
|
+
local_fail = g.new_label
|
156
|
+
old_fail = g.overall_fail
|
157
|
+
g.__send__(
|
158
|
+
:overall_fail=,
|
159
|
+
local_fail
|
160
|
+
)
|
161
|
+
g.push_false
|
162
|
+
local_retry.__send__(:set!)
|
163
|
+
self.__send__(
|
164
|
+
:if,
|
165
|
+
self.inner.__send__(:bytecode_can_capture?)
|
166
|
+
) { || (g.push_temp_captures)}
|
167
|
+
self.inner.bytecode(g)
|
168
|
+
(Rubinius::Type.object_respond_to?(self.inlaid, :call).false? ? ::Myco::Void : self.inlaid.call)
|
169
|
+
self.__send__(
|
170
|
+
:if,
|
171
|
+
self.inner.__send__(:bytecode_can_capture?)
|
172
|
+
) { || (g.pop_to_accept_captures)}
|
173
|
+
g.pop
|
174
|
+
g.push_true
|
175
|
+
g.goto(local_retry)
|
176
|
+
local_fail.__send__(:set!)
|
177
|
+
self.__send__(
|
178
|
+
:if,
|
179
|
+
self.inner.__send__(:bytecode_can_capture?)
|
180
|
+
) { || (g.pop_to_reject_captures)}
|
181
|
+
g.__send__(
|
182
|
+
:overall_fail=,
|
183
|
+
old_fail
|
184
|
+
)
|
185
|
+
g.goto_if_false(g.overall_fail)
|
186
|
+
)})}
|
187
|
+
::Myco.find_constant(:ZeroOrOne).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
188
|
+
local_done = g.new_label
|
189
|
+
local_fail = g.new_label
|
190
|
+
old_fail = g.overall_fail
|
191
|
+
g.__send__(
|
192
|
+
:overall_fail=,
|
193
|
+
local_fail
|
194
|
+
)
|
195
|
+
self.__send__(
|
196
|
+
:if,
|
197
|
+
self.inner.__send__(:bytecode_can_capture?)
|
198
|
+
) { || (g.push_temp_captures)}
|
199
|
+
g.push_idx
|
200
|
+
self.inner.bytecode(g)
|
201
|
+
g.pop
|
202
|
+
self.__send__(
|
203
|
+
:if,
|
204
|
+
self.inner.__send__(:bytecode_can_capture?)
|
205
|
+
) { || (g.pop_to_accept_captures)}
|
206
|
+
g.__send__(
|
207
|
+
:overall_fail=,
|
208
|
+
old_fail
|
209
|
+
)
|
210
|
+
g.goto(local_done)
|
211
|
+
local_fail.__send__(:set!)
|
212
|
+
g.pop_to_set_idx
|
213
|
+
self.__send__(
|
214
|
+
:if,
|
215
|
+
self.inner.__send__(:bytecode_can_capture?)
|
216
|
+
) { || (g.pop_to_reject_captures)}
|
217
|
+
g.__send__(
|
218
|
+
:overall_fail=,
|
219
|
+
old_fail
|
220
|
+
)
|
221
|
+
local_done.__send__(:set!)
|
222
|
+
)})}
|
223
|
+
::Myco.find_constant(:ZeroOrMore).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
224
|
+
local_retry = g.new_label
|
225
|
+
local_fail = g.new_label
|
226
|
+
old_fail = g.overall_fail
|
227
|
+
g.__send__(
|
228
|
+
:overall_fail=,
|
229
|
+
local_fail
|
230
|
+
)
|
231
|
+
local_retry.__send__(:set!)
|
232
|
+
self.__send__(
|
233
|
+
:if,
|
234
|
+
self.inner.__send__(:bytecode_can_capture?)
|
235
|
+
) { || (g.push_temp_captures)}
|
236
|
+
self.inner.bytecode(g)
|
237
|
+
(Rubinius::Type.object_respond_to?(self.inlaid, :call).false? ? ::Myco::Void : self.inlaid.call)
|
238
|
+
self.__send__(
|
239
|
+
:if,
|
240
|
+
self.inner.__send__(:bytecode_can_capture?)
|
241
|
+
) { || (g.pop_to_accept_captures)}
|
242
|
+
g.goto(local_retry)
|
243
|
+
local_fail.__send__(:set!)
|
244
|
+
self.__send__(
|
245
|
+
:if,
|
246
|
+
self.inner.__send__(:bytecode_can_capture?)
|
247
|
+
) { || (g.pop_to_reject_captures)}
|
248
|
+
g.__send__(
|
249
|
+
:overall_fail=,
|
250
|
+
old_fail
|
251
|
+
)
|
252
|
+
)})}
|
253
|
+
::Myco.find_constant(:OrderedChoice).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
254
|
+
local_done = g.new_label
|
255
|
+
local_fail = g.new_label
|
256
|
+
old_fail = g.overall_fail
|
257
|
+
g.__send__(
|
258
|
+
:overall_fail=,
|
259
|
+
local_fail
|
260
|
+
)
|
261
|
+
self.__send__(
|
262
|
+
:if,
|
263
|
+
self.first.__send__(:bytecode_can_capture?)
|
264
|
+
) { || (g.push_temp_captures)}
|
265
|
+
g.push_idx
|
266
|
+
self.first.bytecode(g)
|
267
|
+
g.pop
|
268
|
+
self.__send__(
|
269
|
+
:if,
|
270
|
+
self.first.__send__(:bytecode_can_capture?)
|
271
|
+
) { || (g.pop_to_accept_captures)}
|
272
|
+
g.__send__(
|
273
|
+
:overall_fail=,
|
274
|
+
old_fail
|
275
|
+
)
|
276
|
+
g.goto(local_done)
|
277
|
+
local_fail.__send__(:set!)
|
278
|
+
g.pop_to_set_idx
|
279
|
+
self.__send__(
|
280
|
+
:if,
|
281
|
+
self.first.__send__(:bytecode_can_capture?)
|
282
|
+
) { || (g.pop_to_reject_captures)}
|
283
|
+
g.__send__(
|
284
|
+
:overall_fail=,
|
285
|
+
old_fail
|
286
|
+
)
|
287
|
+
self.second.bytecode(g)
|
288
|
+
local_done.__send__(:set!)
|
289
|
+
)})}
|
290
|
+
::Myco.find_constant(:Concatenation).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
291
|
+
self.first.bytecode(g)
|
292
|
+
self.second.bytecode(g)
|
293
|
+
)})}
|
294
|
+
)}
|
295
|
+
)}}
|
296
|
+
.tap { |__c__| __c__.__name__ = :Composite })}}.instance
|
@@ -1,17 +1,5 @@
|
|
1
1
|
|
2
|
-
Grammar < BasicObject, Patterns::ShorthandMethods {
|
3
|
-
|
4
|
-
Rule < Patterns::UnaryBase {
|
5
|
-
construct_rule: inner.construct
|
6
|
-
construct: RuleReference.new(name:name)
|
7
|
-
}
|
8
|
-
|
9
|
-
RuleReference < Constructions::UnaryBase {
|
10
|
-
var name
|
11
|
-
sequence: [[:call, name]]
|
12
|
-
bytecode: |m| m.call(name)
|
13
|
-
bytecode_can_capture: true
|
14
|
-
}
|
2
|
+
Grammar < BasicObject, Common::Patterns::ShorthandMethods {
|
15
3
|
|
16
4
|
var rule_table: ::Ruby::Hash.new
|
17
5
|
|
@@ -21,7 +9,7 @@ Grammar < BasicObject, Patterns::ShorthandMethods {
|
|
21
9
|
# Consider all rules with "root" in the name
|
22
10
|
rules.memes.each |name, meme| {
|
23
11
|
meme.name.to_s.include?("root") && (
|
24
|
-
meme.result_for(rules).
|
12
|
+
meme.result_for(rules).inner.construct
|
25
13
|
)
|
26
14
|
}
|
27
15
|
|
@@ -30,7 +18,7 @@ Grammar < BasicObject, Patterns::ShorthandMethods {
|
|
30
18
|
new_keys = rule_table.keys - seen_keys
|
31
19
|
new_keys.empty? && break
|
32
20
|
new_keys.each |key| {
|
33
|
-
rule_table[key].
|
21
|
+
rule_table[key].inner.construct
|
34
22
|
seen_keys.push(key)
|
35
23
|
}
|
36
24
|
}
|
@@ -48,20 +36,15 @@ Grammar < BasicObject, Patterns::ShorthandMethods {
|
|
48
36
|
}
|
49
37
|
|
50
38
|
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
|
-
|
58
39
|
apply: |meme| {
|
59
40
|
name = meme.name
|
60
|
-
meme_self = self
|
61
41
|
# TODO: use some kind of Decorator#wrap mechanism instead
|
62
42
|
meme.target.declare_meme(name, [:memoize]) {
|
63
43
|
outer_self = self
|
64
|
-
rule =
|
44
|
+
rule = Capture::Patterns::RuleCall {
|
45
|
+
name: name
|
46
|
+
inner: meme.result_for(outer_self)
|
47
|
+
}
|
65
48
|
rule_table[name] = rule
|
66
49
|
rule
|
67
50
|
}
|
@@ -71,5 +54,5 @@ Grammar < BasicObject, Patterns::ShorthandMethods {
|
|
71
54
|
}
|
72
55
|
|
73
56
|
[rules]
|
74
|
-
rule root: Patterns::AnyCharacter.new.*
|
57
|
+
rule root: String::Patterns::AnyCharacter.new.*
|
75
58
|
}
|
@@ -2,32 +2,15 @@
|
|
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::Grammar = ::Myco::Component.new([
|
4
4
|
::Myco.find_constant(:BasicObject),
|
5
|
-
::Myco.find_constant(:
|
5
|
+
::Myco.find_constant(:Common)::Patterns::ShorthandMethods
|
6
6
|
], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
7
7
|
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
8
|
-
::Myco.cscope.for_method_definition::Rule = ::Myco::Component.new([::Myco.find_constant(:Patterns)::UnaryBase], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
9
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
10
|
-
declare_meme(:construct_rule, [], nil, ::Myco.cscope.dup) { |*| (self.inner.construct)}
|
11
|
-
declare_meme(:construct, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:RuleReference).new({:name => self.name}))}
|
12
|
-
)}}
|
13
|
-
.tap { |__c__| __c__.__name__ = :Rule }
|
14
|
-
::Myco.cscope.for_method_definition::RuleReference = ::Myco::Component.new([::Myco.find_constant(:Constructions)::UnaryBase], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
15
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
16
|
-
declare_meme(:name, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
17
|
-
declare_meme(:sequence, [], nil, ::Myco.cscope.dup) { |*| ([[
|
18
|
-
:call,
|
19
|
-
self.name
|
20
|
-
]])}
|
21
|
-
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.call(self.name))}
|
22
|
-
declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (true)}
|
23
|
-
)}}
|
24
|
-
.tap { |__c__| __c__.__name__ = :RuleReference }
|
25
8
|
declare_meme(:rule_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Object::Hash.new)}
|
26
9
|
declare_meme(:construct_all_rules, [], nil, ::Myco.cscope.dup) { |*| (
|
27
10
|
self.rules.memes.each { |name, meme| (::Myco.branch_op(:"&&", meme.name.to_s.__send__(
|
28
11
|
:include?,
|
29
12
|
"root"
|
30
|
-
)) {meme.result_for(self.rules).
|
13
|
+
)) {meme.result_for(self.rules).inner.construct})}
|
31
14
|
seen_keys = []
|
32
15
|
self.loop { || (
|
33
16
|
new_keys = self.rule_table.keys.__send__(
|
@@ -39,7 +22,7 @@
|
|
39
22
|
self.rule_table.__send__(
|
40
23
|
:[],
|
41
24
|
key
|
42
|
-
).
|
25
|
+
).inner.construct
|
43
26
|
seen_keys.push(key)
|
44
27
|
)}
|
45
28
|
)}
|
@@ -58,29 +41,18 @@
|
|
58
41
|
)}}.instance)}
|
59
42
|
declare_meme(:rule, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
60
43
|
.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)}
|
71
44
|
declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (
|
72
45
|
name = meme.name
|
73
|
-
meme_self = self
|
74
46
|
meme.target.declare_meme(
|
75
47
|
name,
|
76
48
|
[:memoize]
|
77
49
|
) { || (
|
78
50
|
outer_self = self
|
79
|
-
rule =
|
80
|
-
|
81
|
-
|
82
|
-
outer_self
|
83
|
-
)
|
51
|
+
rule = ::Myco::Component.new([::Myco.find_constant(:Capture)::Patterns::RuleCall], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
52
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
53
|
+
declare_meme(:name, [], nil, ::Myco.cscope.dup) { |*| (name)}
|
54
|
+
declare_meme(:inner, [], nil, ::Myco.cscope.dup) { |*| (meme.result_for(outer_self))}
|
55
|
+
)}}.instance
|
84
56
|
self.rule_table.__send__(
|
85
57
|
:[]=,
|
86
58
|
name,
|
@@ -92,6 +64,6 @@
|
|
92
64
|
__category__(:transforms).component_eval {(declare_meme(:expose, [], nil, ::Myco.cscope.dup) { |*| (false)})}
|
93
65
|
)}}.instance)}
|
94
66
|
)}
|
95
|
-
__category__(:rules).component_eval {(declare_meme(:root, [[:rule, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:
|
67
|
+
__category__(:rules).component_eval {(declare_meme(:root, [[:rule, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:String)::Patterns::AnyCharacter.new.__send__(:*))})}
|
96
68
|
)}}
|
97
69
|
.tap { |__c__| __c__.__name__ = :Grammar })}}.instance
|
@@ -1,42 +1,144 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
2
|
+
Common << {
|
3
|
+
Parser < BasicObject {
|
4
|
+
State < BasicObject {
|
5
|
+
var string
|
6
|
+
var start_idx
|
7
|
+
var end_idx
|
8
|
+
var rule
|
9
|
+
var result
|
10
|
+
|
11
|
+
var error_idx
|
12
|
+
var error_row
|
13
|
+
var error_col
|
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 debug_mode: false
|
25
|
+
|
26
|
+
var grammar: Grammar.new
|
27
|
+
var builder: null
|
28
|
+
|
29
|
+
new_worker: set_up_worker(prototype.new)
|
30
|
+
new_processor: Processor.new(builder: builder)
|
31
|
+
|
32
|
+
var prototype: compile_prototype
|
33
|
+
|
34
|
+
refresh: self.prototype = compile_prototype
|
35
|
+
|
36
|
+
compile_prototype: {
|
37
|
+
proto = Component.new
|
38
|
+
grammar.construct_all_rules
|
39
|
+
grammar.rule_table.each |name, rule| {
|
40
|
+
compile_rule_into(proto, name, rule)
|
41
|
+
}
|
42
|
+
proto
|
43
|
+
}
|
44
|
+
|
45
|
+
compile_rule_into: |proto, name, rule| {
|
46
|
+
construct = rule.inner.construct
|
47
|
+
|
48
|
+
Myco.add_dynamic_method(proto, name, "(compiled parser)") |g| {
|
49
|
+
g.extend(BytecodeHelpers)
|
50
|
+
g.debug_mode = self.debug_mode
|
51
|
+
g.rule_start
|
52
|
+
construct.bytecode(g)
|
53
|
+
g.rule_finish
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
compile_generator: |name, file, line=1, &block| {
|
58
|
+
g = Myco::ToolSet::Generator.new
|
59
|
+
g.name = name
|
60
|
+
g.file = file
|
61
|
+
g.set_line(line)
|
62
|
+
|
63
|
+
block.call(g)
|
64
|
+
|
65
|
+
g.ret
|
66
|
+
g.close
|
67
|
+
g.use_detected
|
68
|
+
g
|
38
69
|
}
|
39
70
|
|
40
|
-
|
71
|
+
compile_code: |name, file, line=1, &block| {
|
72
|
+
g = compile_generator(name, file, line, &block)
|
73
|
+
g.encode
|
74
|
+
g.package(Rubinius::CompiledCode)
|
75
|
+
}
|
76
|
+
|
77
|
+
save_prototype: |filename| {
|
78
|
+
code = compile_code(:__script__, :"(snippet)") |g| {
|
79
|
+
g.push_cpath_top; g.find_const(:Class)
|
80
|
+
g.create_block(compile_generator(:__block__, :"(snippet)") |g| {
|
81
|
+
prototype.instance_methods.each |name| {
|
82
|
+
code = prototype.instance_method(name).executable
|
83
|
+
if(code.is_a?(Rubinius::CompiledCode)) {
|
84
|
+
g.push_rubinius
|
85
|
+
g.push_literal(name)
|
86
|
+
g.push_literal(code)
|
87
|
+
g.push_scope
|
88
|
+
g.push_variables; g.send(:method_visibility, 0)
|
89
|
+
g.send(:add_defn_method, 4)
|
90
|
+
}
|
91
|
+
}
|
92
|
+
})
|
93
|
+
g.send_with_block(:new, 0)
|
94
|
+
}
|
95
|
+
|
96
|
+
Myco::ToolSet::CompiledFile.dump(code, filename, Rubinius::Signature, Rubinius::RUBY_LIB_VERSION)
|
97
|
+
}
|
98
|
+
|
99
|
+
load_prototype: |filename| {
|
100
|
+
loader = Myco::CodeLoader::BytecodeLoader.new(filename)
|
101
|
+
loader.bind_to(call_depth:1)
|
102
|
+
self.prototype = loader.load
|
103
|
+
}
|
104
|
+
|
105
|
+
set_up_worker: |worker| {
|
106
|
+
worker.__set_ivar__(:"@captures", [])
|
107
|
+
worker.__set_ivar__(:"@highest_idx", 0)
|
108
|
+
worker
|
109
|
+
}
|
110
|
+
|
111
|
+
captures_of_worker: |worker|
|
112
|
+
worker.__get_ivar__(:"@captures")
|
113
|
+
|
114
|
+
highest_idx_of_worker: |worker|
|
115
|
+
worker.__get_ivar__(:"@highest_idx")
|
116
|
+
|
117
|
+
|
118
|
+
# Match and process the given string using the current grammar
|
119
|
+
parse: |string, rule:"root", start_idx:0| {
|
120
|
+
worker = new_worker
|
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
|
+
)
|
127
|
+
|
128
|
+
state.end_idx = worker.__send__(state.rule, state.string, state.start_idx)
|
129
|
+
|
130
|
+
state.end_idx &? (
|
131
|
+
processor.string = state.string
|
132
|
+
processor.capture_items = captures_of_worker(worker)
|
133
|
+
grammar.?tokenizer && (processor.tokenizer = grammar.tokenizer)
|
134
|
+
state.result = processor.process
|
135
|
+
) ?? (
|
136
|
+
state.error_idx = highest_idx_of_worker(worker)
|
137
|
+
pos = processor.position_of(state.error_idx, state.string)
|
138
|
+
state.error_row = pos.first
|
139
|
+
state.error_col = pos.last
|
140
|
+
)
|
141
|
+
state
|
142
|
+
}
|
41
143
|
}
|
42
144
|
}
|