Class: Tryouts::LegacyParser
- Inherits:
-
Parsers::BaseParser
- Object
- Parsers::BaseParser
- Tryouts::LegacyParser
- Defined in:
- lib/tryouts/parsers/legacy_parser.rb
Overview
Legacy parser using line-by-line regex parsing for compatibility
The LegacyParser provides a simpler, more straightforward approach to parsing tryout files using sequential line-by-line processing with pattern matching. While less sophisticated than the EnhancedParser, it offers predictable behavior and serves as a fallback option for edge cases.
## Characteristics
### 1. Simple Line-by-Line Processing
-
Processes each line sequentially with pattern matching
-
Straightforward regex-based approach
-
Easy to understand and debug parsing logic
### 2. Pattern Matching Classification
-
Uses Ruby 3.4+ pattern matching (
case/in) for token classification -
Modern syntax while maintaining simple parsing approach
-
Consistent with EnhancedParser’s classification logic
### 3. Compatibility Focus
-
Maintains backward compatibility with older tryout files
-
Provides fallback parsing when EnhancedParser encounters issues
-
Useful for debugging parser-specific problems
## Limitations
### 1. HEREDOC Vulnerability
-
Cannot distinguish between real comments and content inside HEREDOCs
-
May incorrectly parse string content as tryout syntax
-
Requires careful handling of complex Ruby syntax
### 2. Limited Inline Comment Support
-
Basic handling of lines with both code and comments
-
Less sophisticated than EnhancedParser’s multi-comment support
## When to Use
-
Debugging: When EnhancedParser produces unexpected results
-
Compatibility: With older Ruby versions or edge cases
-
Simplicity: When predictable line-by-line behavior is preferred
-
Fallback: As a secondary parsing option
Instance Attribute Summary
Attributes inherited from Parsers::BaseParser
Instance Method Summary collapse
-
#parse ⇒ Tryouts::Testrun
Parse source code into a Testrun using line-by-line processing.
Methods inherited from Parsers::BaseParser
Methods included from Parsers::SharedMethods
#add_context_to_block, #add_warning, #block_has_content?, #build_setup, #build_teardown, #build_test_case, #calculate_block_range, #calculate_end_line, #classify_blocks, #classify_potential_descriptions_with_boundaries, #collect_unnamed_test_warning, #extract_code_content, #extract_pure_code_from_blocks, #find_test_case_boundaries, #find_test_case_end, #group_into_test_blocks, #handle_syntax_errors, #has_following_test_pattern?, #is_expectation_type?, #new_test_block, #parse_expectation, #parse_ruby_line, #process_test_blocks, #validate_strict_mode, #warnings
Constructor Details
This class inherits a constructor from Tryouts::Parsers::BaseParser
Instance Method Details
#parse ⇒ Tryouts::Testrun
Parse source code into a Testrun using line-by-line processing
This method provides sequential line-by-line parsing that processes each line with pattern matching to classify tokens. While simpler than EnhancedParser, it may be vulnerable to HEREDOC content parsing issues.
76 77 78 79 80 81 82 83 84 |
# File 'lib/tryouts/parsers/legacy_parser.rb', line 76 def parse return handle_syntax_errors if @prism_result.failure? tokens = tokenize_content test_boundaries = find_test_case_boundaries(tokens) tokens = classify_potential_descriptions_with_boundaries(tokens, test_boundaries) test_blocks = group_into_test_blocks(tokens) process_test_blocks(test_blocks) end |