Class: Bash::Merge::NodeWrapper
- Inherits:
-
Ast::Merge::NodeWrapperBase
- Object
- Ast::Merge::NodeWrapperBase
- Bash::Merge::NodeWrapper
- Defined in:
- lib/bash/merge/node_wrapper.rb
Overview
Wraps TreeHaver nodes with comment associations, line information, and signatures. This provides a unified interface for working with Bash AST nodes during merging.
Inherits common functionality from Ast::Merge::NodeWrapperBase:
-
Source context (lines, source, comments)
-
Line info extraction
-
Basic methods: #type, #type?, #text, #content, #signature
Instance Method Summary collapse
-
#case_statement? ⇒ Boolean
Check if this is a case statement.
-
#command? ⇒ Boolean
Check if this is a command.
-
#command_name ⇒ String?
Get the command name if this is a command.
-
#comment? ⇒ Boolean
Check if this is a comment.
-
#find_child_by_field(field_name) ⇒ TreeSitter::Node?
Find a child by field name.
-
#find_child_by_type(type_name) ⇒ TreeSitter::Node?
Find a child by type.
-
#for_statement? ⇒ Boolean
Check if this is a for loop.
-
#function_definition? ⇒ Boolean
Check if this is a function definition.
-
#function_name ⇒ String?
Get the function name if this is a function definition.
-
#if_statement? ⇒ Boolean
Check if this is an if statement.
-
#pipeline? ⇒ Boolean
Check if this is a pipeline.
-
#variable_assignment? ⇒ Boolean
Check if this is a variable assignment.
-
#variable_name ⇒ String?
Get the variable name if this is a variable assignment.
-
#while_statement? ⇒ Boolean
Check if this is a while loop.
Instance Method Details
#case_statement? ⇒ Boolean
Check if this is a case statement
54 55 56 |
# File 'lib/bash/merge/node_wrapper.rb', line 54 def case_statement? @node.type.to_s == "case_statement" end |
#command? ⇒ Boolean
Check if this is a command
60 61 62 |
# File 'lib/bash/merge/node_wrapper.rb', line 60 def command? @node.type.to_s == "command" end |
#command_name ⇒ String?
Get the command name if this is a command
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/bash/merge/node_wrapper.rb', line 98 def command_name return unless command? # First child that is a word or simple_expansion @node.each do |child| next if %w[comment file_redirect heredoc_redirect].include?(child.type.to_s) return node_text(child) if %w[word command_name].include?(child.type.to_s) end nil end |
#comment? ⇒ Boolean
Check if this is a comment
72 73 74 |
# File 'lib/bash/merge/node_wrapper.rb', line 72 def comment? @node.type.to_s == "comment" end |
#find_child_by_field(field_name) ⇒ TreeSitter::Node?
Find a child by field name
113 114 115 116 117 |
# File 'lib/bash/merge/node_wrapper.rb', line 113 def find_child_by_field(field_name) return unless @node.respond_to?(:child_by_field_name) @node.child_by_field_name(field_name) end |
#find_child_by_type(type_name) ⇒ TreeSitter::Node?
Find a child by type
122 123 124 125 126 127 128 129 |
# File 'lib/bash/merge/node_wrapper.rb', line 122 def find_child_by_type(type_name) return unless @node.respond_to?(:each) @node.each do |child| return child if child.type.to_s == type_name end nil end |
#for_statement? ⇒ Boolean
Check if this is a for loop
42 43 44 |
# File 'lib/bash/merge/node_wrapper.rb', line 42 def for_statement? %w[for_statement c_style_for_statement].include?(@node.type.to_s) end |
#function_definition? ⇒ Boolean
Check if this is a function definition
24 25 26 |
# File 'lib/bash/merge/node_wrapper.rb', line 24 def function_definition? @node.type.to_s == "function_definition" end |
#function_name ⇒ String?
Get the function name if this is a function definition
78 79 80 81 82 83 84 |
# File 'lib/bash/merge/node_wrapper.rb', line 78 def function_name return unless function_definition? # In bash tree-sitter, function name is in a 'name' or 'word' child name_node = find_child_by_type("word") || find_child_by_field("name") node_text(name_node) if name_node end |
#if_statement? ⇒ Boolean
Check if this is an if statement
36 37 38 |
# File 'lib/bash/merge/node_wrapper.rb', line 36 def if_statement? @node.type.to_s == "if_statement" end |
#pipeline? ⇒ Boolean
Check if this is a pipeline
66 67 68 |
# File 'lib/bash/merge/node_wrapper.rb', line 66 def pipeline? @node.type.to_s == "pipeline" end |
#variable_assignment? ⇒ Boolean
Check if this is a variable assignment
30 31 32 |
# File 'lib/bash/merge/node_wrapper.rb', line 30 def variable_assignment? @node.type.to_s == "variable_assignment" end |
#variable_name ⇒ String?
Get the variable name if this is a variable assignment
88 89 90 91 92 93 94 |
# File 'lib/bash/merge/node_wrapper.rb', line 88 def variable_name return unless variable_assignment? # In bash tree-sitter, variable name is a child of type 'variable_name' name_node = find_child_by_type("variable_name") node_text(name_node) if name_node end |
#while_statement? ⇒ Boolean
Check if this is a while loop
48 49 50 |
# File 'lib/bash/merge/node_wrapper.rb', line 48 def while_statement? @node.type.to_s == "while_statement" end |