masamune-ast 1.1.1 → 1.1.3

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: a00f60e535cf2096a37cd6efd639aa7c132c70e58c3b422a23538128368b5c85
4
- data.tar.gz: 5d548fc4b9d5cf25c1099a2b446542f57342694d7b414052df004dcd2cf311c2
3
+ metadata.gz: ccb2d3e2f9229836db093e7d6e164a30a37302610835973bcba1bf63781d4869
4
+ data.tar.gz: afeba57c0b354caa8bb753c4dffdafc1aeca92b96997ec0345bd309c3c0cc33a
5
5
  SHA512:
6
- metadata.gz: c80bcefac510bfd4103d56fd13f39a46d1e4531eceb678d620709b97fe0c941f20f1e7ffddc6058e77aab46ab093d1d4ba768b6860649c5a57197e36f89bf109
7
- data.tar.gz: 731a46f94d655a820acdd949d7d7fa03f3fc37277858b5b5daea3c0c13444720b3b1ca829d0f304d5aecb3f390e3055168503ce6655653268cb89fcf19ab28e3
6
+ metadata.gz: 63c3961e42d7ae3264eac44d6d7c6b43f572f95daa2d4c56077eace0baf2fb1a7259f6f149ce0ab0dc11a00d463f463ae246ba1a563e5a4ef83405e3d5910641
7
+ data.tar.gz: c130f31c0d73a54af8775f538c928ae71d55a456b8f2d715b690ef9cf2b1de906fd808e47d3ad668630817d038d255feefd2cc309c221e5b4de5e693bc844f5c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- masamune-ast (1.1.1)
4
+ masamune-ast (1.1.3)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -11,7 +11,7 @@ module Masamune
11
11
 
12
12
  # :block_var has a lot of nil values within in.
13
13
  # I'm not sure what this represents, but it would be
14
- # nice to find out and implement it document/implement it somewhere.
14
+ # nice to find out and document/implement it somewhere.
15
15
  def extract_data_nodes
16
16
  @contents[1][1].map do |content|
17
17
  DataNode.new(content, @ast_id)
@@ -0,0 +1,20 @@
1
+ # TODO: Add description.
2
+
3
+ module Masamune
4
+ class AbstractSyntaxTree
5
+ class DynaSymbol < Node
6
+ def initialize(contents, ast_id)
7
+ super
8
+ end
9
+
10
+ # Dyna Symbols are symbols created from strings, i.e. - :"project".
11
+ # Since they have :@tstring_content inside of them, the data node
12
+ # is technically for a String, so instead of duplicating it here,
13
+ # we just use a method specifically for getting the symbol.
14
+ # This should be the same as the :symbol_literal type.
15
+ def get_symbol_data
16
+ DataNode.new(@contents[1][1], @ast_id)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # TODO: Add description.
2
+
3
+ module Masamune
4
+ class AbstractSyntaxTree
5
+ class Symbol < Node
6
+ def initialize(contents, ast_id)
7
+ super
8
+ end
9
+
10
+ def extract_data_nodes
11
+ [
12
+ DataNode.new(@contents[1], @ast_id)
13
+ ]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # TODO: Add description.
2
+
3
+ module Masamune
4
+ class AbstractSyntaxTree
5
+ class SymbolLiteral < Node
6
+ def initialize(contents, ast_id)
7
+ super
8
+ end
9
+
10
+ # Symbol Literals are a node type of :symbol_literal,
11
+ # but have a node type of :symbol nested within them.
12
+ # For the reason, the data node is technically for :symbol
13
+ # and not :symbol_literal, so instead of duplicating it here,
14
+ # we just use a method specifically for getting the symbol.
15
+ # This should be the same as the :dyna_symbol type.
16
+ def get_symbol_data
17
+ DataNode.new(@contents[1][1], @ast_id)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -70,6 +70,26 @@ module Masamune
70
70
  def brace_block_params
71
71
  end
72
72
 
73
+ def symbols(content: nil)
74
+ symbol_literals + string_symbols
75
+ end
76
+
77
+ def symbol_literals(content: nil)
78
+ find_nodes(get_node_class(:symbol_literal), token: content)
79
+ end
80
+
81
+ def string_symbols(content: nil)
82
+ find_nodes(get_node_class(:dyna_symbol), token: content)
83
+ end
84
+
85
+ # @tree only shows comments as a type of `:void_stmt` and
86
+ # doesn't have a data node, so we get comments from @lex_nodes.
87
+ def comments(content: nil)
88
+ comments = @lex_nodes.select {|node| node.type == :comment}
89
+ comments.select {|comment| comment.token == content} if content
90
+ comments.map {|comment| {position: comment.position, token: comment.token}}
91
+ end
92
+
73
93
  def all_methods
74
94
  method_definitions + method_calls
75
95
  end
@@ -101,7 +121,13 @@ module Masamune
101
121
 
102
122
  final_result = []
103
123
  nodes.each do |node|
104
- node.data_nodes.each {|dn| final_result << dn.position_and_token} if node.data_nodes
124
+ # Data for symbols are housed within a nested node, so we handle those differently here.
125
+ # Read the comments for `get_symbol_data` in the symbol node classes for details.
126
+ if node.class == Masamune::AbstractSyntaxTree::SymbolLiteral || node.class == Masamune::AbstractSyntaxTree::DynaSymbol
127
+ final_result << node.get_symbol_data.position_and_token
128
+ else
129
+ node.data_nodes.each {|dn| final_result << dn.position_and_token} if node.data_nodes
130
+ end
105
131
  end
106
132
 
107
133
  DataNode.order_results_by_position(final_result)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Masamune
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.3"
5
5
  end
data/lib/masamune.rb CHANGED
@@ -16,9 +16,12 @@ require "masamune/abstract_syntax_tree/brace_block"
16
16
  require "masamune/abstract_syntax_tree/call"
17
17
  require "masamune/abstract_syntax_tree/def"
18
18
  require "masamune/abstract_syntax_tree/do_block"
19
+ require "masamune/abstract_syntax_tree/dyna_symbol"
19
20
  require "masamune/abstract_syntax_tree/params"
20
21
  require "masamune/abstract_syntax_tree/program"
21
22
  require "masamune/abstract_syntax_tree/string_content"
23
+ require "masamune/abstract_syntax_tree/symbol_literal"
24
+ require "masamune/abstract_syntax_tree/symbol"
22
25
  require "masamune/abstract_syntax_tree/var_field"
23
26
  require "masamune/abstract_syntax_tree/var_ref"
24
27
  require "masamune/abstract_syntax_tree/vcall"
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.1.1
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Zayas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-03 00:00:00.000000000 Z
11
+ date: 2023-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -47,10 +47,13 @@ files:
47
47
  - lib/masamune/abstract_syntax_tree/data_node.rb
48
48
  - lib/masamune/abstract_syntax_tree/def.rb
49
49
  - lib/masamune/abstract_syntax_tree/do_block.rb
50
+ - lib/masamune/abstract_syntax_tree/dyna_symbol.rb
50
51
  - lib/masamune/abstract_syntax_tree/node.rb
51
52
  - lib/masamune/abstract_syntax_tree/params.rb
52
53
  - lib/masamune/abstract_syntax_tree/program.rb
53
54
  - lib/masamune/abstract_syntax_tree/string_content.rb
55
+ - lib/masamune/abstract_syntax_tree/symbol.rb
56
+ - lib/masamune/abstract_syntax_tree/symbol_literal.rb
54
57
  - lib/masamune/abstract_syntax_tree/var_field.rb
55
58
  - lib/masamune/abstract_syntax_tree/var_ref.rb
56
59
  - lib/masamune/abstract_syntax_tree/vcall.rb