goccmack / gocc

Parser / Scanner Generator
Other
622 stars 48 forks source link

parser: Update error-recovery mode implemented in gocc #77

Open shivansh opened 6 years ago

shivansh commented 6 years ago

The following steps are performed when an invalid input symbol is encountered -

Demo for error-recovery example

=== RUN   TestFail
input: a ; b
output: [
    a
Error in S0: INVALID(0,;), Pos(offset=2, line=1, column=3), expected one of: $ id error 
    b
]
--- PASS: TestFail (0.00s)
PASS
ok      github.com/goccmack/gocc/example/errorrecovery  0.002s
input: a ; ; b
output: [
    a
Error in S0: INVALID(0,;), Pos(offset=2, line=1, column=3), expected one of: $ id error 
    b
]
--- PASS: TestFail (0.00s)
PASS
ok      github.com/goccmack/gocc/example/errorrecovery  0.002s
input: a ; b ; c
output: [
    a
Error in S0: INVALID(0,;), Pos(offset=2, line=1, column=3), expected one of: $ id error 
    b
Error in S0: INVALID(0,;), Pos(offset=6, line=1, column=6), expected one of: $ id error 
    c
]
--- PASS: TestFail (0.00s)
PASS
ok      github.com/goccmack/gocc/example/errorrecovery  0.002s

It should be noted that there might be scope of further refactoring the code in this PR. I'll defer doing it until the proposed heuristic has been verified.

awalterschulze commented 6 years ago

Am I understanding correctly that this is an attempt to fix https://github.com/goccmack/gocc/issues/76

I wouldn't call this a heuristic, but rather just a possibly better way to do error recovery.

I am sick though, so I probably missed something.

@goccmack this is probably something worth checking out. What do you think?

shivansh commented 6 years ago

Am I understanding correctly that this is an attempt to fix #76

Yes.

I wouldn't call this a heuristic, but rather just a possibly better way to do error recovery.

oic, updating the title and PR message.

I am sick though, so I probably missed something.

Get well soon :)

goccmack commented 6 years ago

@shivansh put his finger on one of the aspects of gocc that didn't receive sufficient attention originally. If I remember correctly I tried to implement error recovery according to the dragon book "Error Recovery in LR Parsing" but under time pressure. I think @shivansh is on the right track.