masamune-ast 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +33 -4
- data/lib/masamune-ast/abstract_syntax_tree/data_node.rb +2 -2
- data/lib/masamune-ast/abstract_syntax_tree/node.rb +1 -1
- data/lib/masamune-ast/abstract_syntax_tree.rb +2 -2
- data/lib/masamune-ast/lex_node.rb +1 -1
- data/lib/masamune-ast/slicer.rb +1 -1
- data/lib/masamune-ast/version.rb +2 -2
- data/lib/masamune-ast.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 418c2c9ca6e229ff03320d7057ff12f19cdbb60d3da8b9f1d03db901b6971b43
|
4
|
+
data.tar.gz: 3dda8f6d319d4ce961a8f9b3421d73bea5a8462c8c740b0c1f6e37e25e3020a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 165fb67094e4e12730106dd7262d4d8be67db9d7994ca96c5d94a46d2334c0c62d1aa9fab64637e9290e3aff6f7a8c8b913580b4ae3e2ed4584b52f40a82d55a
|
7
|
+
data.tar.gz: '006920de6a9409d6a08f6cfe955f918e8411c267665559aec9847fddffb6c514ca9283db8efbe73d8098f687c274d06439ffd681a817172ac5e7216fd61ef774'
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# Masamune
|
2
2
|
|
3
3
|
## A Ruby source code analyzer based on Ripper’s Abstract Syntax Tree generator (`Ripper#sexp`).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
+
```ruby
|
8
|
+
sudo gem install "masamune-ast"
|
9
|
+
```
|
10
|
+
|
11
|
+
Or add the following to your Gemfile and run `bundle install`
|
7
12
|
```ruby
|
8
13
|
gem "masamune-ast"
|
9
14
|
```
|
@@ -19,13 +24,37 @@ puts java + " is not " + javascript
|
|
19
24
|
# java
|
20
25
|
CODE
|
21
26
|
|
22
|
-
msmn =
|
27
|
+
msmn = Masamune::AbstractSyntaxTree.new(code)
|
23
28
|
|
29
|
+
# Searching the tree returns the specific node and the line number it's on.
|
24
30
|
msmn.variables
|
25
|
-
[[[1, 0], "java"], [[2, 0], "javascript"], [[2, 13], "java"]]
|
31
|
+
#=> [[[1, 0], "java"], [[2, 0], "javascript"], [[2, 13], "java"]]
|
26
32
|
|
27
33
|
msmn.search(:variable, "java")
|
28
34
|
#=> [[[1, 0], "java"], [[2, 13], "java"]]
|
35
|
+
|
36
|
+
code = <<CODE
|
37
|
+
ary = [1, 2, 3]
|
38
|
+
ary.sum.times do |n|
|
39
|
+
puts n
|
40
|
+
end
|
41
|
+
|
42
|
+
def foo
|
43
|
+
end
|
44
|
+
foo
|
45
|
+
foo # Call again
|
46
|
+
CODE
|
47
|
+
|
48
|
+
msmn = Masamune::AbstractSyntaxTree.new(code)
|
49
|
+
|
50
|
+
msmn.search(:method_call, "sum")
|
51
|
+
#=> [[[2, 4], "sum"]]
|
52
|
+
|
53
|
+
msmn.search(:def, "foo")
|
54
|
+
#=> [[[6, 4], "foo"]]
|
55
|
+
|
56
|
+
msmn.search(:method_call, "foo")
|
57
|
+
#=> [[[8, 0], "foo"], [[9, 0], "foo"]]
|
29
58
|
```
|
30
59
|
|
31
60
|
In some cases, it can be easier to look at the given lex nodes to analyze your source code:
|
@@ -59,7 +88,7 @@ msmn.lex_nodes[8].is_method_definition?
|
|
59
88
|
|
60
89
|
## Contributing
|
61
90
|
|
62
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/gazayas/masamune.
|
91
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gazayas/masamune-ast.
|
63
92
|
|
64
93
|
## License
|
65
94
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# TODO: Not sure if I'll implement this yet.
|
2
2
|
|
3
|
-
module
|
3
|
+
module Masamune
|
4
4
|
class AbstractSyntaxTree
|
5
|
-
class DataNode <<
|
5
|
+
class DataNode << Masamune::AbstractSyntaxTree::Node
|
6
6
|
def initialize(tree_node)
|
7
7
|
@parent, @contents, _ = tree_node
|
8
8
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Masamune
|
2
2
|
class AbstractSyntaxTree
|
3
3
|
attr_reader :data
|
4
4
|
attr_accessor :lex_nodes, :debug
|
@@ -7,7 +7,7 @@ module MasamuneAst
|
|
7
7
|
@data = Ripper.sexp(code)
|
8
8
|
raw_lex_nodes = Ripper.lex(code)
|
9
9
|
@lex_nodes = raw_lex_nodes.map do |lex_node|
|
10
|
-
|
10
|
+
Masamune::LexNode.new(raw_lex_nodes.index(lex_node), lex_node, self.__id__)
|
11
11
|
end
|
12
12
|
@debug = false
|
13
13
|
end
|
data/lib/masamune-ast/slicer.rb
CHANGED
data/lib/masamune-ast/version.rb
CHANGED
data/lib/masamune-ast.rb
CHANGED
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:
|
4
|
+
version: 1.0.0
|
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-
|
11
|
+
date: 2023-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A layer of abstraction on top of Ripper for handling Abstract Syntax
|
14
14
|
Trees in Ruby.
|
@@ -32,13 +32,13 @@ files:
|
|
32
32
|
- lib/masamune-ast/slicer.rb
|
33
33
|
- lib/masamune-ast/version.rb
|
34
34
|
- sig/masamune.rbs
|
35
|
-
homepage: https://www.github.com/gazayas/masamune
|
35
|
+
homepage: https://www.github.com/gazayas/masamune-ast
|
36
36
|
licenses:
|
37
37
|
- MIT
|
38
38
|
metadata:
|
39
|
-
homepage_uri: https://www.github.com/gazayas/masamune
|
40
|
-
source_code_uri: https://www.github.com/gazayas/masamune
|
41
|
-
changelog_uri: https://www.github.com/gazayas/masamune
|
39
|
+
homepage_uri: https://www.github.com/gazayas/masamune-ast
|
40
|
+
source_code_uri: https://www.github.com/gazayas/masamune-ast
|
41
|
+
changelog_uri: https://www.github.com/gazayas/masamune-ast
|
42
42
|
post_install_message:
|
43
43
|
rdoc_options: []
|
44
44
|
require_paths:
|
@@ -57,5 +57,5 @@ requirements: []
|
|
57
57
|
rubygems_version: 3.3.7
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
|
-
summary:
|
60
|
+
summary: Masamune
|
61
61
|
test_files: []
|