Using Dotstar · Part 6

The debugger

When a pattern matches something unexpected, or takes too long, the Debug tab shows what the engine does, step by step.

The debugger halfway through a match of (\w+\s?)+, with the warning that it can backtrack catastrophically.

Stepping

The slider and the arrows (← and → with the tab focused) go through the steps. At each one, the part of the pattern being tried and the place in the text are marked, and the step says what happened: a part matched and the engine moved on, or it failed and the engine went back to an earlier choice to try another. That going back is backtracking, explained in the lesson on it.

Where the steps go

The debugger counts the steps each part of the pattern takes. A part that takes most of them is where to look: a nested repetition like (\w+\s?)+, or a .* that runs to the end and gives back character by character.

A pattern that can backtrack catastrophically is underlined in the pattern field too, with why, and a safer form one click away where there is one. The debugger shows why it’s slow; the underline, before it gets that far.

Which engines

The debugger steps through JavaScript’s engine for now. For other flavors, the explanation, the tests and Compare still work, and a pattern that runs away in any engine is stopped and reported.