Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit tables for better diagnostics #138

Open
dsyme opened this issue Dec 14, 2020 · 0 comments
Open

Emit tables for better diagnostics #138

dsyme opened this issue Dec 14, 2020 · 0 comments

Comments

@dsyme
Copy link
Contributor

dsyme commented Dec 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant