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
@@ -1,24 +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::Machine = ::Myco::Component.new([
|
4
|
-
::Myco.find_constant(:BasicObject),
|
5
|
-
::Myco.find_constant(:Instructions)
|
6
|
-
], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
7
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
8
|
-
declare_meme(:ip, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (0)}
|
9
|
-
declare_meme(:ipk, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (:root)}
|
10
|
-
declare_meme(:idx, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (0)}
|
11
|
-
declare_meme(:stack, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
|
12
|
-
declare_meme(:captures, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
|
13
|
-
declare_meme(:subject, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
|
14
|
-
declare_meme(:sequence_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Object::Hash.new)}
|
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
|
-
:==,
|
17
|
-
true
|
18
|
-
)) {self.__send__(:break)}) {self.send(*self.sequence_table.fetch(self.ipk).__send__(
|
19
|
-
:[],
|
20
|
-
self.ip
|
21
|
-
))}})})}
|
22
|
-
declare_meme(:had_failure, [], nil, ::Myco.cscope.dup) { |*| (self.ip.__send__(:!))}
|
23
|
-
)}}
|
24
|
-
.tap { |__c__| __c__.__name__ = :Machine })}}.instance
|
@@ -1,123 +0,0 @@
|
|
1
|
-
|
2
|
-
Patterns < EmptyObject {
|
3
|
-
|
4
|
-
##
|
5
|
-
# Basic types of patterns.
|
6
|
-
|
7
|
-
Base < BasicObject { var name: parent_meme.name }
|
8
|
-
UnaryBase < Base { var inner }
|
9
|
-
BinaryBase < Base { var first, var second }
|
10
|
-
|
11
|
-
AnyCharacter < Base { }
|
12
|
-
Character < Base { var code }
|
13
|
-
CharacterString < Base { var codes } # Concatenation for Characters
|
14
|
-
CharacterSet < Base { var codes } # OrderedChoice for Characters
|
15
|
-
CharacterRange < Base { var start, var stop }
|
16
|
-
|
17
|
-
NegativePredicate < UnaryBase { }
|
18
|
-
PositivePredicate < UnaryBase { }
|
19
|
-
OneOrMore < UnaryBase { }
|
20
|
-
ZeroOrOne < UnaryBase { }
|
21
|
-
ZeroOrMore < UnaryBase { }
|
22
|
-
OrderedChoice < BinaryBase { }
|
23
|
-
Concatenation < BinaryBase { }
|
24
|
-
|
25
|
-
NamedCapture < UnaryBase { }
|
26
|
-
NamedTextCapture < UnaryBase { }
|
27
|
-
NamedTokenCapture < UnaryBase { }
|
28
|
-
Reduction < UnaryBase { var block, var args: [] }
|
29
|
-
|
30
|
-
##
|
31
|
-
# Shorthand methods for creating primitive patterns
|
32
|
-
|
33
|
-
ShorthandMethods < EmptyObject {
|
34
|
-
any: AnyCharacter.new
|
35
|
-
char: |character| Character.new(code:character.ord)
|
36
|
-
str: |string| CharacterString.new(codes:string.each_char.map(&:ord))
|
37
|
-
set: |string| CharacterSet.new(codes:string.each_char.map(&:ord))
|
38
|
-
range: |start, stop| CharacterRange.new(start:start.ord, stop:stop.ord)
|
39
|
-
r: |pattern, &block| Reduction.new(inner:pattern, block:block)
|
40
|
-
}
|
41
|
-
|
42
|
-
##
|
43
|
-
# Operator overloading for combining and modifying patterns.
|
44
|
-
#
|
45
|
-
# Each operation returns a new Pattern object composed of the operands
|
46
|
-
# so that complex grammars can be specified with relatively succint syntax.
|
47
|
-
|
48
|
-
Base << {
|
49
|
-
"!": NegativePredicate .new(inner:self)
|
50
|
-
"/": |other| OrderedChoice .new(first:self, second:other)
|
51
|
-
"+": |other=false|
|
52
|
-
other &? Concatenation .new(first:self, second:other)
|
53
|
-
?? OneOrMore .new(inner:self)
|
54
|
-
"-": |other=false|
|
55
|
-
other &? ErrorCondition .new() # TODO: add exception handling to Myco
|
56
|
-
?? ZeroOrOne .new(inner:self)
|
57
|
-
"*": |other=false|
|
58
|
-
other &? ErrorCondition .new()
|
59
|
-
?? ZeroOrMore .new(inner:self)
|
60
|
-
|
61
|
-
"[]": |name| NamedCapture .new(inner:self, name:name)
|
62
|
-
text: |name=:text|
|
63
|
-
NamedTextCapture .new(inner:self, name:name)
|
64
|
-
token: |name|
|
65
|
-
NamedTokenCapture .new(inner:self, name:name)
|
66
|
-
|
67
|
-
[private]
|
68
|
-
|
69
|
-
# Add |other| to |orig| in a right-associative tree of type |type|
|
70
|
-
binary_right_assoc: |orig, other, type| {
|
71
|
-
cursor = orig
|
72
|
-
loop {
|
73
|
-
unless(cursor.second.is_a?(type)) { break }
|
74
|
-
cursor = cursor.second
|
75
|
-
}
|
76
|
-
cursor.second = type.new(first:cursor.second, second:other)
|
77
|
-
orig
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
NegativePredicate << {
|
82
|
-
# Invert the polarity of the predicate instead of nesting the predicate
|
83
|
-
"!": PositivePredicate.new(inner:inner)
|
84
|
-
}
|
85
|
-
|
86
|
-
PositivePredicate << {
|
87
|
-
# Invert the polarity of the predicate instead of nesting the predicate
|
88
|
-
"!": NegativePredicate.new(inner:inner)
|
89
|
-
}
|
90
|
-
|
91
|
-
OrderedChoice << {
|
92
|
-
# Build a right-associative tree if the first operand of another "/"
|
93
|
-
"/": |other|
|
94
|
-
private.binary_right_assoc(self, other, OrderedChoice)
|
95
|
-
}
|
96
|
-
|
97
|
-
Concatenation << {
|
98
|
-
# Build a right-associative tree if the first operand of another "+"
|
99
|
-
"+": |other=false|
|
100
|
-
other
|
101
|
-
&? private.binary_right_assoc(self, other, Concatenation)
|
102
|
-
?? OneOrMore.new(inner:self)
|
103
|
-
}
|
104
|
-
|
105
|
-
##
|
106
|
-
# Reduction and associated named captures implementation
|
107
|
-
|
108
|
-
Reduction << {
|
109
|
-
Environment < EmptyObject, BasicDecorators {
|
110
|
-
var captures # A Hash of capture names to values
|
111
|
-
var builder # The fallback delegate for methods that are not capture names
|
112
|
-
|
113
|
-
method_missing: |name, *args, &block|
|
114
|
-
captures.fetch(name) { builder.__send__(name, *args, &block) }
|
115
|
-
|
116
|
-
# Implement the action for the reduction in the '!' method.
|
117
|
-
# It will have access to the captures via method_missing.
|
118
|
-
"!": null
|
119
|
-
}
|
120
|
-
|
121
|
-
code: block.block.compiled_code
|
122
|
-
}
|
123
|
-
}
|
@@ -1,164 +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::Patterns = ::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::Base = ::Myco::Component.new([::Myco.find_constant(:BasicObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
6
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:name, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (self.parent_meme.name)})}}
|
7
|
-
.tap { |__c__| __c__.__name__ = :Base }
|
8
|
-
::Myco.cscope.for_method_definition::UnaryBase = ::Myco::Component.new([::Myco.find_constant(:Base)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
9
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:inner, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil})}}
|
10
|
-
.tap { |__c__| __c__.__name__ = :UnaryBase }
|
11
|
-
::Myco.cscope.for_method_definition::BinaryBase = ::Myco::Component.new([::Myco.find_constant(:Base)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
12
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
13
|
-
declare_meme(:first, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
14
|
-
declare_meme(:second, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
15
|
-
)}}
|
16
|
-
.tap { |__c__| __c__.__name__ = :BinaryBase }
|
17
|
-
::Myco.cscope.for_method_definition::AnyCharacter = ::Myco::Component.new([::Myco.find_constant(:Base)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
18
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
19
|
-
.tap { |__c__| __c__.__name__ = :AnyCharacter }
|
20
|
-
::Myco.cscope.for_method_definition::Character = ::Myco::Component.new([::Myco.find_constant(:Base)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
21
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:code, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil})}}
|
22
|
-
.tap { |__c__| __c__.__name__ = :Character }
|
23
|
-
::Myco.cscope.for_method_definition::CharacterString = ::Myco::Component.new([::Myco.find_constant(:Base)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
24
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:codes, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil})}}
|
25
|
-
.tap { |__c__| __c__.__name__ = :CharacterString }
|
26
|
-
::Myco.cscope.for_method_definition::CharacterSet = ::Myco::Component.new([::Myco.find_constant(:Base)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
27
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:codes, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil})}}
|
28
|
-
.tap { |__c__| __c__.__name__ = :CharacterSet }
|
29
|
-
::Myco.cscope.for_method_definition::CharacterRange = ::Myco::Component.new([::Myco.find_constant(:Base)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
30
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
31
|
-
declare_meme(:start, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
32
|
-
declare_meme(:stop, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
33
|
-
)}}
|
34
|
-
.tap { |__c__| __c__.__name__ = :CharacterRange }
|
35
|
-
::Myco.cscope.for_method_definition::NegativePredicate = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
36
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
37
|
-
.tap { |__c__| __c__.__name__ = :NegativePredicate }
|
38
|
-
::Myco.cscope.for_method_definition::PositivePredicate = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
39
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
40
|
-
.tap { |__c__| __c__.__name__ = :PositivePredicate }
|
41
|
-
::Myco.cscope.for_method_definition::OneOrMore = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
42
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
43
|
-
.tap { |__c__| __c__.__name__ = :OneOrMore }
|
44
|
-
::Myco.cscope.for_method_definition::ZeroOrOne = ::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__ = :ZeroOrOne }
|
47
|
-
::Myco.cscope.for_method_definition::ZeroOrMore = ::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__ = :ZeroOrMore }
|
50
|
-
::Myco.cscope.for_method_definition::OrderedChoice = ::Myco::Component.new([::Myco.find_constant(:BinaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
51
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
52
|
-
.tap { |__c__| __c__.__name__ = :OrderedChoice }
|
53
|
-
::Myco.cscope.for_method_definition::Concatenation = ::Myco::Component.new([::Myco.find_constant(:BinaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
54
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
55
|
-
.tap { |__c__| __c__.__name__ = :Concatenation }
|
56
|
-
::Myco.cscope.for_method_definition::NamedCapture = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
57
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
58
|
-
.tap { |__c__| __c__.__name__ = :NamedCapture }
|
59
|
-
::Myco.cscope.for_method_definition::NamedTextCapture = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
60
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
61
|
-
.tap { |__c__| __c__.__name__ = :NamedTextCapture }
|
62
|
-
::Myco.cscope.for_method_definition::NamedTokenCapture = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
63
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
64
|
-
.tap { |__c__| __c__.__name__ = :NamedTokenCapture }
|
65
|
-
::Myco.cscope.for_method_definition::Reduction = ::Myco::Component.new([::Myco.find_constant(:UnaryBase)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
66
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
67
|
-
declare_meme(:block, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
68
|
-
declare_meme(:args, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
|
69
|
-
)}}
|
70
|
-
.tap { |__c__| __c__.__name__ = :Reduction }
|
71
|
-
::Myco.cscope.for_method_definition::ShorthandMethods = ::Myco::Component.new([::Myco.find_constant(:EmptyObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
72
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
73
|
-
declare_meme(:any, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:AnyCharacter).new)}
|
74
|
-
declare_meme(:char, [], nil, ::Myco.cscope.dup) { |character| (::Myco.find_constant(:Character).new({:code => character.ord}))}
|
75
|
-
declare_meme(:str, [], nil, ::Myco.cscope.dup) { |string| (::Myco.find_constant(:CharacterString).new({:codes => string.each_char.map(&:ord)}))}
|
76
|
-
declare_meme(:set, [], nil, ::Myco.cscope.dup) { |string| (::Myco.find_constant(:CharacterSet).new({:codes => string.each_char.map(&:ord)}))}
|
77
|
-
declare_meme(:range, [], nil, ::Myco.cscope.dup) { |start, stop| (::Myco.find_constant(:CharacterRange).new({
|
78
|
-
:start => start.ord,
|
79
|
-
:stop => stop.ord
|
80
|
-
}))}
|
81
|
-
declare_meme(:r, [], nil, ::Myco.cscope.dup) { |pattern, &block| (::Myco.find_constant(:Reduction).new({
|
82
|
-
:inner => pattern,
|
83
|
-
:block => block
|
84
|
-
}))}
|
85
|
-
)}}
|
86
|
-
.tap { |__c__| __c__.__name__ = :ShorthandMethods }
|
87
|
-
::Myco.find_constant(:Base).component_eval {(
|
88
|
-
declare_meme(:!, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:NegativePredicate).new({:inner => self}))}
|
89
|
-
declare_meme(:/, [], nil, ::Myco.cscope.dup) { |other| (::Myco.find_constant(:OrderedChoice).new({
|
90
|
-
:first => self,
|
91
|
-
:second => other
|
92
|
-
}))}
|
93
|
-
declare_meme(:+, [], nil, ::Myco.cscope.dup) { |other=false| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", other) {::Myco.find_constant(:Concatenation).new({
|
94
|
-
:first => self,
|
95
|
-
:second => other
|
96
|
-
})}) {::Myco.find_constant(:OneOrMore).new({:inner => self})})}
|
97
|
-
declare_meme(:-, [], nil, ::Myco.cscope.dup) { |other=false| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", other) {::Myco.find_constant(:ErrorCondition).new}) {::Myco.find_constant(:ZeroOrOne).new({:inner => self})})}
|
98
|
-
declare_meme(:*, [], nil, ::Myco.cscope.dup) { |other=false| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", other) {::Myco.find_constant(:ErrorCondition).new}) {::Myco.find_constant(:ZeroOrMore).new({:inner => self})})}
|
99
|
-
declare_meme(:[], [], nil, ::Myco.cscope.dup) { |name| (::Myco.find_constant(:NamedCapture).new({
|
100
|
-
:inner => self,
|
101
|
-
:name => name
|
102
|
-
}))}
|
103
|
-
declare_meme(:text, [], nil, ::Myco.cscope.dup) { |name=:text| (::Myco.find_constant(:NamedTextCapture).new({
|
104
|
-
:inner => self,
|
105
|
-
:name => name
|
106
|
-
}))}
|
107
|
-
declare_meme(:token, [], nil, ::Myco.cscope.dup) { |name| (::Myco.find_constant(:NamedTokenCapture).new({
|
108
|
-
:inner => self,
|
109
|
-
:name => name
|
110
|
-
}))}
|
111
|
-
__category__(:private).component_eval {(declare_meme(:binary_right_assoc, [], nil, ::Myco.cscope.dup) { |orig, other, type| (
|
112
|
-
cursor = orig
|
113
|
-
self.loop { || (
|
114
|
-
self.__send__(
|
115
|
-
:unless,
|
116
|
-
cursor.second.__send__(
|
117
|
-
:is_a?,
|
118
|
-
type
|
119
|
-
)
|
120
|
-
) { || (self.__send__(:break))}
|
121
|
-
cursor = cursor.second
|
122
|
-
)}
|
123
|
-
cursor.__send__(
|
124
|
-
:second=,
|
125
|
-
type.new({
|
126
|
-
:first => cursor.second,
|
127
|
-
:second => other
|
128
|
-
})
|
129
|
-
)
|
130
|
-
orig
|
131
|
-
)})}
|
132
|
-
)}
|
133
|
-
::Myco.find_constant(:NegativePredicate).component_eval {(declare_meme(:!, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:PositivePredicate).new({:inner => self.inner}))})}
|
134
|
-
::Myco.find_constant(:PositivePredicate).component_eval {(declare_meme(:!, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:NegativePredicate).new({:inner => self.inner}))})}
|
135
|
-
::Myco.find_constant(:OrderedChoice).component_eval {(declare_meme(:/, [], nil, ::Myco.cscope.dup) { |other| (self.private.binary_right_assoc(
|
136
|
-
self,
|
137
|
-
other,
|
138
|
-
::Myco.find_constant(:OrderedChoice)
|
139
|
-
))})}
|
140
|
-
::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(
|
141
|
-
self,
|
142
|
-
other,
|
143
|
-
::Myco.find_constant(:Concatenation)
|
144
|
-
)}) {::Myco.find_constant(:OneOrMore).new({:inner => self})})})}
|
145
|
-
::Myco.find_constant(:Reduction).component_eval {(
|
146
|
-
::Myco.cscope.for_method_definition::Environment = ::Myco::Component.new([
|
147
|
-
::Myco.find_constant(:EmptyObject),
|
148
|
-
::Myco.find_constant(:BasicDecorators)
|
149
|
-
], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
150
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
151
|
-
declare_meme(:captures, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
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__(
|
154
|
-
name,
|
155
|
-
*args,
|
156
|
-
&block
|
157
|
-
))})}
|
158
|
-
declare_meme(:!, [], nil, ::Myco.cscope.dup) { |*| (nil)}
|
159
|
-
)}}
|
160
|
-
.tap { |__c__| __c__.__name__ = :Environment }
|
161
|
-
declare_meme(:code, [], nil, ::Myco.cscope.dup) { |*| (self.block.block.compiled_code)}
|
162
|
-
)}
|
163
|
-
)}}
|
164
|
-
.tap { |__c__| __c__.__name__ = :Patterns })}}.instance
|
@@ -1,9 +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::Component.new([::Myco.find_constant(:BasicSpec)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
4
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
5
|
-
declare_meme(:name, [], nil, ::Myco.cscope.dup) { |*| ("Builder")}
|
6
|
-
declare_meme(:new_builder, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Builder)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
7
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}.instance)}
|
8
|
-
__category__(:tests).component_eval {(declare_meme(:exists, [[:it, []]], nil, ::Myco.cscope.dup) { |*| (self.assert(self.new_builder))})}
|
9
|
-
)}}.instance)}}.instance
|
@@ -1,9 +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::Component.new([::Myco.find_constant(:BasicSpec)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
4
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
5
|
-
declare_meme(:name, [], nil, ::Myco.cscope.dup) { |*| ("BytecodeInstructions")}
|
6
|
-
declare_meme(:instructions, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:BytecodeInstructions)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
7
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}.instance)}
|
8
|
-
__category__(:tests).component_eval {(declare_meme(:exists, [[:it, []]], nil, ::Myco.cscope.dup) { |*| (self.assert(self.instructions))})}
|
9
|
-
)}}.instance)}}.instance
|
@@ -1,229 +0,0 @@
|
|
1
|
-
|
2
|
-
BasicSpec {
|
3
|
-
name: "Constructions"
|
4
|
-
|
5
|
-
[tests]
|
6
|
-
|
7
|
-
specify "AnyCharacter creates a single any instruction": {
|
8
|
-
construct = Constructions::AnyCharacter.new
|
9
|
-
assert_equal(construct.sequence, [
|
10
|
-
[:any, 1]
|
11
|
-
])
|
12
|
-
}
|
13
|
-
|
14
|
-
specify "Character creates a single char instruction": {
|
15
|
-
construct = Constructions::Character.new(code:120)
|
16
|
-
assert_equal(construct.sequence, [
|
17
|
-
[:char, 120]
|
18
|
-
])
|
19
|
-
}
|
20
|
-
|
21
|
-
specify "CharacterString creates a string of char instructions": {
|
22
|
-
construct = Constructions::CharacterString.new(codes:[120,121,122])
|
23
|
-
assert_equal(construct.sequence, [
|
24
|
-
[:char, 120]
|
25
|
-
[:char, 121]
|
26
|
-
[:char, 122]
|
27
|
-
])
|
28
|
-
}
|
29
|
-
|
30
|
-
specify "CharacterSet creates a single charset instruction": {
|
31
|
-
construct = Constructions::CharacterSet.new(codes:[120,121,122])
|
32
|
-
expected_table = [120,121,122].map |code| { [code,true] }.to_h
|
33
|
-
assert_equal(construct.sequence, [
|
34
|
-
[:charset, expected_table]
|
35
|
-
])
|
36
|
-
}
|
37
|
-
|
38
|
-
specify "CharacterRange creates a single charrange instruction": {
|
39
|
-
construct = Constructions::CharacterRange.new(start:120, stop:122)
|
40
|
-
assert_equal(construct.sequence, [
|
41
|
-
[:charrange, 120, 122]
|
42
|
-
])
|
43
|
-
}
|
44
|
-
|
45
|
-
specify "NegativePredicate assembles choice, fail_twice instructions": {
|
46
|
-
a = Constructions::CharacterString.new(codes:[120,121,122])
|
47
|
-
construct = Constructions::NegativePredicate.new(inner:a)
|
48
|
-
assert_equal(construct.sequence, [
|
49
|
-
[:choice, 5] # ip+5 == L1
|
50
|
-
[:char, 120]
|
51
|
-
[:char, 121]
|
52
|
-
[:char, 122]
|
53
|
-
[:fail_twice]
|
54
|
-
]) # (L1)
|
55
|
-
}
|
56
|
-
|
57
|
-
specify "PositivePredicate assembles choice, commit, fail instructions": {
|
58
|
-
a = Constructions::CharacterString.new(codes:[120,121,122])
|
59
|
-
construct = Constructions::PositivePredicate.new(inner:a)
|
60
|
-
assert_equal(construct.sequence, [
|
61
|
-
[:choice, 7] # ip+7 == L1
|
62
|
-
[:choice, 4] # ip+4 == L2
|
63
|
-
[:char, 120]
|
64
|
-
[:char, 121]
|
65
|
-
[:char, 122]
|
66
|
-
[:commit, 1] # ip+1 == L3 (L2)
|
67
|
-
[:fail] # (L3)
|
68
|
-
]) # (L1)
|
69
|
-
}
|
70
|
-
|
71
|
-
specify "OneOrMore assembles UNOPTIMIZED instructions": {
|
72
|
-
a = Constructions::CharacterString.new(codes:[120,121,122])
|
73
|
-
construct = Constructions::OneOrMore.new(inner:a)
|
74
|
-
assert_equal(construct.sequence, [
|
75
|
-
[:char, 120] # TODO: optimize and eliminate the double specification here
|
76
|
-
[:char, 121]
|
77
|
-
[:char, 122]
|
78
|
-
[:choice, 5] # ip+5 == L2
|
79
|
-
[:char, 120] # (L1)
|
80
|
-
[:char, 121]
|
81
|
-
[:char, 122]
|
82
|
-
[:partial_commit, -3] # ip-3 == L1
|
83
|
-
]) # (L2)
|
84
|
-
}
|
85
|
-
|
86
|
-
specify "ZeroOrOne assembles choice and commit instructions": {
|
87
|
-
a = Constructions::CharacterString.new(codes:[120,121,122])
|
88
|
-
construct = Constructions::ZeroOrOne.new(inner:a)
|
89
|
-
assert_equal(construct.sequence, [
|
90
|
-
[:choice, 5] # ip+5 == L1
|
91
|
-
[:char, 120]
|
92
|
-
[:char, 121]
|
93
|
-
[:char, 122]
|
94
|
-
[:commit, 1] # ip+1 == L1
|
95
|
-
]) # (L1)
|
96
|
-
}
|
97
|
-
|
98
|
-
specify "ZeroOrMore assembles choice and partial_commit instructions": {
|
99
|
-
a = Constructions::CharacterString.new(codes:[120,121,122])
|
100
|
-
construct = Constructions::ZeroOrMore.new(inner:a)
|
101
|
-
assert_equal(construct.sequence, [
|
102
|
-
[:choice, 5] # ip+5 == L2
|
103
|
-
[:char, 120] # (L1)
|
104
|
-
[:char, 121]
|
105
|
-
[:char, 122]
|
106
|
-
[:partial_commit, -3] # ip-3 == L1
|
107
|
-
]) # (L2)
|
108
|
-
}
|
109
|
-
|
110
|
-
specify "ZeroOrMore<CharacterSet> creates a single span instruction": {
|
111
|
-
a = Constructions::CharacterSet.new(codes:[120,121,122])
|
112
|
-
construct = Constructions::ZeroOrMore.new(inner:a)
|
113
|
-
expected_table = [120,121,122].map |code| { [code,true] }.to_h
|
114
|
-
assert_equal(construct.sequence, [
|
115
|
-
[:span, expected_table]
|
116
|
-
])
|
117
|
-
}
|
118
|
-
|
119
|
-
specify "OrderedChoice assembles choice and commit instructions": {
|
120
|
-
a = Constructions::CharacterString.new(codes:[110,111,112])
|
121
|
-
b = Constructions::CharacterString.new(codes:[120,121,122])
|
122
|
-
construct = Constructions::OrderedChoice.new(first:a, second:b)
|
123
|
-
assert_equal(construct.sequence, [
|
124
|
-
[:choice, 5] # ip+5 == L1
|
125
|
-
[:char, 110]
|
126
|
-
[:char, 111]
|
127
|
-
[:char, 112]
|
128
|
-
[:commit, 4] # ip+4 == L2
|
129
|
-
[:char, 120] # (L1)
|
130
|
-
[:char, 121]
|
131
|
-
[:char, 122]
|
132
|
-
]) # (L2)
|
133
|
-
|
134
|
-
a = Constructions::CharacterString.new(codes:[110,111,112])
|
135
|
-
b = Constructions::CharacterString.new(codes:[120,121,122])
|
136
|
-
c = Constructions::CharacterString.new(codes:[130,131,132])
|
137
|
-
construct = Constructions::OrderedChoice.new(first:b, second:c)
|
138
|
-
construct = Constructions::OrderedChoice.new(first:a, second:construct)
|
139
|
-
assert_equal(construct.sequence, [
|
140
|
-
[:choice, 5] # ip+5 == L1
|
141
|
-
[:char, 110]
|
142
|
-
[:char, 111]
|
143
|
-
[:char, 112]
|
144
|
-
[:commit, 9] # ip+9 == L2
|
145
|
-
[:choice, 5] # ip+5 == L3; (L1)
|
146
|
-
[:char, 120]
|
147
|
-
[:char, 121]
|
148
|
-
[:char, 122]
|
149
|
-
[:commit, 4] # ip+4 == L2
|
150
|
-
[:char, 130] # (L3)
|
151
|
-
[:char, 131]
|
152
|
-
[:char, 132]
|
153
|
-
]) # (L2)
|
154
|
-
}
|
155
|
-
|
156
|
-
specify "Concatenation simply concatenates the operands": {
|
157
|
-
a = Constructions::CharacterString.new(codes:[110,111,112])
|
158
|
-
b = Constructions::CharacterString.new(codes:[120,121,122])
|
159
|
-
construct = Constructions::Concatenation.new(first:a, second:b)
|
160
|
-
assert_equal(construct.sequence, [
|
161
|
-
[:char, 110]
|
162
|
-
[:char, 111]
|
163
|
-
[:char, 112]
|
164
|
-
[:char, 120]
|
165
|
-
[:char, 121]
|
166
|
-
[:char, 122]
|
167
|
-
])
|
168
|
-
}
|
169
|
-
|
170
|
-
specify "NamedCapture assembles capture instructions": {
|
171
|
-
a = Constructions::CharacterString.new(codes:[120,121,122])
|
172
|
-
construct = Constructions::NamedCapture.new(inner:a)
|
173
|
-
assert_equal(construct.sequence, [
|
174
|
-
[:capture, [:c_start]]
|
175
|
-
[:char, 120]
|
176
|
-
[:char, 121]
|
177
|
-
[:char, 122]
|
178
|
-
[:capture, [:c_end, construct.captargs]]
|
179
|
-
])
|
180
|
-
}
|
181
|
-
|
182
|
-
specify "NamedCapture of ZeroOrMore has a special multiplicit strategy": {
|
183
|
-
a = Constructions::CharacterString.new(codes:[120,121,122])
|
184
|
-
b = Constructions::ZeroOrMore.new(inner:a)
|
185
|
-
construct = Constructions::NamedCapture.new(inner:b)
|
186
|
-
assert_equal(construct.sequence, [
|
187
|
-
[:capture, [:m_start]]
|
188
|
-
[:choice, 6]
|
189
|
-
[:char, 120]
|
190
|
-
[:char, 121]
|
191
|
-
[:char, 122]
|
192
|
-
[:capture, [:m_split, null]]
|
193
|
-
[:partial_commit, -4]
|
194
|
-
[:capture, [:m_end, null]]
|
195
|
-
])
|
196
|
-
}
|
197
|
-
|
198
|
-
specify "NamedCapture of OneOrMore has a special multiplicit strategy": {
|
199
|
-
a = Constructions::CharacterString.new(codes:[120,121,122])
|
200
|
-
b = Constructions::OneOrMore.new(inner:a)
|
201
|
-
construct = Constructions::NamedCapture.new(inner:b)
|
202
|
-
assert_equal(construct.sequence, [
|
203
|
-
[:capture, [:m_start]]
|
204
|
-
[:char, 120]
|
205
|
-
[:char, 121]
|
206
|
-
[:char, 122]
|
207
|
-
[:capture, [:m_split, null]]
|
208
|
-
[:choice, 6]
|
209
|
-
[:char, 120]
|
210
|
-
[:char, 121]
|
211
|
-
[:char, 122]
|
212
|
-
[:capture, [:m_split, null]]
|
213
|
-
[:partial_commit, -4]
|
214
|
-
[:capture, [:m_end, null]]
|
215
|
-
])
|
216
|
-
}
|
217
|
-
|
218
|
-
specify "Reduction assembles capture instructions": {
|
219
|
-
a = Constructions::CharacterString.new(codes:[120,121,122])
|
220
|
-
construct = Constructions::Reduction.new(inner:a)
|
221
|
-
assert_equal(construct.sequence, [
|
222
|
-
[:capture, [:r_start]]
|
223
|
-
[:char, 120]
|
224
|
-
[:char, 121]
|
225
|
-
[:char, 122]
|
226
|
-
[:capture, [:r_end, construct.captargs]]
|
227
|
-
])
|
228
|
-
}
|
229
|
-
}
|