masamune-ast 1.1.4 → 1.1.5

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: 34d1bcf1f5fc587393f5ded22b65afb26d64217253dcea0d83ea483574988326
4
- data.tar.gz: 21f726e99d53494fb50c08012962156245a37920425fae2ab338946d463f2721
3
+ metadata.gz: cde8e5ad304fc141ebf9a19a2b14ca11bdb5a582f37946e7190888a142cbf800
4
+ data.tar.gz: 79cfd7151f94c22f78efd3fcfda3be6321b68a76ea5d5175b73ecd96b2ae2331
5
5
  SHA512:
6
- metadata.gz: 2cca246c5770392976a5b9b9a577ac90a7363c8972bbf954f76493b13dfebbc16e3c3eeb3230238e348fa77f11accadf326fb774d11a40d03aaf172e15f9a946
7
- data.tar.gz: 9da6db975cdd75e0a3fc57056bcb2908054a54f90da996660d4fca46e967e64aa5431a78e118b8a264ca4749f421fc7dc667626da5b6e28b7d724656d7bca241
6
+ metadata.gz: 071e318a82a6c9df04ca33746f2f1e97ff2a49362e054621d7ff490bf727574bcd55648c6fcdd63ec6f49c5962eea009fbdce1acd6bc98d0f5d9bc35f3336d9e
7
+ data.tar.gz: 7bfd78af1aa7e621f343ef77521a2895921b449f944487518746b201ff3d925fe9e22645b17d7bd8fd83fcaf89463870f339bb2fa0a654c9bc9c9cf194bb2183
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- masamune-ast (1.1.4)
4
+ masamune-ast (1.1.5)
5
5
  activesupport
6
6
 
7
7
  GEM
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 (`Ripper#sexp`).
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
- line_number = position_and_token[:position].first
30
+ position_and_token[:position].first
30
31
  end.uniq.sort
31
32
 
32
33
  final_result = []
@@ -9,7 +9,7 @@ module Masamune
9
9
 
10
10
  def extract_data_nodes
11
11
  [
12
- DataNode.new(@contents.last, @ast_id)
12
+ DataNode.new(@contents.last, @ast_id, self)
13
13
  ]
14
14
  end
15
15
  end
@@ -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
@@ -9,7 +9,7 @@ module Masamune
9
9
 
10
10
  def extract_data_nodes
11
11
  [
12
- DataNode.new(@contents[1], @ast_id)
12
+ DataNode.new(@contents[1], @ast_id, self)
13
13
  ]
14
14
  end
15
15
  end
@@ -14,7 +14,7 @@ module Masamune
14
14
  # to ensure that it's being handled properly.
15
15
  unless @contents[1].nil?
16
16
  @contents[1].map do |content|
17
- DataNode.new(content, @ast_id)
17
+ DataNode.new(content, @ast_id, self)
18
18
  end
19
19
  end
20
20
  end
@@ -9,7 +9,7 @@ module Masamune
9
9
 
10
10
  def extract_data_nodes
11
11
  [
12
- DataNode.new(@contents[1], @ast_id)
12
+ DataNode.new(@contents[1], @ast_id, self)
13
13
  ]
14
14
  end
15
15
  end
@@ -17,7 +17,7 @@ module Masamune
17
17
 
18
18
  def extract_data_nodes
19
19
  [
20
- DataNode.new([contents.type, contents.token, contents.position], @ast_id)
20
+ DataNode.new([contents.type, contents.token, contents.position], @ast_id, self)
21
21
  ]
22
22
  end
23
23
  end
@@ -9,7 +9,7 @@ module Masamune
9
9
 
10
10
  def extract_data_nodes
11
11
  [
12
- DataNode.new(@contents[1], @ast_id)
12
+ DataNode.new(@contents[1], @ast_id, self)
13
13
  ]
14
14
  end
15
15
  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
@@ -14,7 +14,7 @@ module Masamune
14
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
- DataNode.new(content, @ast_id)
17
+ DataNode.new(content, @ast_id, self)
18
18
  end
19
19
  end
20
20
  end
@@ -9,7 +9,7 @@ module Masamune
9
9
 
10
10
  def extract_data_nodes
11
11
  [
12
- DataNode.new(@contents[1], @ast_id)
12
+ DataNode.new(@contents[1], @ast_id, self)
13
13
  ]
14
14
  end
15
15
  end
@@ -11,7 +11,7 @@ module Masamune
11
11
 
12
12
  def extract_data_nodes
13
13
  [
14
- DataNode.new(@contents[1], @ast_id)
14
+ DataNode.new(@contents[1], @ast_id, self)
15
15
  ]
16
16
  end
17
17
  end
@@ -9,7 +9,7 @@ module Masamune
9
9
 
10
10
  def extract_data_nodes
11
11
  [
12
- DataNode.new(@contents[1], @ast_id)
12
+ DataNode.new(@contents[1], @ast_id, self)
13
13
  ]
14
14
  end
15
15
  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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Masamune
4
- VERSION = "1.1.4"
4
+ VERSION = "1.1.5"
5
5
  end
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
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-10 00:00:00.000000000 Z
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