masamune-ast 1.2.0 → 2.0.0

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/Gemfile.lock +5 -1
  4. data/README.md +30 -82
  5. data/lib/masamune/abstract_syntax_tree/prism/node_extensions.rb +82 -0
  6. data/lib/masamune/abstract_syntax_tree/visitors/block_parameters_visitor.rb +18 -0
  7. data/lib/masamune/abstract_syntax_tree/visitors/method_calls_visitor.rb +19 -0
  8. data/lib/masamune/abstract_syntax_tree/visitors/method_definitions_visitor.rb +17 -0
  9. data/lib/masamune/abstract_syntax_tree/visitors/parameters_visitor.rb +18 -0
  10. data/lib/masamune/abstract_syntax_tree/visitors/strings_visitor.rb +17 -0
  11. data/lib/masamune/abstract_syntax_tree/visitors/symbols_visitor.rb +17 -0
  12. data/lib/masamune/abstract_syntax_tree/visitors/variables_visitor.rb +34 -0
  13. data/lib/masamune/abstract_syntax_tree.rb +57 -151
  14. data/lib/masamune/lex_node.rb +6 -6
  15. data/lib/masamune/slasher.rb +9 -15
  16. data/lib/masamune/version.rb +1 -1
  17. data/lib/masamune.rb +10 -23
  18. metadata +26 -24
  19. data/lib/masamune/abstract_syntax_tree/data_node.rb +0 -65
  20. data/lib/masamune/abstract_syntax_tree/node.rb +0 -41
  21. data/lib/masamune/abstract_syntax_tree/nodes/assign.rb +0 -11
  22. data/lib/masamune/abstract_syntax_tree/nodes/blocks/brace_block.rb +0 -13
  23. data/lib/masamune/abstract_syntax_tree/nodes/blocks/do_block.rb +0 -13
  24. data/lib/masamune/abstract_syntax_tree/nodes/call.rb +0 -17
  25. data/lib/masamune/abstract_syntax_tree/nodes/command.rb +0 -64
  26. data/lib/masamune/abstract_syntax_tree/nodes/def.rb +0 -17
  27. data/lib/masamune/abstract_syntax_tree/nodes/params.rb +0 -23
  28. data/lib/masamune/abstract_syntax_tree/nodes/program.rb +0 -16
  29. data/lib/masamune/abstract_syntax_tree/nodes/string_content.rb +0 -17
  30. data/lib/masamune/abstract_syntax_tree/nodes/support_nodes/block.rb +0 -18
  31. data/lib/masamune/abstract_syntax_tree/nodes/support_nodes/comment.rb +0 -25
  32. data/lib/masamune/abstract_syntax_tree/nodes/symbol.rb +0 -17
  33. data/lib/masamune/abstract_syntax_tree/nodes/symbols/dyna_symbol.rb +0 -20
  34. data/lib/masamune/abstract_syntax_tree/nodes/symbols/symbol_literal.rb +0 -21
  35. data/lib/masamune/abstract_syntax_tree/nodes/variables/block_var.rb +0 -22
  36. data/lib/masamune/abstract_syntax_tree/nodes/variables/var_field.rb +0 -17
  37. data/lib/masamune/abstract_syntax_tree/nodes/variables/var_ref.rb +0 -19
  38. data/lib/masamune/abstract_syntax_tree/nodes/vcall.rb +0 -17
