masamune-ast 1.2.0 → 1.2.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: 3029256236d8953d9f258d370abb57d1dac4a425b9112f7f4a5a42e951634943
4
- data.tar.gz: 123f4977244d1db7d1cbceebee495e6a7d8494401f1db86f4a8360de27b06f2e
3
+ metadata.gz: f599b770d8e12444bbb2c2bb6aad28d8d0b9673e99708d9d713af4186f96fb4f
4
+ data.tar.gz: 723f6ab17c2152f9ab92e6da6f0130bc1ab1aa1fd0174ee00a1d9bb7206df182
5
5
  SHA512:
6
- metadata.gz: 3282cd14e7c591bff140c5d92d782a9724be2af32e9cc2542a0aab949fd469ad4c526c2a11255be267546cb2d1634e97ea7d950c8762c21635fc4274fe5f487c
7
- data.tar.gz: d652c21b25b38d460045336d9dd330afb302470358a98f43a0eacb7f79128cdc26e8efe6d233f41067f2be28af3314585ba03b0df1f83e47f8f7d8419a018d98
6
+ metadata.gz: 622cfe88710212e12d4045fe39837dd9767b56b64abb62872f544b37d6ac286f85dfb9324ef709bb32ab4219e280eff7f4fc6a966ddb379b79b5a5b3b9c06dc3
7
+ data.tar.gz: 7db8c29128764c9c36f79a98156c68d4bc008a183ceeed351405a6377606721e33523b267362b0cf1f3a19119db3e1606d494869ec28f340680a8812a4e3868b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- masamune-ast (1.2.0)
4
+ masamune-ast (1.2.1)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -26,6 +26,7 @@ GEM
26
26
  concurrent-ruby (~> 1.0)
27
27
 
28
28
  PLATFORMS
29
+ x86_64-darwin-21
29
30
  x86_64-linux
30
31
 
31
32
  DEPENDENCIES
@@ -26,27 +26,11 @@ module Masamune
26
26
  # ]
27
27
  # TODO: Worry about using a faster sorting algorithm later.
28
28
  def self.order_results_by_position(results)
29
- final_result = []
30
-
31
- line_numbers = results.map {|result| result[:line_number]}.uniq.sort
32
- line_numbers.each do |line_number|
33
- # Group data together in an array if they're on the same line.
34
- shared_line_data = results.select {|result| result[:line_number] == line_number}
35
-
36
- # Sort the positions on each line number respectively.
37
- indexes_on_line = shared_line_data.map {|data| data[:index_on_line]}.sort
38
-
39
- # Apply to the final result.
40
- indexes_on_line.each do |index_on_line|
41
- shared_line_data.each do |data|
42
- if data[:index_on_line] == index_on_line
43
- final_result << data
44
- end
45
- end
46
- end
29
+ results.sort do |a, b|
30
+ by_line = a[:line_number] <=> b[:line_number]
31
+ # If we're on the same line, refer to the inner index for order.
32
+ by_line.zero? ? a[:index_on_line] <=> b[:index_on_line] : by_line
47
33
  end
48
-
49
- final_result
50
34
  end
51
35
 
52
36
  def line_data_and_token
@@ -52,32 +52,22 @@ module Masamune
52
52
 
53
53
  # TODO: Add block_params: true to the arguments.
54
54
  def variables(name: nil, result_type: Hash)
55
- var_classes = [
56
- :var_field,
57
- :var_ref,
58
- :params
59
- ].map {|type| get_node_class(type)}
60
- results = find_nodes(var_classes, token: name, result_type: result_type)
55
+ results = find_nodes([VarField, VarRef, Params], token: name, result_type: result_type)
61
56
  order_results(results)
62
57
  end
63
58
 
64
59
  def strings(content: nil, result_type: Hash)
65
- results = find_nodes(get_node_class(:string_content), token: content, result_type: result_type)
60
+ results = find_nodes(StringContent, token: content, result_type: result_type)
66
61
  order_results(results)
67
62
  end
68
63
 
69
64
  def method_definitions(name: nil, result_type: Hash)
70
- results = find_nodes(get_node_class(:def), token: name, result_type: result_type)
65
+ results = find_nodes(Def, token: name, result_type: result_type)
71
66
  order_results(results)
72
67
  end
73
68
 
74
69
  def method_calls(name: nil, result_type: Hash)
75
- method_classes = [
76
- :vcall,
77
- :call,
78
- :command
79
- ].map {|type| get_node_class(type)}
80
- results = find_nodes(method_classes, token: name, result_type: result_type)
70
+ results = find_nodes([Vcall, Call, Command], token: name, result_type: result_type)
81
71
  order_results(results)
