The parser that makes no progress
A successful tokenizer rule can repeatedly emit a token without consuming any input.
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
[{"text":"x","rules":[{"prefix":"x","consume":0,"token":"word"}]}][{"status":"stalled","offset":0,"tokens":[]}][{"text":"abc","rules":[{"prefix":"ab","consume":2,"token":"pair"}]}][{"status":"ok","offset":3,"tokens":["pair","c"]}][{"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.
Read the report, then sign in to start your investigation.