Class: Ast::Merge::Text::FileAnalysis
- Inherits:
-
Object
- Object
- Ast::Merge::Text::FileAnalysis
- Includes:
- FileAnalyzable
- Defined in:
- lib/ast/merge/text/file_analysis.rb
Overview
Text file analysis class for the text-based AST.
This class parses plain text files into a simple AST structure where:
- Top-level nodes are LineNodes (one per line)
- Nested nodes are WordNodes (words within each line, split on word boundaries)
This provides a minimal AST implementation that can be used to test
the merge infrastructure with any text-based content.
Constant Summary collapse
- DEFAULT_FREEZE_TOKEN =
Default freeze token for text files
"text-merge"
Instance Attribute Summary collapse
-
#statements ⇒ Array<LineNode, FreezeNodeBase>
readonly
Get all top-level statements (LineNodes and FreezeNodes).
Instance Method Summary collapse
-
#compute_node_signature(node) ⇒ Array?
Compute signature for a node.
-
#fallthrough_node?(value) ⇒ Boolean
Check if a value is a fallthrough node.
-
#initialize(source, freeze_token: DEFAULT_FREEZE_TOKEN, signature_generator: nil) ⇒ FileAnalysis
constructor
Initialize a new FileAnalysis.
Methods included from FileAnalyzable
#freeze_block_at, #freeze_blocks, #generate_signature, #in_freeze_block?, included, #line_at, #normalized_line, #signature_at
Constructor Details
#initialize(source, freeze_token: DEFAULT_FREEZE_TOKEN, signature_generator: nil) ⇒ FileAnalysis
Initialize a new FileAnalysis
41 42 43 44 45 46 47 48 49 |
# File 'lib/ast/merge/text/file_analysis.rb', line 41 def initialize(source, freeze_token: DEFAULT_FREEZE_TOKEN, signature_generator: nil) @source = source # Split preserving empty lines, but remove trailing empty line from final newline @lines = source.split("\n", -1) @lines.pop if @lines.last&.empty? && source.end_with?("\n") @freeze_token = freeze_token @signature_generator = signature_generator @statements = parse_statements end |
Instance Attribute Details
#statements ⇒ Array<LineNode, FreezeNodeBase> (readonly)
Get all top-level statements (LineNodes and FreezeNodes)
54 55 56 |
# File 'lib/ast/merge/text/file_analysis.rb', line 54 def statements @statements end |
Instance Method Details
#compute_node_signature(node) ⇒ Array?
Compute signature for a node
60 61 62 63 64 65 66 67 |
# File 'lib/ast/merge/text/file_analysis.rb', line 60 def compute_node_signature(node) case node when LineNode node.signature when FreezeNodeBase [:freeze_block, node.start_line, node.end_line] end end |
#fallthrough_node?(value) ⇒ Boolean
Check if a value is a fallthrough node
73 74 75 |
# File 'lib/ast/merge/text/file_analysis.rb', line 73 def fallthrough_node?(value) value.is_a?(LineNode) || value.is_a?(FreezeNodeBase) || super end |