masamune-ast 1.1.4 → 1.1.5
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/README.md +3 -1
- data/lib/masamune/abstract_syntax_tree/data_node.rb +3 -2
- data/lib/masamune/abstract_syntax_tree/nodes/call.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/command.rb +64 -0
- data/lib/masamune/abstract_syntax_tree/nodes/def.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/params.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/string_content.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/support_nodes/comment.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/symbol.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/symbols/dyna_symbol.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/symbols/symbol_literal.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/variables/block_var.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/variables/var_field.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/variables/var_ref.rb +1 -1
- data/lib/masamune/abstract_syntax_tree/nodes/vcall.rb +1 -1
- data/lib/masamune/abstract_syntax_tree.rb +2 -1
- data/lib/masamune/version.rb +1 -1
- data/lib/masamune.rb +1 -0
- metadata +3 -2
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
|
|
@@ -90,6 +90,7 @@ msmn = Masamune::AbstractSyntaxTree.new(code)
|
|
90
90
|
msmn.all_methods
|
91
91
|
#=> [{:position=>[2, 4], :token=>"sum"},
|
92
92
|
#=> {:position=>[2, 8], :token=>"times"},
|
93
|
+
#=> {:position=>[3, 2], :token=>"puts"},
|
93
94
|
#=> {:position=>[6, 4], :token=>"foo"},
|
94
95
|
#=> {:position=>[8, 0], :token=>"foo"},
|
95
96
|
#=> {:position=>[9, 0], :token=>"foo"}]
|
@@ -97,6 +98,7 @@ msmn.all_methods
|
|
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
|
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -74,7 +74,8 @@ module Masamune
|
|
74
74
|
def method_calls(name: nil, result_type: Hash)
|
75
75
|
method_classes = [
|
76
76
|
:vcall,
|
77
|
-
:call
|
77
|
+
:call,
|
78
|
+
:command
|
78
79
|
].map {|type| get_node_class(type)}
|
79
80
|
results = find_nodes(method_classes, token: name, result_type: result_type)
|
80
81
|
order_results(results)
|
data/lib/masamune/version.rb
CHANGED
data/lib/masamune.rb
CHANGED
@@ -21,6 +21,7 @@ require "masamune/abstract_syntax_tree/nodes/variables/var_field"
|
|
21
21
|
require "masamune/abstract_syntax_tree/nodes/variables/var_ref"
|
22
22
|
require "masamune/abstract_syntax_tree/nodes/assign"
|
23
23
|
require "masamune/abstract_syntax_tree/nodes/call"
|
24
|
+
require "masamune/abstract_syntax_tree/nodes/command"
|
24
25
|
require "masamune/abstract_syntax_tree/nodes/def"
|
25
26
|
require "masamune/abstract_syntax_tree/nodes/params"
|
26
27
|
require "masamune/abstract_syntax_tree/nodes/program"
|
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
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/masamune/abstract_syntax_tree/nodes/blocks/brace_block.rb
|
47
47
|
- lib/masamune/abstract_syntax_tree/nodes/blocks/do_block.rb
|
48
48
|
- lib/masamune/abstract_syntax_tree/nodes/call.rb
|
49
|
+
- lib/masamune/abstract_syntax_tree/nodes/command.rb
|
49
50
|
- lib/masamune/abstract_syntax_tree/nodes/def.rb
|
50
51
|
- lib/masamune/abstract_syntax_tree/nodes/params.rb
|
51
52
|
- lib/masamune/abstract_syntax_tree/nodes/program.rb
|