parser_node_ext 0.5.1 → 0.6.1

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: fc6fc830978807e48ef5cc142cf9dfa32829e835020e31d09252f29d96d13e42
4
- data.tar.gz: 3e44eee2fb5e4dafdf6c2070c49d934cee5d0dc5e1c9d56e7146d37628bed239
3
+ metadata.gz: 0c010eedee012b007e7dd9d4ad497a418baff0fd7ff6cbd90e28900f2910ab61
4
+ data.tar.gz: 69a8789262a112d6761a47230cfa7dabac548e7250dbcbc71eecd9aa11faf3d3
5
5
  SHA512:
6
- metadata.gz: 8ae876214f7a2d73764d2a34c04eba1205917120d5133bee4c32ccd1219ba3de1b5e5be69d9deb11d6d53d1aa0e7e8015d4e47b74441c8926ee779d5bcb40db5
7
- data.tar.gz: 7c588aa80f8a762b8402f173adc902aded19e37821bf91ad0fb7ac5ab7ebf392c7b47f4f12ab31aba09a9b307a629ad3a9e5859f5bcf84515db2e674a899d511
6
+ metadata.gz: 4aaab8fec5b8b0c4ac5df1cd4a56acb4e0331bd13988cab00e52bd9e0c08e103a4bfa9a976bff84699dec1310f9a01f891a4222b750d1836c26171ccc5913a0d
7
+ data.tar.gz: 86bd7ed9bd852983e2ec19d3c795edae960f20670c325557549e2abe69e0086f05c6510a33d550e8f480d87ae64d652cc88bcd5debddcfb221f0a7b79cbaa254
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.6.1 (2023-01-21)
4
+
5
+ * Fix typo
6
+
7
+ ## 0.6.0 (2023-01-06)
8
+
9
+ * Support `value` for `float`, `int`, `str` and `sym` nodes
10
+ * Support `if` node
11
+ * Support `case`/`when` node
12
+ * Truly dynamically define methods based on const `TYPE_CHILDREN`
13
+
14
+ ## 0.5.1 (2022-12-26)
15
+
16
+ * hash node pairs should return an array of pair nodes
17
+
18
+ ## 0.5.0 (2022-12-25)
19
+
20
+ * Add primitive types
21
+
3
22
  ## 0.4.1 (2022-10-21)
4
23
 
5
24
  * Update error message
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parser_node_ext (0.5.1)
4
+ parser_node_ext (0.6.1)
5
5
  parser
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  diff-lcs (1.5.0)
12
- parser (3.1.3.0)
12
+ parser (3.2.0.0)
13
13
  ast (~> 2.4.1)
14
14
  rake (13.0.6)
15
15
  rspec (3.11.0)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParserNodeExt
4
- VERSION = "0.5.1"
4
+ VERSION = "0.6.1"
5
5
  end
@@ -14,18 +14,20 @@ module ParserNodeExt
14
14
  begin: %i[body],
15
15
  block: %i[caller arguments body],
16
16
  blockarg: %i[name],
17
+ case: %i[expression when_statements else_statement],
17
18
  const: %i[parent_const name],
18
19
  class: %i[name parent_class body],
19
20
  csend: %i[receiver message arguments],
20
21
  cvasgn: %i[left_value right_value],
21
22
  cvar: %i[name],
22
23
  def: %i[name arguments body],
23
- definded?: %i[arguments],
24
+ defined?: %i[arguments],
24
25
  defs: %i[self name arguments body],
25
26
  false: [],
26
- float: [],
27
+ float: %i[value],
27
28
  hash: %i[pairs],
28
- int: [],
29
+ if: %i[expression if_statement else_statement],
30
+ int: %i[value],
29
31
  ivasgn: %i[left_value right_value],
30
32
  ivar: %i[name],
31
33
  lvar: %i[name],
@@ -38,10 +40,11 @@ module ParserNodeExt
38
40
  pair: %i[key value],
39
41
  restarg: %i[name],
