masamune-ast 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/masamune/abstract_syntax_tree/block_var.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/dyna_symbol.rb +20 -0
- data/lib/masamune/abstract_syntax_tree/symbol.rb +17 -0
- data/lib/masamune/abstract_syntax_tree/symbol_literal.rb +21 -0
- data/lib/masamune/abstract_syntax_tree.rb +19 -1
- data/lib/masamune/version.rb +1 -1
- data/lib/masamune.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccb2d3e2f9229836db093e7d6e164a30a37302610835973bcba1bf63781d4869
|
4
|
+
data.tar.gz: afeba57c0b354caa8bb753c4dffdafc1aeca92b96997ec0345bd309c3c0cc33a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63c3961e42d7ae3264eac44d6d7c6b43f572f95daa2d4c56077eace0baf2fb1a7259f6f149ce0ab0dc11a00d463f463ae246ba1a563e5a4ef83405e3d5910641
|
7
|
+
data.tar.gz: c130f31c0d73a54af8775f538c928ae71d55a456b8f2d715b690ef9cf2b1de906fd808e47d3ad668630817d038d255feefd2cc309c221e5b4de5e693bc844f5c
|
data/Gemfile.lock
CHANGED
@@ -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
|
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,18 @@ 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
|
+
|
73
85
|
# @tree only shows comments as a type of `:void_stmt` and
|
74
86
|
# doesn't have a data node, so we get comments from @lex_nodes.
|
75
87
|
def comments(content: nil)
|
@@ -109,7 +121,13 @@ module Masamune
|
|
109
121
|
|
110
122
|
final_result = []
|
111
123
|
nodes.each do |node|
|
112
|
-
node
|
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
|
113
131
|
end
|
114
132
|
|
115
133
|
DataNode.order_results_by_position(final_result)
|
data/lib/masamune/version.rb
CHANGED
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.
|
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-
|
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
|