node_visitor 1.0.1 → 1.1.0

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
  SHA256:
3
- metadata.gz: 733804b808e37fc559e0cb45451f1f1417479e6cfcc9e48c9372a9fdb392ff4d
4
- data.tar.gz: 0115f0af3b595803bdfa0bcfe04a0d109a3935ac32ab735eef2577a6523daa1b
3
+ metadata.gz: 38253864e4eb4cf2caaf72d169bc84397af05003c1cee6abdb9ddaf59b0fc298
4
+ data.tar.gz: 30f67d7d7aba9464089a13cf5a3c6621bb8228ea310bff8cd11ef62282d279f9
5
5
  SHA512:
6
- metadata.gz: f34adbca18a00f13e2a1c8bfd7be646d042fa68fc681bd214618bf85bf4ba57a30831ccc47665d713d1901597cf9aa41324f91042d726ee7e0c314f0deb96a2b
7
- data.tar.gz: 1bdd078316a131230adf7957186826ce050719be9c416ee5795ba3f1cf4e17d3c2467845332b971ed856642993f57f28ccdbf6bc06acd25d75b40613757823df
6
+ metadata.gz: 93d4fe4465947205a048250ca5dda8dd725719efbbf4451702a5aaf3e951d47e5d30277a66a833d569de8ee7b058e980c97a8bc65f35dda344c318bc2637a4f7
7
+ data.tar.gz: acc26f33fc58b66a5e07573899a80f9bbf10a15f43ed41fbf1d107556f567efc181899ad572dc0b7c64db68784e3e014b61f3637cbb5e80ee11cb27b936bb176
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.0 (2024-06-25)
4
+
5
+ * Call `block` in `block_context`
6
+ * Catch `abort` when visiting node
7
+
3
8
  ## 1.0.1 (2024-04-27)
4
9
 
5
10
  * Do not visit if `@callbacks` is empty
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_visitor (1.0.1)
4
+ node_visitor (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  class NodeVisitor
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/node_visitor.rb CHANGED
@@ -22,9 +22,11 @@ class NodeVisitor
22
22
  return if @callbacks.empty?
23
23
 
24
24
  callbacks = @callbacks[:all]
25
- callbacks.each { |callback| block_context.instance_exec(node, &callback[:block]) if callback[:at] == 'start' } if callbacks
26
- visit_node(node)
27
- callbacks.each { |callback| block_context.instance_exec(node, &callback[:block]) if callback[:at] == 'end' } if callbacks
25
+ catch(:abort) do
26
+ callbacks.each { |callback| block_context.instance_exec(node, &callback[:block]) if callback[:at] == 'start' } if callbacks
27
+ visit_node(node, block_context)
28
+ callbacks.each { |callback| block_context.instance_exec(node, &callback[:block]) if callback[:at] == 'end' } if callbacks
29
+ end
28
30
  end
29
31
 
30
32
  private
@@ -42,16 +44,16 @@ class NodeVisitor
42
44
  end
43
45
  end
44
46
 
45
- def visit_node(node)
47
+ def visit_node(node, block_context)
46
48
  if node.is_a?(Array)
47
- node.each { |child_node| visit_node(child_node) }
49
+ node.each { |child_node| visit_node(child_node, block_context) }
48
50
  return
49
51
  end
50
52
  return unless @adapter.is_node?(node)
51
53
 
52
54
  callbacks = @callbacks[@adapter.get_node_type(node)]
53
- callbacks.each { |callback| instance_exec(node, &callback[:block]) if callback[:at] == 'start' } if callbacks
54
- @adapter.get_children(node).each { |child_node| visit_node(child_node) }
55
- callbacks.each { |callback| instance_exec(node, &callback[:block]) if callback[:at] == 'end' } if callbacks
55
+ callbacks.each { |callback| block_context.instance_exec(node, &callback[:block]) if callback[:at] == 'start' } if callbacks
56
+ @adapter.get_children(node).each { |child_node| visit_node(child_node, block_context) }
57
+ callbacks.each { |callback| block_context.instance_exec(node, &callback[:block]) if callback[:at] == 'end' } if callbacks
56
58
  end
57
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node_visitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-27 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: visit ast nodes
14
14
  email:
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.5.9
54
+ rubygems_version: 3.5.13
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: visit ast nodes