Skip to content

Refactor parse_args_inner to reduce nesting and complexity #9

Description

@dean0x

From: PR #feat/mds-three-enhancements (2026-05-16)
Deferred: Not modified in PR; complex refactoring of stateful character loop

Details

parse_args_inner at src/parser.rs:634-692 spans 59 lines with 4-level nesting and implements a stateful character-by-character parser:

  • String escape handling (backslash sequences)
  • Parenthesis depth tracking
  • In-string flag state
  • Argument boundary detection

Why Deferred

The refactoring is not safe as a one-pass extraction during this PR because:

  1. Changes were not made to this function in the current review
  2. Restructuring the loop requires careful state management (escape flags, depth)
  3. Extraction risk is moderate-to-high for behavioral regression
  4. Best extracted as a separate PR with targeted test coverage

Suggested Approach

  1. Extract parse_loop_state struct to hold (in_string, escape_pending, paren_depth)
  2. Extract loop body into helper function accepting mutable state
  3. Add tests for edge cases: nested parens, escaped quotes, mixed depths
  4. Consider builder pattern or state machine for clarity

Related

  • Similar pattern found in Lexer's string handling (potential shared refactoring)

Co-Authored-By: Claude noreply@anthropic.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions