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).
Attributes included from FileAnalyzable
#freeze_token, #lines, #signature_generator, #source
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
44 45 46 47 48 49 50 51 52 |
# File 'lib/ast/merge/text/file_analysis.rb', line 44 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)
57 58 59 |
# File 'lib/ast/merge/text/file_analysis.rb', line 57 def statements @statements end |
Instance Method Details
#compute_node_signature(node) ⇒ Array?
Compute signature for a node
63 64 65 66 67 68 69 70 |
# File 'lib/ast/merge/text/file_analysis.rb', line 63 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
76 77 78 |
# File 'lib/ast/merge/text/file_analysis.rb', line 76 def fallthrough_node?(value) value.is_a?(LineNode) || value.is_a?(FreezeNodeBase) || super end |