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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 417ba2423590d8422e67cec2e3a51dba8516cc68
4
- data.tar.gz: 7e676a51505dd9777067c724025a83b08a09aacb
3
+ metadata.gz: 073fda3c6d00da4b30b19ddbabb283704db398ef
4
+ data.tar.gz: 8afd13c7c44ff3b4d47f7a6bba60a3e46c60b53f
5
5
  SHA512:
6
- metadata.gz: 6195727fa0ed101ea0d8f23ffa42dc386c44cb21ca5bc1ba2951f802e0d7515cf8c7fe018084ada224c15f6780031a16d2a77f38717dc96ffa2150bf2c0d18c6
7
- data.tar.gz: aaa815e585a4aa74285677e0dfd5fa09f6d007453c19487267e27cf25c76b6fd1918a06353a4747d2d07da86560d4ec321f09c03bef151a35c118da380cda5eb
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.1)
5
- jievro-ast (= 0.3.2)
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.3.2)
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)
@@ -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.3.2'
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
- unless node.type == Jievro::Ast::Node::TYPE_LITERAL
8
- node.each do |n|
9
- visit(n, preorder, postorder)
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
@@ -1,5 +1,5 @@
1
1
  module Jievro
2
2
  module AstVisitor
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
@@ -7,40 +7,31 @@ describe Jievro::AstVisitor::Visitor do
7
7
  @visitor = described_class.new
8
8
 
9
9
  hash = {
10
- __type: 'type_root',
11
- k1: 'v1',
12
- k2: {
13
- __type: 'type_k2',
14
- k3: 'v3',
15
- k4: {
16
- __type: 'type_k4',
17
- # left empty
18
- },
19
- k5: {
20
- __type: 'type_k5',
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[:k1],
58
- @ast[:k2],
59
- @ast[:k2][:k3],
60
- @ast[:k2][:k4],
61
- @ast[:k2][:k5],
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[:k1],
81
- @ast[:k2][:k3],
82
- @ast[:k2][:k4],
83
- @ast[:k2][:k5][:k6][0][:k7],
84
- @ast[:k2][:k5][:k6][0][:k8],
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.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-05-08 00:00:00.000000000 Z
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.3.2
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.3.2
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.0.14
107
+ rubygems_version: 2.4.6
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: jievro AST visitor