Class: Toml::Merge::FileAnalysis
- Inherits:
-
Object
- Object
- Toml::Merge::FileAnalysis
- Includes:
- Ast::Merge::FileAnalyzable
- Defined in:
- lib/toml/merge/file_analysis.rb
Overview
Analyzes TOML file structure, extracting statements for merging. This is the main analysis class that prepares TOML content for merging.
Instance Attribute Summary collapse
-
#ast ⇒ TreeHaver::Tree?
readonly
Parsed AST.
-
#errors ⇒ Array
readonly
Parse errors if any.
Instance Method Summary collapse
-
#fallthrough_node?(value) ⇒ Boolean
Override to detect tree-sitter nodes for signature generator fallthrough.
-
#initialize(source, signature_generator: nil) ⇒ FileAnalysis
constructor
Initialize file analysis.
-
#root_node ⇒ NodeWrapper?
Get the root node of the parse tree.
-
#root_pairs ⇒ Array<NodeWrapper>
Get all top-level key-value pairs (not in tables).
-
#signature_map ⇒ Hash<Array, NodeWrapper>
Get a hash mapping signatures to nodes.
-
#tables ⇒ Array<NodeWrapper>
Get all top-level tables (sections) in the TOML document.
-
#valid? ⇒ Boolean
Check if parse was successful.
Constructor Details
#initialize(source, signature_generator: nil) ⇒ FileAnalysis
Initialize file analysis
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/toml/merge/file_analysis.rb', line 25 def initialize(source, signature_generator: nil) @source = source @lines = source.lines.map(&:chomp) @signature_generator = signature_generator @errors = [] # Parse the TOML DebugLogger.time("FileAnalysis#parse_toml") { parse_toml } @statements = integrate_nodes DebugLogger.debug("FileAnalysis initialized", { signature_generator: signature_generator ? "custom" : "default", statements_count: @statements.size, valid: valid?, }) end |
Instance Attribute Details
#ast ⇒ TreeHaver::Tree? (readonly)
Returns Parsed AST.
16 17 18 |
# File 'lib/toml/merge/file_analysis.rb', line 16 def ast @ast end |
#errors ⇒ Array (readonly)
Returns Parse errors if any.
19 20 21 |
# File 'lib/toml/merge/file_analysis.rb', line 19 def errors @errors end |
Instance Method Details
#fallthrough_node?(value) ⇒ Boolean
Override to detect tree-sitter nodes for signature generator fallthrough
52 53 54 |
# File 'lib/toml/merge/file_analysis.rb', line 52 def fallthrough_node?(value) value.is_a?(NodeWrapper) || super end |
#root_node ⇒ NodeWrapper?
Get the root node of the parse tree
58 59 60 61 62 |
# File 'lib/toml/merge/file_analysis.rb', line 58 def root_node return unless valid? NodeWrapper.new(@ast.root_node, lines: @lines, source: @source) end |
#root_pairs ⇒ Array<NodeWrapper>
Get all top-level key-value pairs (not in tables)
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/toml/merge/file_analysis.rb', line 87 def root_pairs return [] unless valid? result = [] @ast.root_node.each do |child| next unless child.type.to_s == "pair" result << NodeWrapper.new(child, lines: @lines, source: @source) end result end |
#signature_map ⇒ Hash<Array, NodeWrapper>
Get a hash mapping signatures to nodes
66 67 68 |
# File 'lib/toml/merge/file_analysis.rb', line 66 def signature_map @signature_map ||= build_signature_map end |
#tables ⇒ Array<NodeWrapper>
Get all top-level tables (sections) in the TOML document
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/toml/merge/file_analysis.rb', line 72 def tables return [] unless valid? result = [] @ast.root_node.each do |child| child_type = child.type.to_s next unless %w[table array_of_tables].include?(child_type) result << NodeWrapper.new(child, lines: @lines, source: @source) end result end |
#valid? ⇒ Boolean
Check if parse was successful
45 46 47 |
# File 'lib/toml/merge/file_analysis.rb', line 45 def valid? @errors.empty? && !@ast.nil? end |