FsLexYacc
FsLexYacc copied to clipboard
Emit tables for better diagnostics
The parsers we generate already have some tables for auto-generation of diagnostics
We should extend this to allow better diagnosis of error recovery situations.
Currently for a grammar like this:
nonterm1:
| tok1 { } // ProdIdx 1
| tok1 nonterm { } // ProdIdx 2
| tok2 nonterm { } // ProdIdx 3
nonterm2:
| tok1 nonterm { } // ProdIdx 4
| tok2 nonterm { } // ProdIdx 5
The parse will generate states something like this:
state 300:
nonterm1: . tok1
nonterm1: . tok1 nonterm
state 301:
nonterm1: tok1 .
nonterm1: tok1 . nonterm
etc and we emit tables that contain this kind of information:
State --> ProdIdx list ( 300 --> [1; 2], 301 --> [1,2], ....)
ProdIdx --> NonTerm (1 --> nonterm1, 2 --> nonterm1, ...)
For diagnostics we really want textual representations of the states and productions, e.g. tables for:
ProdIdx --> text
1 --> "tok1 nonterm (line 506 ilpars.fsy)"
State --> text
301 -->
"nonterm1: . tok1 (rule at line 506 ilpars.fsy)
nonterm1: . tok1 nonterm (rule at line 507 ilpars.fsy)"
302 -->
"nonterm1: tok1 . (rule at line 506 ilpars.fsy)
nonterm1: tok1 . nonterm (rule at line 507 ilpars.fsy)"
etc.
This information should probably just always be emitted by default - the slight increase in size is of no great concern in modern situations