masamune-ast 1.1.3 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +39 -4
- data/lib/masamune/abstract_syntax_tree/data_node.rb +3 -2
- data/lib/masamune/abstract_syntax_tree/nodes/blocks/brace_block.rb +13 -0
- data/lib/masamune/abstract_syntax_tree/nodes/blocks/do_block.rb +13 -0
- data/lib/masamune/abstract_syntax_tree/{call.rb → nodes/call.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/command.rb +64 -0
- data/lib/masamune/abstract_syntax_tree/{def.rb → nodes/def.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{params.rb → nodes/params.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{program.rb → nodes/program.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{string_content.rb → nodes/string_content.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{do_block.rb → nodes/support_nodes/block.rb} +3 -4
- data/lib/masamune/abstract_syntax_tree/nodes/support_nodes/comment.rb +25 -0
- data/lib/masamune/abstract_syntax_tree/{symbol.rb → nodes/symbol.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{dyna_symbol.rb → nodes/symbols/dyna_symbol.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{symbol_literal.rb → nodes/symbols/symbol_literal.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{block_var.rb → nodes/variables/block_var.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{var_field.rb → nodes/variables/var_field.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{var_ref.rb → nodes/variables/var_ref.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree/{vcall.rb → nodes/vcall.rb} +1 -1
- data/lib/masamune/abstract_syntax_tree.rb +70 -30
- data/lib/masamune/slasher.rb +3 -2
- data/lib/masamune/version.rb +1 -1
- data/lib/masamune.rb +19 -16
- metadata +20 -17
- data/lib/masamune/abstract_syntax_tree/brace_block.rb +0 -19
- /data/lib/masamune/abstract_syntax_tree/{assign.rb → nodes/assign.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cde8e5ad304fc141ebf9a19a2b14ca11bdb5a582f37946e7190888a142cbf800
|
4
|
+
data.tar.gz: 79cfd7151f94c22f78efd3fcfda3be6321b68a76ea5d5175b73ecd96b2ae2331
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 071e318a82a6c9df04ca33746f2f1e97ff2a49362e054621d7ff490bf727574bcd55648c6fcdd63ec6f49c5962eea009fbdce1acd6bc98d0f5d9bc35f3336d9e
|
7
|
+
data.tar.gz: 7bfd78af1aa7e621f343ef77521a2895921b449f944487518746b201ff3d925fe9e22645b17d7bd8fd83fcaf89463870f339bb2fa0a654c9bc9c9cf194bb2183
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Masamune
|
2
2
|
|
3
|
-
## A Ruby source code analyzer based on Ripper’s Abstract Syntax Tree generator
|
3
|
+
## A Ruby source code analyzer based on Ripper’s Abstract Syntax Tree generator.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -33,7 +33,7 @@ code = <<~CODE
|
|
33
33
|
CODE
|
34
34
|
|
35
35
|
msmn = Masamune::AbstractSyntaxTree.new(code)
|
36
|
-
msmn.replace(type: :
|
36
|
+
msmn.replace(type: :variable, old_token: "n", new_token: "foo")
|
37
37
|
|
38
38
|
# This will produce the following code in string form.
|
39
39
|
10.times do |foo|
|
@@ -88,15 +88,17 @@ CODE
|
|
88
88
|
msmn = Masamune::AbstractSyntaxTree.new(code)
|
89
89
|
|
90
90
|
msmn.all_methods
|
91
|
-
#=> [{:position=>[
|
92
|
-
#=> {:position=>[2, 4], :token=>"sum"},
|
91
|
+
#=> [{:position=>[2, 4], :token=>"sum"},
|
93
92
|
#=> {:position=>[2, 8], :token=>"times"},
|
93
|
+
#=> {:position=>[3, 2], :token=>"puts"},
|
94
|
+
#=> {:position=>[6, 4], :token=>"foo"},
|
94
95
|
#=> {:position=>[8, 0], :token=>"foo"},
|
95
96
|
#=> {:position=>[9, 0], :token=>"foo"}]
|
96
97
|
|
97
98
|
msmn.method_calls
|
98
99
|
#=> [{:position=>[2, 4], :token=>"sum"},
|
99
100
|
#=> {:position=>[2, 8], :token=>"times"},
|
101
|
+
#=> {:position=>[3, 2], :token=>"puts"},
|
100
102
|
#=> {:position=>[8, 0], :token=>"foo"},
|
101
103
|
#=> {:position=>[9, 0], :token=>"foo"}]
|
102
104
|
|
@@ -104,6 +106,39 @@ msmn.method_definitions
|
|
104
106
|
#=> [{:position=>[6, 4], :token=>"foo"}]
|
105
107
|
```
|
106
108
|
|
109
|
+
You can also return the node classes themselves and get the data from there:
|
110
|
+
```ruby
|
111
|
+
code = <<~CODE
|
112
|
+
"ruby"
|
113
|
+
"rails"
|
114
|
+
CODE
|
115
|
+
|
116
|
+
msmn = Masamune::AbstractSyntaxTree.new(code)
|
117
|
+
msmn.strings(result_type: :nodes)
|
118
|
+
#=> [#<Masamune::AbstractSyntaxTree::StringContent:0x00007f6f7c9a6850
|
119
|
+
#=> @ast_id=1440,
|
120
|
+
#=> @contents=[:string_content, [:@tstring_content, "ruby", [1, 1]]],
|
121
|
+
#=> @data_nodes=
|
122
|
+
#=> [#<Masamune::AbstractSyntaxTree::DataNode:0x00007f6f7c9a6828
|
123
|
+
#=> @ast_id=1440,
|
124
|
+
#=> @contents=[:@tstring_content, "ruby", [1, 1]],
|
125
|
+
#=> @data_nodes=nil,
|
126
|
+
#=> @line_position=[1, 1],
|
127
|
+
#=> @token="ruby",
|
128
|
+
#=> @type=:@tstring_content>]>,
|
129
|
+
#=> #<Masamune::AbstractSyntaxTree::StringContent:0x00007f6f7c9a5630
|
130
|
+
#=> @ast_id=1440,
|
131
|
+
#=> @contents=[:string_content, [:@tstring_content, "rails", [2, 1]]],
|
132
|
+
#=> @data_nodes=
|
133
|
+
#=> [#<Masamune::AbstractSyntaxTree::DataNode:0x00007f6f7c9a5608
|
134
|
+
#=> @ast_id=1440,
|
135
|
+
#=> @contents=[:@tstring_content, "rails", [2, 1]],
|
136
|
+
#=> @data_nodes=nil,
|
137
|
+
#=> @line_position=[2, 1],
|
138
|
+
#=> @token="rails",
|
139
|
+
#=> @type=:@tstring_content>]>]
|
140
|
+
```
|
141
|
+
|
107
142
|
In some cases, it can be easier to look at the given lex nodes to analyze your source code since you can easily see the index and the line position it's on:
|
108
143
|
```ruby
|
109
144
|
msmn.lex_nodes
|
@@ -11,8 +11,9 @@ module Masamune
|
|
11
11
|
class DataNode < Node
|
12
12
|
attr_reader :type, :token, :line_position
|
13
13
|
|
14
|
-
def initialize(contents, ast_id)
|
14
|
+
def initialize(contents, ast_id, parent)
|
15
15
|
@type, @token, @line_position = contents
|
16
|
+
@parent = parent
|
16
17
|
super(contents, ast_id)
|
17
18
|
end
|
18
19
|
|
@@ -26,7 +27,7 @@ module Masamune
|
|
26
27
|
def self.order_results_by_position(position_and_token_ary)
|
27
28
|
# Extract the line numbers first, i.e - 4 from [4, 7]
|
28
29
|
line_numbers = position_and_token_ary.map do |position_and_token|
|
29
|
-
|
30
|
+
position_and_token[:position].first
|
30
31
|
end.uniq.sort
|
31
32
|
|
32
33
|
final_result = []
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Code example:
|
2
|
+
# puts "hello"
|
3
|
+
#
|
4
|
+
# syntax_tree output:
|
5
|
+
# SyntaxTree::Command[
|
6
|
+
# message: SyntaxTree::Ident[value: "puts"],
|
7
|
+
# arguments: SyntaxTree::Args[
|
8
|
+
# parts: [
|
9
|
+
# SyntaxTree::StringLiteral[
|
10
|
+
# parts: [SyntaxTree::TStringContent[value: "greetings"]]
|
11
|
+
# ]
|
12
|
+
# ]
|
13
|
+
# ]
|
14
|
+
# ]
|
15
|
+
|
16
|
+
# Code example:
|
17
|
+
# namespace :project
|
18
|
+
# resources :pages
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# syntax_tree output:
|
22
|
+
# SyntaxTree::Command[
|
23
|
+
# message: SyntaxTree::Ident[value: "namespace"],
|
24
|
+
# arguments: SyntaxTree::Args[
|
25
|
+
# parts: [SyntaxTree::SymbolLiteral[value: SyntaxTree::Ident[value: "project"]]]
|
26
|
+
# ],
|
27
|
+
# block: SyntaxTree::BlockNode[
|
28
|
+
# bodystmt: SyntaxTree::BodyStmt[
|
29
|
+
# statements: SyntaxTree::Statements[
|
30
|
+
# body: [
|
31
|
+
# SyntaxTree::Command[
|
32
|
+
# message: SyntaxTree::Ident[value: "resources"],
|
33
|
+
# arguments: SyntaxTree::Args[
|
34
|
+
# parts: [
|
35
|
+
# SyntaxTree::SymbolLiteral[
|
36
|
+
# value: SyntaxTree::Ident[value: "pages"]
|
37
|
+
# ]
|
38
|
+
# ]
|
39
|
+
# ]
|
40
|
+
# ]
|
41
|
+
# ]
|
42
|
+
# ]
|
43
|
+
# ]
|
44
|
+
# ]
|
45
|
+
# ]
|
46
|
+
|
47
|
+
|
48
|
+
# TODO: As you can see in the second example above, `command` can receive a
|
49
|
+
# block, so we might want to have a way to access the block node in the future.
|
50
|
+
module Masamune
|
51
|
+
class AbstractSyntaxTree
|
52
|
+
class Command < Node
|
53
|
+
def initialize(contents, ast_id)
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
57
|
+
def extract_data_nodes
|
58
|
+
[
|
59
|
+
DataNode.new(@contents[1], @ast_id, self)
|
60
|
+
]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# DoBlock and BraceBlock share some of
|
2
|
+
# the same logic, so we share that here.
|
2
3
|
|
3
4
|
module Masamune
|
4
5
|
class AbstractSyntaxTree
|
5
|
-
class
|
6
|
-
attr_accessor :ast_id
|
7
|
-
|
6
|
+
class Block < Node
|
8
7
|
def initialize(contents, ast_id)
|
9
8
|
super
|
10
9
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# In the abstract syntax tree created by Ripper.sexp,
|
2
|
+
# the type for comments is :void_stmt, and it doesn't have
|
3
|
+
# a data node within it either. This means that the text
|
4
|
+
# for the comment doesn't exist in the ast. It DOES exist
|
5
|
+
# in LexNode though, so we grab from them there instead.
|
6
|
+
|
7
|
+
module Masamune
|
8
|
+
class AbstractSyntaxTree
|
9
|
+
class Comment < Node
|
10
|
+
def initialize(contents, ast_id)
|
11
|
+
super
|
12
|
+
|
13
|
+
# Since this is techincally supposed to be a :void_stmt
|
14
|
+
# in this ast, we just leave this as nil.
|
15
|
+
@contents = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def extract_data_nodes
|
19
|
+
[
|
20
|
+
DataNode.new([contents.type, contents.token, contents.position], @ast_id, self)
|
21
|
+
]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -13,7 +13,7 @@ module Masamune
|
|
13
13
|
# we just use a method specifically for getting the symbol.
|
14
14
|
# This should be the same as the :symbol_literal type.
|
15
15
|
def get_symbol_data
|
16
|
-
DataNode.new(@contents[1][1], @ast_id)
|
16
|
+
DataNode.new(@contents[1][1], @ast_id, self)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/masamune/abstract_syntax_tree/{symbol_literal.rb → nodes/symbols/symbol_literal.rb}
RENAMED
@@ -14,7 +14,7 @@ module Masamune
|
|
14
14
|
# we just use a method specifically for getting the symbol.
|
15
15
|
# This should be the same as the :dyna_symbol type.
|
16
16
|
def get_symbol_data
|
17
|
-
DataNode.new(@contents[1][1], @ast_id)
|
17
|
+
DataNode.new(@contents[1][1], @ast_id, self)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Masamune
|
2
2
|
class AbstractSyntaxTree
|
3
|
-
attr_reader :code, :tree
|
3
|
+
attr_reader :code, :tree, :comment_list
|
4
4
|
attr_accessor :node_list, :data_node_list, :lex_nodes
|
5
5
|
|
6
6
|
def initialize(code)
|
@@ -13,7 +13,12 @@ module Masamune
|
|
13
13
|
|
14
14
|
@node_list = []
|
15
15
|
@data_node_list = []
|
16
|
+
@comment_list = []
|
16
17
|
register_nodes(@tree)
|
18
|
+
|
19
|
+
# Refer to Masamune::AbstractSyntaxTree::Comment
|
20
|
+
# to see why we register these separately.
|
21
|
+
register_comments
|
17
22
|
end
|
18
23
|
|
19
24
|
def register_nodes(tree_node = self.tree)
|
@@ -36,30 +41,44 @@ module Masamune
|
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
44
|
+
def register_comments
|
45
|
+
comment_lex_nodes = @lex_nodes.select {|node| node.type == :comment}.flatten
|
46
|
+
@comment_list << comment_lex_nodes.map {|node| Comment.new(node, self.__id__)}
|
47
|
+
@comment_list.flatten!
|
48
|
+
end
|
49
|
+
|
50
|
+
# TODO: A lot of these methods have the same content,
|
51
|
+
# so I want to come up with a way to refactor these.
|
52
|
+
|
39
53
|
# TODO: Add block_params: true to the arguments.
|
40
|
-
def variables(name: nil)
|
54
|
+
def variables(name: nil, result_type: Hash)
|
41
55
|
var_classes = [
|
42
56
|
:var_field,
|
43
57
|
:var_ref,
|
44
58
|
:params
|
45
59
|
].map {|type| get_node_class(type)}
|
46
|
-
find_nodes(var_classes, token: name)
|
60
|
+
results = find_nodes(var_classes, token: name, result_type: result_type)
|
61
|
+
order_results(results)
|
47
62
|
end
|
48
63
|
|
49
|
-
def strings(content: nil)
|
50
|
-
find_nodes(get_node_class(:string_content), token: content)
|
64
|
+
def strings(content: nil, result_type: Hash)
|
65
|
+
results = find_nodes(get_node_class(:string_content), token: content, result_type: result_type)
|
66
|
+
order_results(results)
|
51
67
|
end
|
52
68
|
|
53
|
-
def method_definitions(name: nil)
|
54
|
-
find_nodes(get_node_class(:def), token: name)
|
69
|
+
def method_definitions(name: nil, result_type: Hash)
|
70
|
+
results = find_nodes(get_node_class(:def), token: name, result_type: result_type)
|
71
|
+
order_results(results)
|
55
72
|
end
|
56
73
|
|
57
|
-
def method_calls(name: nil)
|
74
|
+
def method_calls(name: nil, result_type: Hash)
|
58
75
|
method_classes = [
|
59
76
|
:vcall,
|
60
|
-
:call
|
77
|
+
:call,
|
78
|
+
:command
|
61
79
|
].map {|type| get_node_class(type)}
|
62
|
-
find_nodes(method_classes, token: name)
|
80
|
+
results = find_nodes(method_classes, token: name, result_type: result_type)
|
81
|
+
order_results(results)
|
63
82
|
end
|
64
83
|
|
65
84
|
# TODO
|
@@ -70,49 +89,56 @@ module Masamune
|
|
70
89
|
def brace_block_params
|
71
90
|
end
|
72
91
|
|
73
|
-
def symbols(content: nil)
|
74
|
-
symbol_literals + string_symbols
|
92
|
+
def symbols(content: nil, result_type: Hash)
|
93
|
+
results = symbol_literals(content: content, result_type: result_type) + string_symbols(content: content, result_type: result_type)
|
94
|
+
order_results(results)
|
75
95
|
end
|
76
96
|
|
77
|
-
def symbol_literals(content: nil)
|
78
|
-
find_nodes(get_node_class(:symbol_literal), token: content)
|
97
|
+
def symbol_literals(content: nil, result_type: Hash)
|
98
|
+
results = find_nodes(get_node_class(:symbol_literal), token: content, result_type: result_type)
|
99
|
+
order_results(results)
|
79
100
|
end
|
80
101
|
|
81
|
-
def string_symbols(content: nil)
|
82
|
-
find_nodes(get_node_class(:dyna_symbol), token: content)
|
102
|
+
def string_symbols(content: nil, result_type: Hash)
|
103
|
+
results = find_nodes(get_node_class(:dyna_symbol), token: content, result_type: result_type)
|
104
|
+
order_results(results)
|
83
105
|
end
|
84
106
|
|
85
|
-
|
86
|
-
|
87
|
-
|
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}}
|
107
|
+
def comments(content: nil, result_type: Hash)
|
108
|
+
results = find_nodes(get_node_class(:comment), token: content, result_type: result_type)
|
109
|
+
order_results(results)
|
91
110
|
end
|
92
111
|
|
93
|
-
def all_methods
|
94
|
-
method_definitions + method_calls
|
112
|
+
def all_methods(name: nil, result_type: Hash)
|
113
|
+
results = method_definitions(name: name, result_type: result_type) + method_calls(name: name, result_type: result_type)
|
114
|
+
order_results(results)
|
95
115
|
end
|
96
116
|
|
97
|
-
def block_params
|
117
|
+
def block_params(content: nil, result_type: Hash)
|
98
118
|
# TODO: do_block_params + brace_block_params
|
99
|
-
find_nodes(get_node_class(:params))
|
119
|
+
results = find_nodes(get_node_class(:params), token: content, result_type: result_type)
|
120
|
+
order_results(results)
|
100
121
|
end
|
101
122
|
|
102
|
-
|
103
|
-
def find_nodes(token_classes, token: nil)
|
123
|
+
def find_nodes(token_classes, token: nil, result_type: Hash)
|
104
124
|
# Ensure the classes are in an array
|
105
125
|
token_classes = [token_classes].flatten
|
106
126
|
|
107
127
|
nodes = []
|
108
128
|
token_classes.each do |klass|
|
109
|
-
|
129
|
+
if klass == Masamune::AbstractSyntaxTree::Comment
|
130
|
+
nodes = @comment_list.dup
|
131
|
+
else
|
132
|
+
nodes << @node_list.select {|node| node.class == klass}
|
133
|
+
end
|
110
134
|
end
|
111
135
|
|
112
136
|
# Searching for multiple classes will yield multi-dimensional arrays,
|
113
137
|
# so we ensure everything is flattened out before moving forward.
|
114
138
|
nodes.flatten!
|
115
139
|
|
140
|
+
return nodes if result_type == :nodes
|
141
|
+
|
116
142
|
if token
|
117
143
|
# TODO: This most likely shouldn't be `node.data_nodes.first`.
|
118
144
|
# There are probably more data_nodes we need to check depending on the node class.
|
@@ -130,7 +156,10 @@ module Masamune
|
|
130
156
|
end
|
131
157
|
end
|
132
158
|
|
133
|
-
|
159
|
+
# Only order the information if we're returning hashes.
|
160
|
+
# TODO: We might want to change the placement of order_results_by_position
|
161
|
+
# if the operation is being done against hashes and not data nodes.
|
162
|
+
nodes.first.class.is_a?(Hash) ? DataNode.order_results_by_position(final_result) : final_result
|
134
163
|
end
|
135
164
|
|
136
165
|
def replace(type:, old_token:, new_token:)
|
@@ -154,5 +183,16 @@ module Masamune
|
|
154
183
|
Node
|
155
184
|
end
|
156
185
|
end
|
186
|
+
|
187
|
+
# We only order results when they are a Hash.
|
188
|
+
# The contents from the Hash are pulled from data nodes.
|
189
|
+
# i.e. - {position: [4, 7], token: "project"}
|
190
|
+
def order_results(results)
|
191
|
+
if results.first.is_a?(Hash)
|
192
|
+
DataNode.order_results_by_position(results)
|
193
|
+
else
|
194
|
+
results
|
195
|
+
end
|
196
|
+
end
|
157
197
|
end
|
158
198
|
end
|
data/lib/masamune/slasher.rb
CHANGED
@@ -3,8 +3,9 @@ module Masamune
|
|
3
3
|
def self.replace(type:, old_token:, new_token:, code:, ast:)
|
4
4
|
# `type` can either be a method from the ast like `method_definitions`,
|
5
5
|
# or it can be a list of Masamune::AbstractSyntaxTree node classes.
|
6
|
-
position_and_token_ary = if type.is_a?(Symbol)
|
7
|
-
|
6
|
+
position_and_token_ary = if type.is_a?(Symbol)
|
7
|
+
type_to_method = type.to_s.pluralize.to_sym
|
8
|
+
ast.send(type_to_method)
|
8
9
|
elsif type.is_a?(Array)
|
9
10
|
type.map {|klass| ast.find_nodes(klass)}.flatten
|
10
11
|
end
|
data/lib/masamune/version.rb
CHANGED
data/lib/masamune.rb
CHANGED
@@ -9,22 +9,25 @@ require "masamune/abstract_syntax_tree"
|
|
9
9
|
require "masamune/abstract_syntax_tree/node"
|
10
10
|
require "masamune/abstract_syntax_tree/data_node"
|
11
11
|
|
12
|
-
|
13
|
-
require "masamune/abstract_syntax_tree/
|
14
|
-
|
15
|
-
require "masamune/abstract_syntax_tree/brace_block"
|
16
|
-
require "masamune/abstract_syntax_tree/
|
17
|
-
require "masamune/abstract_syntax_tree/
|
18
|
-
require "masamune/abstract_syntax_tree/
|
19
|
-
require "masamune/abstract_syntax_tree/
|
20
|
-
require "masamune/abstract_syntax_tree/
|
21
|
-
require "masamune/abstract_syntax_tree/
|
22
|
-
require "masamune/abstract_syntax_tree/
|
23
|
-
require "masamune/abstract_syntax_tree/
|
24
|
-
require "masamune/abstract_syntax_tree/
|
25
|
-
require "masamune/abstract_syntax_tree/
|
26
|
-
require "masamune/abstract_syntax_tree/
|
27
|
-
require "masamune/abstract_syntax_tree/
|
12
|
+
require "masamune/abstract_syntax_tree/nodes/support_nodes/block"
|
13
|
+
require "masamune/abstract_syntax_tree/nodes/support_nodes/comment"
|
14
|
+
|
15
|
+
require "masamune/abstract_syntax_tree/nodes/blocks/brace_block"
|
16
|
+
require "masamune/abstract_syntax_tree/nodes/blocks/do_block"
|
17
|
+
require "masamune/abstract_syntax_tree/nodes/symbols/dyna_symbol"
|
18
|
+
require "masamune/abstract_syntax_tree/nodes/symbols/symbol_literal"
|
19
|
+
require "masamune/abstract_syntax_tree/nodes/variables/block_var"
|
20
|
+
require "masamune/abstract_syntax_tree/nodes/variables/var_field"
|
21
|
+
require "masamune/abstract_syntax_tree/nodes/variables/var_ref"
|
22
|
+
require "masamune/abstract_syntax_tree/nodes/assign"
|
23
|
+
require "masamune/abstract_syntax_tree/nodes/call"
|
24
|
+
require "masamune/abstract_syntax_tree/nodes/command"
|
25
|
+
require "masamune/abstract_syntax_tree/nodes/def"
|
26
|
+
require "masamune/abstract_syntax_tree/nodes/params"
|
27
|
+
require "masamune/abstract_syntax_tree/nodes/program"
|
28
|
+
require "masamune/abstract_syntax_tree/nodes/string_content"
|
29
|
+
require "masamune/abstract_syntax_tree/nodes/symbol"
|
30
|
+
require "masamune/abstract_syntax_tree/nodes/vcall"
|
28
31
|
|
29
32
|
require "pp"
|
30
33
|
require "pry"
|
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.5
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -40,23 +40,26 @@ files:
|
|
40
40
|
- Rakefile
|
41
41
|
- lib/masamune.rb
|
42
42
|
- lib/masamune/abstract_syntax_tree.rb
|
43
|
-
- lib/masamune/abstract_syntax_tree/assign.rb
|
44
|
-
- lib/masamune/abstract_syntax_tree/block_var.rb
|
45
|
-
- lib/masamune/abstract_syntax_tree/brace_block.rb
|
46
|
-
- lib/masamune/abstract_syntax_tree/call.rb
|
47
43
|
- lib/masamune/abstract_syntax_tree/data_node.rb
|
48
|
-
- lib/masamune/abstract_syntax_tree/def.rb
|
49
|
-
- lib/masamune/abstract_syntax_tree/do_block.rb
|
50
|
-
- lib/masamune/abstract_syntax_tree/dyna_symbol.rb
|
51
44
|
- lib/masamune/abstract_syntax_tree/node.rb
|
52
|
-
- lib/masamune/abstract_syntax_tree/
|
53
|
-
- lib/masamune/abstract_syntax_tree/
|
54
|
-
- lib/masamune/abstract_syntax_tree/
|
55
|
-
- lib/masamune/abstract_syntax_tree/
|
56
|
-
- lib/masamune/abstract_syntax_tree/
|
57
|
-
- lib/masamune/abstract_syntax_tree/
|
58
|
-
- lib/masamune/abstract_syntax_tree/
|
59
|
-
- lib/masamune/abstract_syntax_tree/
|
45
|
+
- lib/masamune/abstract_syntax_tree/nodes/assign.rb
|
46
|
+
- lib/masamune/abstract_syntax_tree/nodes/blocks/brace_block.rb
|
47
|
+
- lib/masamune/abstract_syntax_tree/nodes/blocks/do_block.rb
|
48
|
+
- lib/masamune/abstract_syntax_tree/nodes/call.rb
|
49
|
+
- lib/masamune/abstract_syntax_tree/nodes/command.rb
|
50
|
+
- lib/masamune/abstract_syntax_tree/nodes/def.rb
|
51
|
+
- lib/masamune/abstract_syntax_tree/nodes/params.rb
|
52
|
+
- lib/masamune/abstract_syntax_tree/nodes/program.rb
|
53
|
+
- lib/masamune/abstract_syntax_tree/nodes/string_content.rb
|
54
|
+
- lib/masamune/abstract_syntax_tree/nodes/support_nodes/block.rb
|
55
|
+
- lib/masamune/abstract_syntax_tree/nodes/support_nodes/comment.rb
|
56
|
+
- lib/masamune/abstract_syntax_tree/nodes/symbol.rb
|
57
|
+
- lib/masamune/abstract_syntax_tree/nodes/symbols/dyna_symbol.rb
|
58
|
+
- lib/masamune/abstract_syntax_tree/nodes/symbols/symbol_literal.rb
|
59
|
+
- lib/masamune/abstract_syntax_tree/nodes/variables/block_var.rb
|
60
|
+
- lib/masamune/abstract_syntax_tree/nodes/variables/var_field.rb
|
61
|
+
- lib/masamune/abstract_syntax_tree/nodes/variables/var_ref.rb
|
62
|
+
- lib/masamune/abstract_syntax_tree/nodes/vcall.rb
|
60
63
|
- lib/masamune/lex_node.rb
|
61
64
|
- lib/masamune/slasher.rb
|
62
65
|
- lib/masamune/version.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# TODO: Add description.
|
2
|
-
|
3
|
-
module Masamune
|
4
|
-
class AbstractSyntaxTree
|
5
|
-
class BraceBlock < Node
|
6
|
-
attr_accessor :ast_id
|
7
|
-
|
8
|
-
def initialize(contents, ast_id)
|
9
|
-
super
|
10
|
-
end
|
11
|
-
|
12
|
-
def params
|
13
|
-
# This node should exist already, so we search for it in the ast object.
|
14
|
-
block_var = BlockVar.new(contents[1], ast_id)
|
15
|
-
ast.node_list.find {|node| node.contents == block_var.contents}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
File without changes
|