Implement ogex explain Command to Visualize Matching Process #20

Closed
opened 2026-03-11 18:14:55 +03:00 by NiXTheDev · 0 comments
NiXTheDev commented 2026-03-11 18:14:55 +03:00 (Migrated from github.com)

Goal: Provide a debugging tool for users to understand how their regex matches (or fails to match) a given input.

Add a new CLI subcommand ogex explain <pattern> <input> that shows step-by-step how the engine processes the input, including:

  • Current position, current NFA states.
  • Which transitions are taken.
  • Capture group updates.
  • Backreference matching attempts.
  • Final match result.

Implementation Idea:

  • Add a "debug mode" to NfaSimulator that logs events.
  • In engine.rs, conditionally compile logging when a feature flag is enabled.
  • In the CLI, parse the explain command, enable debug mode, and print a nicely formatted trace.

Example Output:

Step 0: pos=0, states=[0]
epsilon closure -> [0,1,2]
Step 1: read 'a' at pos=0
state 2 matches 'a' -> state 3
...
Match found at pos=3
**Goal**: Provide a debugging tool for users to understand how their regex matches (or fails to match) a given input. Add a new CLI subcommand `ogex explain <pattern> <input>` that shows step-by-step how the engine processes the input, including: - Current position, current NFA states. - Which transitions are taken. - Capture group updates. - Backreference matching attempts. - Final match result. **Implementation Idea**: - Add a "debug mode" to `NfaSimulator` that logs events. - In `engine.rs`, conditionally compile logging when a feature flag is enabled. - In the CLI, parse the explain command, enable debug mode, and print a nicely formatted trace. **Example Output**: ``` Step 0: pos=0, states=[0] epsilon closure -> [0,1,2] Step 1: read 'a' at pos=0 state 2 matches 'a' -> state 3 ... Match found at pos=3 ```
Sign in to join this conversation.
No description provided.