82
72
  end
83
73
 
@@ -95,17 +85,17 @@ module Masamune
95
85
  end
96
86
 
97
87
  def symbol_literals(content: nil, result_type: Hash)
98
- results = find_nodes(get_node_class(:symbol_literal), token: content, result_type: result_type)
88
+ results = find_nodes(SymbolLiteral, token: content, result_type: result_type)
99
89
  order_results(results)
100
90
  end
101
91
 
102
92
  def string_symbols(content: nil, result_type: Hash)
103
- results = find_nodes(get_node_class(:dyna_symbol), token: content, result_type: result_type)
93
+ results = find_nodes(DynaSymbol, token: content, result_type: result_type)
104
94
  order_results(results)
105
95
  end
106
96
 
107
97
  def comments(content: nil, result_type: Hash)
108
- results = find_nodes(get_node_class(:comment), token: content, result_type: result_type)
98
+ results = find_nodes(Comment, token: content, result_type: result_type)
109
99
  order_results(results)
110
100
  end
111
101
 
@@ -116,17 +106,16 @@ module Masamune
116
106
 
117
107
  def block_params(content: nil, result_type: Hash)
118
108
  # TODO: do_block_params + brace_block_params
119
- results = find_nodes(get_node_class(:params), token: content, result_type: result_type)
109
+ results = find_nodes(Params, token: content, result_type: result_type)
120
110
  order_results(results)
121
111
  end
122
112
 
123
113
  def find_nodes(token_classes, token: nil, result_type: Hash)
124
- # Ensure the classes are in an array
125
- token_classes = [token_classes].flatten
114
+ token_classes = Array(token_classes)
126
115
 
127
116
  nodes = []
128
117
  token_classes.each do |klass|
129
- if klass == Masamune::AbstractSyntaxTree::Comment
118
+ if klass == Comment
130
119
  nodes = @comment_list.dup
131
120
  else
132
121
  nodes << @node_list.select {|node| node.class == klass}
@@ -149,7 +138,7 @@ module Masamune
149
138
  nodes.each do |node|
150
139
  # Data for symbols are housed within a nested node, so we handle those differently here.
151
140
  # Read the comments for `get_symbol_data` in the symbol node classes for details.
152
- if node.class == Masamune::AbstractSyntaxTree::SymbolLiteral || node.class == Masamune::AbstractSyntaxTree::DynaSymbol
141
+ if node.class == SymbolLiteral || node.class == DynaSymbol
153
142
  final_result << node.get_symbol_data.line_data_and_token
154
143
  else
155
144
  node.data_nodes.each {|dn| final_result << dn.line_data_and_token} if node.data_nodes
@@ -176,13 +165,7 @@ module Masamune
176
165
  private
177
166
 
178
167
  def get_node_class(type)
179
- begin
180
- "Masamune::AbstractSyntaxTree::#{type.to_s.camelize}".constantize
181
- rescue NameError
182
- # For all other nodes that we haven't covered yet, we just make a general class.
183
- # We can worry about adding the classes for other nodes as we go.
184
- Node
185
- end
168
+ "#{self.class}::#{type.to_s.camelize}".safe_constantize || Node # Return base Node class for any not-yet-covered nodes.
186
169
  end
187
170
 
188
171
  # We only order results when they are a Hash.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Masamune
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  end
data/lib/masamune.rb CHANGED
@@ -30,7 +30,6 @@ require "masamune/abstract_syntax_tree/nodes/symbol"
30
30
  require "masamune/abstract_syntax_tree/nodes/vcall"
31
31
 
32
32
  require "pp"
33
- require "pry"
34
33
 
35
34
  module Masamune
36
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: masamune-ast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Zayas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-27 00:00:00.000000000 Z
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -71,7 +71,7 @@ metadata:
71
71
  homepage_uri: https://www.github.com/gazayas/masamune-ast
72
72
  source_code_uri: https://www.github.com/gazayas/masamune-ast
73
73
  changelog_uri: https://www.github.com/gazayas/masamune-ast
74
- post_install_message:
74
+ post_install_message:
75
75
  rdoc_options: []
76
76
  require_paths:
77
77
  - lib
@@ -86,8 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.3.7
90
- signing_key:
89
+ rubygems_version: 3.4.1
90
+ signing_key:
91
91
  specification_version: 4
92
92
  summary: Masamune
93
93
  test_files: []