liveBook · Manning

Error recovery

As explained in Building User-Friendly DSLs

A parsing technique that continues analysis after syntactic errors by resynchronizing at a later point in the input.

Error recovery lets a parser continue analyzing a textual DSL after a syntactic error. Instead of failing at the first bad character, it resynchronizes and resumes as soon as possible, preventing one mistake from invalidating the remaining content. section 15.1

This capability is essential when domain experts create or repair invalid DSL text, but useful recovery is difficult to implement without substantial parser-generator support. section 15.1

Listing 15.2 A grammar in EBNF that can parse listing 15.1
STRING: '"' [A-Za-z0-9 ]+ '"' ;            #1

type: 'amount' | 'date range' | 'percentage' ;   #2

WS: (' ' | '\t' | '\n')+ ;         #3

attributeReference: '->' WS? STRING ;

number: [0-9]+ ('.' [0-9]+)? ;

value: attributeReference | number ;

attribute: STRING WS? ':' WS? type (WS 'initially' WS? value)? ;

recordType: WS? 'record type' WS? STRING WS?
     'having attributes:' (WS? attribute)* WS? ;

Use the example EBNF grammar to see the textual structure whose errors a parser must recover from. section 15.1

How Building User-Friendly DSLs covers it

How deep it goes
Defines the recovery goal and implementation difficulty, but defers recovery algorithms and parser-engineering details.
Examples
Uses a textual Rental record grammar and the case of one wrong character corrupting DSL content.
What it assumes
Assumes basic familiarity with parsing and grammar-based DSLs while naming tokens, lexing, lookahead, and related concepts.
What you can do after
Evaluate why textual DSL parsers require recovery and why parser generators are valuable for implementing it.
How it connects
Connects error recovery with parsers, grammars, parser generators, textual DSLs, and projectional editing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.