node_visitor 1.0.0 → 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: a596ef648c5a209a47fa0355a8956a14df436f9b82d178560323809387a235aa
4
- data.tar.gz: 98d3fe4e938c5d841c9d1e34c037cdfa1f1c209cf521c005f732d07cefc8da65
3
+ metadata.gz: 38253864e4eb4cf2caaf72d169bc84397af05003c1cee6abdb9ddaf59b0fc298
4
+ data.tar.gz: 30f67d7d7aba9464089a13cf5a3c6621bb8228ea310bff8cd11ef62282d279f9
5
5
  SHA512:
6
- metadata.gz: beb38d152e58c83c48c7a1d714b4ba635e6ce226e804d04e00b38568afc6b10f6f4a82e9074ac1e998d30ebd0ff2cdcb271c09748cdb2e3993a132d3e9f4ab06
7
- data.tar.gz: 5ad89b6ee986b7ac6a7d4ff7834905633a5302018a2e23de16769dab74bd3798ac4ace624f6c5641db3f2ef26de833914b710ca7bc744f7ddb65255c01460732
6
+ metadata.gz: 93d4fe4465947205a048250ca5dda8dd725719efbbf4451702a5aaf3e951d47e5d30277a66a833d569de8ee7b058e980c97a8bc65f35dda344c318bc2637a4f7
7
+ data.tar.gz: acc26f33fc58b66a5e07573899a80f9bbf10a15f43ed41fbf1d107556f567efc181899ad572dc0b7c64db68784e3e014b61f3637cbb5e80ee11cb27b936bb176
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
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
+
8
+ ## 1.0.1 (2024-04-27)
9
+
10
+ * Do not visit if `@callbacks` is empty
11
+
3
12
  ## 1.0.0 (2024-04-27)
4
13
 
5
14
  * Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- node_visitor (1.0.0)
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.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/node_visitor.rb CHANGED
@@ -19,10 +19,14 @@ class NodeVisitor
19
19
  end
20
20
 
21
21
  def visit(node, block_context = self)
22
+ return if @callbacks.empty?
23
+
22
24
  callbacks = @callbacks[:all]
23
- callbacks.each { |callback| block_context.instance_exec(node, &callback[:block]) if callback[:at] == 'start' } if callbacks
24
- visit_node(node)
25
- 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
26
30
  end
27
31
 
28
32
  private
@@ -40,16 +44,16 @@ class NodeVisitor
40
44
  end
41
45
  end
42
46
 
43
- def visit_node(node)
47
+ def visit_node(node, block_context)
44
48
  if node.is_a?(Array)
45
- node.each { |child_node| visit_node(child_node) }
49
+ node.each { |child_node| visit_node(child_node, block_context) }
46
50
  return
47
51
  end
48
52
  return unless @adapter.is_node?(node)
49
53
 
50
54
  callbacks = @callbacks[@adapter.get_node_type(node)]
51
- callbacks.each { |callback| instance_exec(node, &callback[:block]) if callback[:at] == 'start' } if callbacks
52
- @adapter.get_children(node).each { |child_node| visit_node(child_node) }
53
- 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
54
58
  end
55
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.0
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