-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Error recovery ideas #342
Comments
Could you provide an example that enables external contributors to attempt implementing it? |
I would love to, but I'm not sure myself! If you have any ideas, please add them here. |
My current thoughts though, are that you might need something like Here's a hypothetical partial language: type Decls struct {
Func *FuncDecl `@@*`
}
type FuncDecl struct {
Name string `"func" @Ident "{"`
Statements []*Stmt `@@* "}"`
}
type Stmt struct {
If *IfStmt ` "if" @@`
For *ForStmt `| "for" @@`
Switch *SwitchStmt `| "switch" @@`
}
var parser = participle.MustBuild[Decls](
participle.RecoverTo(&FuncDecl{}, &Stmt{}),
) ... though having now written this out I wonder if there could be a recovery heuristic used here to do this automatically. Something like "recover to literals from the nearest ancestral disjunction, and repeat" |
Absence of fault-tolerant parsing is the only reason I might have to stop using participle (which is otherwise awesome!) |
Implement a
RecoverToNext(token...string)
option that allows resumption from synchronisation tokens. eg. a language might choose statement keywords likeif
,while
, etc. as synchronisation tokens.Edit: it might be better to specify a list of nodes to recover to, or generate a mapping of token value to node. The parser would then traverse up from the failing node to the nearest recovery node and attempt to match the token for that node. eg.
if
,while
, etc. might map to theStatement
node.The text was updated successfully, but these errors were encountered: