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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1131c8f9da2cb862e77f3840c9abc806443a7d4445d788fd3683cec41b1916e8
4
- data.tar.gz: bb9025361d1063fd3f7776070830b4e41b7529d3ea04b11fbe9466890bca8d28
3
+ metadata.gz: 418c2c9ca6e229ff03320d7057ff12f19cdbb60d3da8b9f1d03db901b6971b43
4
+ data.tar.gz: 3dda8f6d319d4ce961a8f9b3421d73bea5a8462c8c740b0c1f6e37e25e3020a1
5
5
  SHA512:
6
- metadata.gz: f6e571ac354ab0fae7e39fbf1d0030c1025738732d008b9c3afa9ade11c2cb41b88d67a08ac66d878dd913fae1a9cf08f79d4539f931b7a55fd43f563332d08b
7
- data.tar.gz: 47065f76eebaab82601b9d577a738765e66d588f6ad300931223bd61824e0f290612a6341dd098d8bd78cdb90e5b44ce9513d6beb5280b9ebc5691b4044145ea
6
+ metadata.gz: 165fb67094e4e12730106dd7262d4d8be67db9d7994ca96c5d94a46d2334c0c62d1aa9fab64637e9290e3aff6f7a8c8b913580b4ae3e2ed4584b52f40a82d55a
7
+ data.tar.gz: '006920de6a9409d6a08f6cfe955f918e8411c267665559aec9847fddffb6c514ca9283db8efbe73d8098f687c274d06439ffd681a817172ac5e7216fd61ef774'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0] - 2023-05-01
4
+
5
+ - Change `MasamuneAst` module to `Masamune`.
6
+
3
7
  ## [0.1.0] - 2023-04-24
4
8
 
5
9
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- masamune-ast (0.1.0)
4
+ masamune-ast (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,9 +1,14 @@
1
- # MasamuneAst
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 = MasamuneAst::AbstractSyntaxTree.new(code)
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 MasamuneAst
3
+ module Masamune
4
4
  class AbstractSyntaxTree
5
- class DataNode << MasamuneAst::AbstractSyntaxTree::Node
5
+ class DataNode << Masamune::AbstractSyntaxTree::Node
6
6
  def initialize(tree_node)
7
7
  @parent, @contents, _ = tree_node
8
8
  end
@@ -1,6 +1,6 @@
1
1
  # TODO: Not sure if I'll implement this yet.
2
2
 
3
- module MasamuneAst
3
+ module Masamune
4
4
  class AbstractSyntaxTree
5
5
  class Node
6
6
  def initialize(tree_node)
@@ -1,4 +1,4 @@
1
- module MasamuneAst
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
- MasamuneAst::LexNode.new(raw_lex_nodes.index(lex_node), lex_node, self.__id__)
10
+ Masamune::LexNode.new(raw_lex_nodes.index(lex_node), lex_node, self.__id__)
11
11
  end
12
12
  @debug = false
13
13
  end
@@ -1,4 +1,4 @@
1
- module MasamuneAst
1
+ module Masamune
2
2
  # https://docs.ruby-lang.org/en/3.0/Ripper.html#method-c-lex
3
3
  #
4
4
  # @position: Line number and starting point on the line. i.e. - [4, 7].
@@ -1,4 +1,4 @@
1
- module MasamuneAst
1
+ module Masamune
2
2
  module Slicer
3
3
  def initialize(ast)
4
4
  @ast = ast
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MasamuneAst
4
- VERSION = "0.1.0"
3
+ module Masamune
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/masamune-ast.rb CHANGED
@@ -8,5 +8,5 @@ require "masamune-ast/abstract_syntax_tree"
8
8
  require "pp"
9
9
  require "pry"
10
10
 
11
- module MasamuneAst
11
+ module Masamune
12
12
  end
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: 0.1.0
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-04-29 00:00:00.000000000 Z
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: MasamuneAst
60
+ summary: Masamune
61
61
  test_files: []