bugger.
All challenges/JavaScriptmediumthe-parser-that-makes-no-progress-v1
THE INVESTIGATION

The parser that makes no progress

A successful tokenizer rule can repeatedly emit a token without consuming any input.

Real incidentsParser progressRegression testing

What’s going wrong

Input is an array of at most 100 {text, rules} rows. text contains at most 80 ASCII characters. rules is an ordered array of at most 10 {prefix, consume, token} objects: prefix is a nonempty ASCII string, consume is an integer from 0 to prefix.length, and token is an ASCII string. At each offset choose the FIRST rule whose prefix matches the remaining text; a positive consume advances exactly that many characters and emits token. With no matching rule consume one character and emit that character. A chosen zero-consumption rule is an error: return {status: "stalled", offset, tokens} immediately WITHOUT emitting its token. Reaching the end returns status "ok". Never treat a repeated emitted token as a stall if input advances. The starter includes a finite diagnostic step budget solely to keep a broken parser bounded.

Expected behavior

Detect successful parsing steps that consume no input.

Reproduction

01 Zero-length success stalls immediately
[{"text":"x","rules":[{"prefix":"x","consume":0,"token":"word"}]}]
[{"status":"stalled","offset":0,"tokens":[]}]
02 Ordinary token control
[{"text":"abc","rules":[{"prefix":"ab","consume":2,"token":"pair"}]}]
[{"status":"ok","offset":3,"tokens":["pair","c"]}]
03 No extension rules control
[{"text":"ab","rules":[]}]
[{"status":"ok","offset":2,"tokens":["a","b"]}]

Before you begin

  • JavaScript loops and ordered matching
  • Parser state and termination invariants

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.