feat(joinir): Phase 171-C-2 Trim pattern detection in LoopBodyCarrierPromoter

Implements the Trim pattern detection logic for carrier promotion:

- find_definition_in_body(): Iterative AST traversal to locate variable definitions
- is_substring_method_call(): Detects substring() method calls
- extract_equality_literals(): Extracts string literals from OR chains (ch == " " || ch == "\t")
- TrimPatternInfo: Captures detected pattern details for carrier promotion

This enables Pattern 5 to detect trim-style loops:
```hako
loop(start < end) {
    local ch = s.substring(start, start+1)
    if ch == " " || ch == "\t" || ch == "\n" || ch == "\r" {
        start = start + 1
    } else {
        break
    }
}
```

Unit tests cover:
- Simple and nested definition detection
- substring method call detection
- Single and chained equality literal extraction
- Full Trim pattern detection with 2-4 whitespace characters

Next: Phase 171-C-3 integration with Pattern 2/4 routing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-07 23:09:25 +09:00
parent 907a54b55c
commit 88400e7e22
11 changed files with 2334 additions and 4668 deletions

View File

@ -758,3 +758,6 @@ pub mod condition_var_analyzer;
// Phase 170-ultrathink: Error Message Utilities
pub mod error_messages;
// Phase 171-C: LoopBodyLocal Carrier Promotion
pub mod loop_body_carrier_promoter;