bel 0.3.2-x86-mingw32 → 0.3.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/README.md +1 -1
- data/bel.gemspec +4 -4
- data/ext/mri/extconf.rb +20 -6
- data/lib/bel.rb +4 -3
- data/lib/bel/libbel.rb +141 -177
- data/lib/bel/libbel/bel_ast_structs.rb +150 -148
- data/lib/bel/libbel/bel_token.rb +29 -27
- data/lib/bel/libbel/bel_token_list.rb +28 -26
- data/lib/bel/{2.0 → libbel/ext/2.0}/libbel.so +0 -0
- data/lib/bel/libbel/ext/2.1/libbel.so +0 -0
- data/lib/bel/{2.2 → libbel/ext/2.2}/libbel.so +0 -0
- data/lib/bel/libbel/ext/java/darwin/x86_64/libbel.bundle +0 -0
- data/lib/bel/libbel/ext/java/linux/x86_64/libbel.so +0 -0
- data/lib/bel/libbel/ext/java/mswin/i686/2.0/libbel.so +0 -0
- data/lib/bel/{2.1 → libbel/ext/java/mswin/i686/2.1}/libbel.so +0 -0
- data/lib/bel/libbel/ext/java/mswin/i686/2.2/libbel.so +0 -0
- data/lib/bel/libbel/ext/java/mswin/x86_64/2.0/libbel.so +0 -0
- data/lib/bel/libbel/ext/java/mswin/x86_64/2.1/libbel.so +0 -0
- data/lib/bel/libbel/ext/java/mswin/x86_64/2.2/libbel.so +0 -0
- data/lib/bel/libbel/ext/mingw/i686/2.0/libbel.so +0 -0
- data/lib/bel/libbel/ext/mingw/i686/2.1/libbel.so +0 -0
- data/lib/bel/libbel/ext/mingw/i686/2.2/libbel.so +0 -0
- data/lib/bel/libbel/ext/mingw/x86_64/2.0/libbel.so +0 -0
- data/lib/bel/libbel/ext/mingw/x86_64/2.1/libbel.so +0 -0
- data/lib/bel/libbel/ext/mingw/x86_64/2.2/libbel.so +0 -0
- data/lib/bel/libbel/library_load_error.rb +30 -0
- data/lib/bel/libbel/library_resolver.rb +103 -0
- data/lib/bel/libbel/node_test.rb +29 -27
- data/lib/bel/libbel/node_transformation.rb +24 -22
- data/lib/bel/libbel/node_traversal.rb +79 -77
- data/lib/bel/libbel/platform_support_error.rb +23 -0
- data/lib/bel/version.rb +1 -1
- metadata +23 -33
@@ -2,201 +2,203 @@ require_relative 'node_traversal'
|
|
2
2
|
require_relative 'node_transformation'
|
3
3
|
require_relative 'node_test'
|
4
4
|
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
module BEL
|
6
|
+
module LibBEL
|
7
|
+
class AstNodeTypeUnion < FFI::Union
|
8
|
+
layout(
|
9
|
+
:ttype, :bel_ast_token_type,
|
10
|
+
:vtype, :bel_ast_value_type
|
11
|
+
)
|
12
|
+
|
13
|
+
def token_type
|
14
|
+
self[:ttype]
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
def value_type
|
18
|
+
self[:vtype]
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
class BelAstNodeTypeInfo < FFI::Struct
|
23
|
+
layout(
|
24
|
+
:type, :bel_ast_node_type,
|
25
|
+
:union, AstNodeTypeUnion
|
26
|
+
)
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def type
|
29
|
+
self[:type]
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
def union
|
33
|
+
self[:union]
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
class BelAstNode < FFI::Union
|
38
|
+
include NodeTraversal
|
39
|
+
include NodeTransformation
|
40
|
+
include NodeTest
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
layout(
|
43
|
+
:type_info, BelAstNodeTypeInfo.ptr,
|
44
|
+
:token, :pointer,
|
45
|
+
:value, :pointer
|
46
|
+
)
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def type_info
|
49
|
+
self[:type_info]
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def type_info=(type_info)
|
53
|
+
self[:type_info] = type_info
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
def token
|
57
|
+
self[:token]
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def token=(token)
|
61
|
+
self[:token] = token
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def value
|
65
|
+
self[:value]
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
def value=(value)
|
69
|
+
self[:value] = value
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
72
|
+
def to_typed_node
|
73
|
+
LibBEL.typed_node(self)
|
74
|
+
end
|
73
75
|
end
|
74
|
-
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
77
|
+
class BelAstNodeToken < FFI::Struct
|
78
|
+
layout(
|
79
|
+
:type, :bel_ast_node_type,
|
80
|
+
:ttype, :bel_ast_token_type,
|
81
|
+
:left, BelAstNode.ptr,
|
82
|
+
:right, BelAstNode.ptr
|
83
|
+
)
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
def type
|
86
|
+
self[:type]
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
def token_type
|
90
|
+
self[:ttype]
|
91
|
+
end
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
93
|
+
def left
|
94
|
+
self[:left]
|
95
|
+
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
def left=(left)
|
98
|
+
self[:left] = left
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
def right
|
102
|
+
self[:right]
|
103
|
+
end
|
103
104
|
|
104
|
-
|
105
|
-
|
105
|
+
def right=(right)
|
106
|
+
self[:right] = right
|
107
|
+
end
|
106
108
|
end
|
107
|
-
end
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
class BelAstNodeValue < FFI::Struct
|
111
|
+
layout(
|
112
|
+
:type, :bel_ast_node_type,
|
113
|
+
:vtype, :bel_ast_value_type,
|
114
|
+
:value, :string
|
115
|
+
)
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
117
|
+
def type
|
118
|
+
self[:type]
|
119
|
+
end
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
def value_type
|
122
|
+
self[:vtype]
|
123
|
+
end
|
123
124
|
|
124
|
-
|
125
|
-
|
125
|
+
def value
|
126
|
+
self[:value]
|
127
|
+
end
|
126
128
|
end
|
127
|
-
end
|
128
129
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
130
|
+
class BelAst < FFI::ManagedStruct
|
131
|
+
include NodeTraversal
|
132
|
+
include NodeTransformation
|
133
|
+
include NodeTest
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
layout(
|
136
|
+
:root, BelAstNode.ptr
|
137
|
+
)
|
137
138
|
|
138
|
-
|
139
|
-
|
140
|
-
|
139
|
+
def root
|
140
|
+
self[:root]
|
141
|
+
end
|
141
142
|
|
142
|
-
|
143
|
-
|
144
|
-
|
143
|
+
def root=(root)
|
144
|
+
self[:root] = root
|
145
|
+
end
|
145
146
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
147
|
+
# overrides {NodeTraversal#each_depth_first}
|
148
|
+
def each_depth_first(&block)
|
149
|
+
if block_given?
|
150
|
+
root.each_depth_first(&block)
|
151
|
+
else
|
152
|
+
root.enum_for(:each_depth_first)
|
153
|
+
end
|
152
154
|
end
|
153
|
-
end
|
154
155
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
156
|
+
# overrides {NodeTraversal#each_breadth_first}
|
157
|
+
def each_breadth_first(queue = [], &block)
|
158
|
+
if block_given?
|
159
|
+
root.each_breadth_first(&block)
|
160
|
+
else
|
161
|
+
root.enum_for(:each_breadth_first)
|
162
|
+
end
|
161
163
|
end
|
162
|
-
end
|
163
164
|
|
164
|
-
|
165
|
-
|
166
|
-
|
165
|
+
def transform(transforms, options = {})
|
166
|
+
transform_tree(transforms, :depth_first, options)
|
167
|
+
end
|
167
168
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
169
|
+
def transform_tree(transforms, traversal = :depth_first, options = {})
|
170
|
+
copy_ast = LibBEL::copy_ast(self)
|
171
|
+
options = {
|
172
|
+
:mutate => true
|
173
|
+
}.merge(options)
|
173
174
|
|
174
|
-
|
175
|
-
|
176
|
-
|
175
|
+
copy_ast.root.transform_tree(transforms, traversal, options)
|
176
|
+
copy_ast
|
177
|
+
end
|
177
178
|
|
178
|
-
|
179
|
-
|
180
|
-
|
179
|
+
def any?(predicates)
|
180
|
+
self.root.any_in_tree?(predicates)
|
181
|
+
end
|
181
182
|
|
182
|
-
|
183
|
-
|
184
|
-
|
183
|
+
def all?(predicates)
|
184
|
+
self.root.all_in_tree?(predicates)
|
185
|
+
end
|
185
186
|
|
186
|
-
|
187
|
-
|
188
|
-
|
187
|
+
def self.release(ptr)
|
188
|
+
if !ptr.null?
|
189
|
+
LibBEL::bel_free_ast(ptr)
|
190
|
+
end
|
189
191
|
end
|
190
192
|
end
|
191
|
-
end
|
192
193
|
|
193
|
-
|
194
|
+
private
|
194
195
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
196
|
+
def self.typed_node(bel_ast_node)
|
197
|
+
if bel_ast_node.type_info.type == :BEL_TOKEN
|
198
|
+
BelAstNodeToken.new(bel_ast_node.token)
|
199
|
+
else
|
200
|
+
BelAstNodeValue.new(bel_ast_node.value)
|
201
|
+
end
|
200
202
|
end
|
201
203
|
end
|
202
204
|
end
|
data/lib/bel/libbel/bel_token.rb
CHANGED
@@ -1,38 +1,40 @@
|
|
1
|
-
module
|
1
|
+
module BEL
|
2
|
+
module LibBEL
|
2
3
|
|
3
|
-
|
4
|
+
class BelToken < FFI::Struct
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
layout :type, :bel_token_type,
|
7
|
+
:pos_start, :int,
|
8
|
+
:pos_end, :int,
|
9
|
+
:value, :pointer
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def type
|
12
|
+
self[:type]
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def pos_start
|
16
|
+
self[:pos_start]
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def pos_end
|
20
|
+
self[:pos_end]
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def value
|
24
|
+
self[:value].read_string
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def hash
|
28
|
+
[self.type, self.value, self.pos_start, self.pos_end].hash
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
def ==(other)
|
32
|
+
return false if other == nil
|
33
|
+
self.type == other.type && self.value == other.value &&
|
34
|
+
self.pos_start == other.pos_start && self.pos_end == other.pos_end
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
+
alias_method :eql?, :'=='
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
@@ -1,36 +1,38 @@
|
|
1
|
-
module
|
1
|
+
module BEL
|
2
|
+
module LibBEL
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
class BelTokenList < FFI::ManagedStruct
|
5
|
+
include Enumerable
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
layout :length, :int,
|
8
|
+
:tokens, BelToken.ptr
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
def each
|
11
|
+
if block_given?
|
12
|
+
iterator = LibBEL::bel_new_token_iterator(self.pointer)
|
13
|
+
while LibBEL::bel_token_iterator_end(iterator).zero?
|
14
|
+
current_token = LibBEL::bel_token_iterator_get(iterator)
|
15
|
+
yield LibBEL::BelToken.new(current_token)
|
16
|
+
LibBEL::bel_token_iterator_next(iterator)
|
17
|
+
end
|
18
|
+
LibBEL::free_bel_token_iterator(iterator)
|
19
|
+
else
|
20
|
+
enum_for(:each)
|
16
21
|
end
|
17
|
-
LibBEL::free_bel_token_iterator(iterator)
|
18
|
-
else
|
19
|
-
enum_for(:each)
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def token_at(position)
|
25
|
+
self.each_with_index { |tk, index|
|
26
|
+
if (tk.pos_start..tk.pos_end).include? position
|
27
|
+
return [tk, index]
|
28
|
+
end
|
29
|
+
}
|
30
|
+
nil
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
def self.release(ptr)
|
34
|
+
LibBEL::free_bel_token_list(ptr)
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|