jievro-ast-visitor 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/jievro-ast-visitor.gemspec +1 -1
- data/lib/jievro/ast_visitor/ast_visitor.rb +13 -3
- data/lib/jievro/ast_visitor/version.rb +1 -1
- data/spec/ast_visitor_spec.rb +29 -58
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 073fda3c6d00da4b30b19ddbabb283704db398ef
|
4
|
+
data.tar.gz: 8afd13c7c44ff3b4d47f7a6bba60a3e46c60b53f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a988e4e31065dd0e79037aeabdca76bd5ef785d40a4f2cd08bcddba8265c937590f6510715534e6dcfe6ac5670f9ce25ed8dbf7edd268df61b1b5009623e828
|
7
|
+
data.tar.gz: e98406d645f4b62ee89c5093c91982da77f708f34881281220916b71f16084f7dcd2773135a73d4498cd2794b3db0ee66b718fc73748fcc5ca915c144caa3ee5
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jievro-ast-visitor (0.1.
|
5
|
-
jievro-ast (= 0.
|
4
|
+
jievro-ast-visitor (0.1.4)
|
5
|
+
jievro-ast (= 0.8.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.2.5)
|
11
|
-
jievro-ast (0.
|
11
|
+
jievro-ast (0.8.1)
|
12
12
|
rake (10.4.2)
|
13
13
|
rspec (3.2.0)
|
14
14
|
rspec-core (~> 3.2.0)
|
data/jievro-ast-visitor.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.required_ruby_version = '~> 2.0'
|
21
21
|
|
22
|
-
spec.add_runtime_dependency 'jievro-ast', '0.
|
22
|
+
spec.add_runtime_dependency 'jievro-ast', '0.8.1'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -4,14 +4,24 @@ module Jievro
|
|
4
4
|
def visit(node, preorder = nil, postorder = nil)
|
5
5
|
preorder.call(node) unless preorder.nil?
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
node.each do |n|
|
8
|
+
if n.is_a?(Array)
|
9
|
+
n.each do |m|
|
10
|
+
visit(m, preorder, postorder) if to_be_visited?(m)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
visit(n, preorder, postorder) if to_be_visited?(n)
|
10
14
|
end
|
11
15
|
end
|
12
16
|
|
13
17
|
postorder.call(node) unless postorder.nil?
|
14
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def to_be_visited?(node)
|
23
|
+
node.is_a?(Jievro::Ast::Node)
|
24
|
+
end
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
data/spec/ast_visitor_spec.rb
CHANGED
@@ -7,40 +7,31 @@ describe Jievro::AstVisitor::Visitor do
|
|
7
7
|
@visitor = described_class.new
|
8
8
|
|
9
9
|
hash = {
|
10
|
-
__type: '
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
k6: [
|
22
|
-
{
|
23
|
-
__type: 'type_k6[0]',
|
24
|
-
k7: 'v7',
|
25
|
-
k8: 'v8'
|
26
|
-
},
|
27
|
-
{
|
28
|
-
__type: 'type_k6[1]',
|
29
|
-
k9: 'v9'
|
30
|
-
},
|
31
|
-
{
|
32
|
-
__type: 'type_k6[2]',
|
33
|
-
k10: {
|
34
|
-
__type: 'type_k10',
|
35
|
-
k11: 'v11'
|
10
|
+
__type: 'program',
|
11
|
+
body: [
|
12
|
+
{
|
13
|
+
__type: 'closure-expression',
|
14
|
+
signature: {
|
15
|
+
__type: 'closure-expression-signature',
|
16
|
+
capture: {
|
17
|
+
__type: 'closure-expression-capture-specifier',
|
18
|
+
specifier: 'unowned-unsafe',
|
19
|
+
expression: {
|
20
|
+
__type: 'self-expression'
|
36
21
|
}
|
37
22
|
}
|
23
|
+
},
|
24
|
+
body: [
|
25
|
+
{
|
26
|
+
__type: 'literal-boolean',
|
27
|
+
value: true
|
28
|
+
}
|
38
29
|
]
|
39
30
|
}
|
40
|
-
|
31
|
+
]
|
41
32
|
}
|
42
33
|
|
43
|
-
@ast = Jievro::Ast::Node.new(hash)
|
34
|
+
@ast = Jievro::Ast::Node.new(hash, nil, 1)
|
44
35
|
|
45
36
|
@hooked = []
|
46
37
|
|
@@ -51,25 +42,14 @@ describe Jievro::AstVisitor::Visitor do
|
|
51
42
|
|
52
43
|
it 'should visit in preorder' do
|
53
44
|
@visitor.visit(@ast, @hook)
|
54
|
-
|
55
45
|
expected = [
|
56
46
|
@ast,
|
57
|
-
@ast[:
|
58
|
-
@ast[:
|
59
|
-
@ast[:
|
60
|
-
@ast[:
|
61
|
-
@ast[:
|
62
|
-
@ast[:k2][:k5][:k6],
|
63
|
-
@ast[:k2][:k5][:k6][0],
|
64
|
-
@ast[:k2][:k5][:k6][0][:k7],
|
65
|
-
@ast[:k2][:k5][:k6][0][:k8],
|
66
|
-
@ast[:k2][:k5][:k6][1],
|
67
|
-
@ast[:k2][:k5][:k6][1][:k9],
|
68
|
-
@ast[:k2][:k5][:k6][2],
|
69
|
-
@ast[:k2][:k5][:k6][2][:k10],
|
70
|
-
@ast[:k2][:k5][:k6][2][:k10][:k11]
|
47
|
+
@ast[:body][0],
|
48
|
+
@ast[:body][0][:signature],
|
49
|
+
@ast[:body][0][:signature][:capture],
|
50
|
+
@ast[:body][0][:signature][:capture][:expression],
|
51
|
+
@ast[:body][0][:body][0]
|
71
52
|
]
|
72
|
-
|
73
53
|
expect(@hooked).to match(expected)
|
74
54
|
end
|
75
55
|
|
@@ -77,20 +57,11 @@ describe Jievro::AstVisitor::Visitor do
|
|
77
57
|
@visitor.visit(@ast, nil, @hook)
|
78
58
|
|
79
59
|
expected = [
|
80
|
-
@ast[:
|
81
|
-
@ast[:
|
82
|
-
@ast[:
|
83
|
-
@ast[:
|
84
|
-
@ast[:
|
85
|
-
@ast[:k2][:k5][:k6][0],
|
86
|
-
@ast[:k2][:k5][:k6][1][:k9],
|
87
|
-
@ast[:k2][:k5][:k6][1],
|
88
|
-
@ast[:k2][:k5][:k6][2][:k10][:k11],
|
89
|
-
@ast[:k2][:k5][:k6][2][:k10],
|
90
|
-
@ast[:k2][:k5][:k6][2],
|
91
|
-
@ast[:k2][:k5][:k6],
|
92
|
-
@ast[:k2][:k5],
|
93
|
-
@ast[:k2],
|
60
|
+
@ast[:body][0][:signature][:capture][:expression],
|
61
|
+
@ast[:body][0][:signature][:capture],
|
62
|
+
@ast[:body][0][:signature],
|
63
|
+
@ast[:body][0][:body][0],
|
64
|
+
@ast[:body][0],
|
94
65
|
@ast
|
95
66
|
]
|
96
67
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jievro-ast-visitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Azzalini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jievro-ast
|
@@ -16,54 +16,54 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.8.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.8.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.6'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.2'
|
69
69
|
description:
|
@@ -72,8 +72,8 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
-
- .gitignore
|
76
|
-
- .travis.yml
|
75
|
+
- ".gitignore"
|
76
|
+
- ".travis.yml"
|
77
77
|
- Gemfile
|
78
78
|
- Gemfile.lock
|
79
79
|
- LICENSE.txt
|
@@ -94,17 +94,17 @@ require_paths:
|
|
94
94
|
- lib
|
95
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- - ~>
|
97
|
+
- - "~>"
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '2.0'
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.4.6
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: jievro AST visitor
|