parser_node_ext 1.2.2 → 1.3.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: f6c6c18cd96c8260a6318584861952e15597a1e89e3ad765459cbcd7ee09811e
4
- data.tar.gz: 9b60771fe8b4428ef615e0bc7064d275027f3a292c13b2936266b1e19c0c2178
3
+ metadata.gz: 3f58dd28166500b9ae0882d5a629d272f4ad7713538e2f7aeb2a0218c77a359a
4
+ data.tar.gz: 3947994cf6a5669d2d37971af8dae83836a429c9715aa2c2e29a7efd3c74863a
5
5
  SHA512:
6
- metadata.gz: cd2ebf1060bca500fb0ea333ddd8819040095566ccf385eafed3bfe0da15f9d5659147e83547d2a714a7393debc934c3c791404d0595d7ca3fbaa29d0434b3f4
7
- data.tar.gz: 9238796ab318e28ec2a1df877142985d4461e39d74923ff5055ab3fcc4267ca234c1ce89110ef3e947b1f1bfc136c168486962db36ec952342b1617123423cb0
6
+ metadata.gz: 3e2462943a0c6db7a0e2d95a9ce9e967deb19c5d2a7ce71d44b68c7db5cb74bbf398d2ae487ea0db8145371d4c7ec17910c5889d675d9201b19e81ae7ab041d4
7
+ data.tar.gz: f8b0f07ff32914d11bb1a3cc70e1a6b2a19501bdb08d795334c738780fa4cfa016a18e86e3014f80b86953eba7e06e44dcfca4d67680e7bb0e35e52f9402f9e0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.3.0 (2024-04-07)
4
+
5
+ * Add github actions
6
+ * Remove `siblings` method
7
+ * Abstract `parser_node_ext/parent_node_ext`
8
+
3
9
  ## 1.2.2 (2024-02-10)
4
10
 
5
11
  * Remove `to_hash` extend
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parser_node_ext (1.2.2)
4
+ parser_node_ext (1.3.0)
5
5
  parser
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # ParserNodeExt
2
2
 