40
42
  send: %i[receiver message arguments],
41
- str: [],
43
+ str: %i[value],
42
44
  super: %i[arguments],
43
- sym: [],
45
+ sym: %i[value],
44
46
  true: [],
47
+ when: %i[expression body],
45
48
  zsuper: []
46
49
  }
47
50
 
@@ -80,22 +83,8 @@ module ParserNodeExt
80
83
  parent.children[index + 1..]
81
84
  end
82
85
 
83
- # Dyamically defined method
84
- # caller, key, left_value, message, name, pairs, parent_class, parent_const, receivr, rgith_value and value.
85
- # based on const TYPE_CHILDREN.
86
- %i[
87
- caller
88
- key
89
- left_value
90
- message
91
- name
92
- pairs
93
- parent_class
94
- parent_const
95
- receiver
96
- right_value
97
- value
98
- ].each do |method_name|
86
+ # Dyamically defined method based on const TYPE_CHILDREN.
87
+ TYPE_CHILDREN.values.flatten.uniq.each do |method_name|
99
88
  define_method(method_name) do
100
89
  index = TYPE_CHILDREN[type]&.index(method_name)
101
90
  return children[index] if index
@@ -153,6 +142,10 @@ module ParserNodeExt
153
142
  case type
154
143
  when :begin
155
144
  children
145
+ when :when
146
+ return [] if children[1].nil?
147
+
148
+ :begin == children[1].type ? children[1].body : children[1..-1]
156
149
  when :def, :block, :class, :module
157
150
  return [] if children[2].nil?
158
151
 
@@ -166,21 +159,24 @@ module ParserNodeExt
166
159
  end
167
160
  end
168
161
 
169
- # Get condition of node.
170
- # It supports :if node.
171
- # @example
172
- # node # s(:if, s(:defined?, s(:const, nil, :Bundler)), nil, nil)
173
- # node.condition # s(:defined?, s(:const, nil, :Bundler))
174
- # @return [Parser::AST::Node] condition of node.
175
- # @raise [MethodNotSupported] if calls on other node.
176
- def condition
177
- if :if == type
178
- children[0]
162
+ def when_statements
163
+ if :case == type
164
+ children[1...-1]
179
165
  else
180
- raise MethodNotSupported, "condition is not supported for #{self}"
166
+ raise MethodNotSupported, "when_statements is not supported for #{self}"
181
167
  end
182
168
  end
183
169
 
170
+ def else_statement
171
+ children[-1]
172
+ end
173
+
174
+ # Get pairs of :hash node.
175
+ # @example
176
+ # node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar")))
177
+ # node.pairs # [s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar"))]
178
+ # @return [Array<Parser::AST::Node>] pairs of node.
179
+ # @raise [MethodNotSupported] if calls on other node.
184
180
  def pairs
185
181
  if :hash == type
186
182
  children
@@ -5,6 +5,9 @@ module ParserNodeExt
5
5
  def arguments: () -> Array[Parser::AST::Node]
6
6
  def body: () -> Array[Parser::AST::Node]
7
7
  def caller: () -> Parser::AST::Node
8
+ def else_statement: () -> Parser::AST::Node
9
+ def expression: () -> Parser::AST::Node
10
+ def if_statement: () -> Parser::AST::Node
8
11
  def key: () -> Parser::AST::Node
9
12
  def left_value: () -> Parser::AST::Node | Symbol
10
13
  def message: () -> Symbol
@@ -15,6 +18,7 @@ module ParserNodeExt
15
18
  def right_value: () -> Parser::AST::Node
16
19
  def self: () -> Parser::AST::Node
17
20
  def value: () -> Parser::AST::Node
21
+ def when_statements: () -> Array[Parser::AST::Node]
18
22
 
19
23
  def to_hash: () -> Hash
20
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser_node_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-26 00:00:00.000000000 Z
11
+ date: 2023-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.3.26
66
+ rubygems_version: 3.4.1
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: extend parser node