@@ -1,64 +0,0 @@
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,17 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class Def < Node
6
- def initialize(contents, ast_id)
7
- super
8
- end
9
-
10
- def extract_data_nodes
11
- [
12
- DataNode.new(@contents[1], @ast_id, self)
13
- ]
14
- end
15
- end
16
- end
17
- end
@@ -1,23 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class Params < Node
6
- def initialize(contents, ast_id)
7
- super
8
- end
9
-
10
- def extract_data_nodes
11
- # TODO: Sometimes the params node looks like this:
12
- # [:params, nil, nil, nil, nil, nil, nil, nil]
13
- # Add a description for this, and review this portion
14
- # to ensure that it's being handled properly.
15
- unless @contents[1].nil?
16
- @contents[1].map do |content|
17
- DataNode.new(content, @ast_id, self)
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,16 +0,0 @@
1
- # Program represents the top layer of the abstract syntax tree,
2
- # and the second element of the array houses the entire program.
3
-
4
- module Masamune
5
- class AbstractSyntaxTree
6
- class Program < Node
7
- def initialize(contents, ast_id)
8
- super
9
- end
10
-
11
- def extract_data_nodes
12
- # No data nodes to extract.
13
- end
14
- end
15
- end
16
- end
@@ -1,17 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class StringContent < Node
6
- def initialize(contents, ast_id)
7
- super
8
- end
9
-
10
- def extract_data_nodes
11
- [
12
- DataNode.new(@contents[1], @ast_id, self)
13
- ]
14
- end
15
- end
16
- end
17
- end
@@ -1,18 +0,0 @@
1
- # DoBlock and BraceBlock share some of
2
- # the same logic, so we share that here.
3
-
4
- module Masamune
5
- class AbstractSyntaxTree
6
- class Block < Node
7
- def initialize(contents, ast_id)
8
- super
9
- end
10
-
11
- def params
12
- # This node should exist already, so we search for it in the ast object.
13
- block_var = BlockVar.new(contents[1], ast_id)
14
- ast.node_list.find {|node| node.contents == block_var.contents}
15
- end
16
- end
17
- end
18
- end
@@ -1,25 +0,0 @@
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
@@ -1,17 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class Symbol < Node
6
- def initialize(contents, ast_id)
7
- super
8
- end
9
-
10
- def extract_data_nodes
11
- [
12
- DataNode.new(@contents[1], @ast_id, self)
13
- ]
14
- end
15
- end
16
- end
17
- end
@@ -1,20 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class DynaSymbol < Node
6
- def initialize(contents, ast_id)
7
- super
8
- end
9
-
10
- # Dyna Symbols are symbols created from strings, i.e. - :"project".
11
- # Since they have :@tstring_content inside of them, the data node
12
- # is technically for a String, so instead of duplicating it here,
13
- # we just use a method specifically for getting the symbol.
14
- # This should be the same as the :symbol_literal type.
15
- def get_symbol_data
16
- DataNode.new(@contents[1][1], @ast_id, self)
17
- end
18
- end
19
- end
20
- end
@@ -1,21 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class SymbolLiteral < Node
6
- def initialize(contents, ast_id)
7
- super
8
- end
9
-
10
- # Symbol Literals are a node type of :symbol_literal,
11
- # but have a node type of :symbol nested within them.
12
- # For the reason, the data node is technically for :symbol
13
- # and not :symbol_literal, so instead of duplicating it here,
14
- # we just use a method specifically for getting the symbol.
15
- # This should be the same as the :dyna_symbol type.
16
- def get_symbol_data
17
- DataNode.new(@contents[1][1], @ast_id, self)
18
- end
19
- end
20
- end
21
- end
@@ -1,22 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class BlockVar < Node
6
- attr_accessor :ast_id
7
-
8
- def initialize(contents, ast_id)
9
- super
10
- end
11
-
12
- # :block_var has a lot of nil values within in.
13
- # I'm not sure what this represents, but it would be
14
- # nice to find out and document/implement it somewhere.
15
- def extract_data_nodes
16
- @contents[1][1].map do |content|
17
- DataNode.new(content, @ast_id, self)
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class VarField < Node
6
- def initialize(contents, ast_id)
7
- super
8
- end
9
-
10
- def extract_data_nodes
11
- [
12
- DataNode.new(@contents[1], @ast_id, self)
13
- ]
14
- end
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class VarRef < Node
6
- attr_accessor :ast_id
7
-
8
- def initialize(contents, ast_id)
9
- super
10
- end
11
-
12
- def extract_data_nodes
13
- [
14
- DataNode.new(@contents[1], @ast_id, self)
15
- ]
16
- end
17
- end
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- # TODO: Add description.
2
-
3
- module Masamune
4
- class AbstractSyntaxTree
5
- class Vcall < Node
6
- def initialize(contents, ast_id)
7
- super
8
- end
9
-
10
- def extract_data_nodes
11
- [
12
- DataNode.new(@contents[1], @ast_id, self)
13
- ]
14
- end
15
- end
16
- end
17
- end