3
+ [![Build Status](https://github.com/synvert-hq/parser_node_ext/actions/workflows/main.yml/badge.svg)](https://github.com/synvert-hq/parser_node_ext/actions/workflows/main.yml)
4
+ [![Gem Version](https://img.shields.io/gem/v/parser_node_ext.svg)](https://rubygems.org/gems/parser_node_ext)
5
+
3
6
  It assigns names to the child nodes of the [parser](https://rubygems.org/gems/parser).
4
7
 
5
8
  ```ruby
@@ -16,6 +19,12 @@ It also adds some helpers
16
19
  node.foo_pair # get the pair node of hash foo key
17
20
  node.foo_value # get the value node of the hash foo key
18
21
  node.foo_source # get the source of the value node of the hash foo key
22
+ node.keys # get key nodes of the hash node
23
+ node.values # get value nodes of the hash node
24
+
25
+ # all nodes
26
+ node.to_value # get the value of the node, like `true`, `false`, `nil`, `1`, `"foo"`
27
+ node.to_source # get the source code of the node
19
28
  ```
20
29
 
21
30
  ## Installation
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Parser::AST::Node
4
+ # Initialize a Node.
5
+ #
6
+ # It extends {Parser::AST::Node} and set parent for its child nodes.
7
+ def initialize(type, children = [], properties = {})
8
+ @mutable_attributes = {}
9
+ super
10
+ # children could be nil for s(:array)
11
+ Array(children).each do |child_node|
12
+ if child_node.is_a?(Parser::AST::Node)
13
+ child_node.parent = self
14
+ end
15
+ end
16
+ end
17
+
18
+ # Get the parent node.
19
+ # @return [Parser::AST::Node] parent node.
20
+ def parent
21
+ @mutable_attributes[:parent]
22
+ end
23
+
24
+ # Set the parent node.
25
+ # @param node [Parser::AST::Node] parent node.
26
+ def parent=(node)
27
+ @mutable_attributes[:parent] = node
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParserNodeExt
4
- VERSION = "1.2.2"
4
+ VERSION = "1.3.0"
5
5
  end
@@ -119,39 +119,6 @@ module ParserNodeExt
119
119
 
120
120
  def self.included(base)
121
121
  base.class_eval do
122
- # Initialize a Node.
123
- #
124
- # It extends {Parser::AST::Node} and set parent for its child nodes.
125
- def initialize(type, children = [], properties = {})
126
- @mutable_attributes = {}
127
- super
128
- # children could be nil for s(:array)
129
- Array(children).each do |child_node|
130
- if child_node.is_a?(Parser::AST::Node)
131
- child_node.parent = self
132
- end
133
- end
134
- end
135
-
136
- # Get the parent node.
137
- # @return [Parser::AST::Node] parent node.
138
- def parent
139
- @mutable_attributes[:parent]
140
- end
141
-
142
- # Set the parent node.
143
- # @param node [Parser::AST::Node] parent node.
144
- def parent=(node)
145
- @mutable_attributes[:parent] = node
146
- end
147
-
148
- # Get the sibling nodes.
149
- # @return [Array<Parser::AST::Node>] sibling nodes.
150
- def siblings
151
- index = parent.children.index(self)
152
- parent.children[index + 1..]
153
- end
154
-
155
122
  # Dyamically defined method based on const TYPE_CHILDREN.
156
123
  TYPE_CHILDREN.values.flatten.uniq.each do |method_name|
157
124
  define_method(method_name) do
@@ -497,32 +464,6 @@ module ParserNodeExt
497
464
  end
498
465
 
499
466
  # Extend Parser::AST::Node.
500
- # {https://github.com/whitequark/parser/blob/master/lib/parser/ast/node.rb}
501
- #
502
- # Rules
503
- #
504
- # Synvert compares ast nodes with key / value pairs, each ast node has
505
- # multiple attributes, e.g. +receiver+, +message+ and +arguments+, it
506
- # matches only when all of key / value pairs match.
507
- #
508
- # +type: 'send', message: :include, arguments: ['FactoryGirl::Syntax::Methods']+
509
- #
510
- # Synvert does comparison based on the value type
511
- #
512
- # 1. if value is a symbol, then compares ast node value as symbol, e.g. +message: :include+
513
- # 2. if value is a string, then compares ast node original source code, e.g. +name: 'Synvert::Application'+
514
- # 3. if value is a regexp, then compares ast node original source code, e.g. +message: /find_all_by_/+
515
- # 4. if value is an array, then compares each ast node, e.g. +arguments: ['FactoryGirl::Syntax::Methods']+
516
- # 5. if value is nil, then check if ast node is nil, e.g. +arguments: [nil]+
517
- # 6. if value is true or false, then check if ast node is :true or :false, e.g. +arguments: [false]+
518
- # 7. if value is ast, then compare ast node directly, e.g. +to_ast: Parser::CurrentRuby.parse("self.class.serialized_attributes")+
519
- #
520
- # It can also compare nested key / value pairs, like
521
- #
522
- # +type: 'send', receiver: { type: 'send', receiver: { type: 'send', message: 'config' }, message: 'active_record' }, message: 'identity_map='+
523
- #
524
- # Source Code to Ast Node
525
- # {https://playground.synvert.net/ruby}
526
467
  class Parser::AST::Node
527
468
  include ParserNodeExt
528
469
  end
@@ -10,12 +10,12 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "extend parser node"
12
12
  spec.description = "extend parser node, add parent and sibling, use meaning properties to get child node"
13
- spec.homepage = "https://github.com/xinminlabs/parser_node_ext"
13
+ spec.homepage = "https://github.com/synvert-hq/parser_node_ext"
14
14
  spec.required_ruby_version = ">= 2.6.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/xinminlabs/parser_node_ext"
18
- spec.metadata["changelog_uri"] = "https://github.com/xinminlabs/parser_node_ext/blob/main/CHANGELOG.md"
17
+ spec.metadata["source_code_uri"] = "https://github.com/synvert-hq/parser_node_ext"
18
+ spec.metadata["changelog_uri"] = "https://github.com/synvert-hq/parser_node_ext/blob/main/CHANGELOG.md"
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
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: 1.2.2
4
+ version: 1.3.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-02-10 00:00:00.000000000 Z
11
+ date: 2024-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -39,14 +39,15 @@ files:
39
39
  - README.md
40
40
  - Rakefile
41
41
  - lib/parser_node_ext.rb
42
+ - lib/parser_node_ext/parent_node_ext.rb
42
43
  - lib/parser_node_ext/version.rb
43
44
  - parser_node_ext.gemspec
44
- homepage: https://github.com/xinminlabs/parser_node_ext
45
+ homepage: https://github.com/synvert-hq/parser_node_ext
45
46
  licenses: []
46
47
  metadata:
47
- homepage_uri: https://github.com/xinminlabs/parser_node_ext
48
- source_code_uri: https://github.com/xinminlabs/parser_node_ext
49
- changelog_uri: https://github.com/xinminlabs/parser_node_ext/blob/main/CHANGELOG.md
48
+ homepage_uri: https://github.com/synvert-hq/parser_node_ext
49
+ source_code_uri: https://github.com/synvert-hq/parser_node_ext
50
+ changelog_uri: https://github.com/synvert-hq/parser_node_ext/blob/main/CHANGELOG.md
50
51
  post_install_message:
51
52
  rdoc_options: []
52
53
  require_paths: