Skip one line parser error

SyntaxEditor for WPF Forum

Posted 7 years ago by bean
Version: 17.2.0661


As I konw if I don't use OnError methods to handle parser error, the content after the error postion will not be parsed.

But for my scenario, each line of the content interdepend to other lines. Which means if one line has parse error it should not impact other lines, therefore the rest lines should be parsed normally/correctly.

I konw if I handled the errors of a line using OnError methods it will fix the issue, but problem is I can't cover all the error cases.

So is there a solution for my case? Thanks!

Comments (3)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA


In the main non-terminal where you have a loop of parsing single lines, you could do something like this:

compilationUnit.Production = singleLine.OnError(ErrorCompilationUnit).ZeroOrMore().SetLabel("c") + @documentEnd.OnErrorContinue();


private IParserErrorResult ErrorCompilationUnit(IParserState state) {
	// Advance to the start of the next line
	if (state.TokenReader.AdvanceTo(tokenId.LineTerminator))
	return ParserErrorResults.Continue;

That would effectively capture any errors that bubbled up to that point from a singleLine non-terminal, and would advance to the start of the next line, allowing it to continue on as if nothing happened, while still reporting the original error.  The "tokenId.LineTerminator" would need to be the token ID for your language's line terminator.

Actipro Software Support

Posted 7 years ago by bean

Hi, thank you.

My issue is children's errors doesn't bubble up to singleLine non-terminal. What condition will cause this?

Sorry I can't provide my code snippets for some reason for now.

For your refer, I used type-specific AST node for the children A, error on A will be caught by its OnError method, but no upper non-terminal of A could catch the error if I don't handle error on A. 

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA

The errors should bubble up ok, unless you have some error handler (like an OnError handler) that occurs in between where the error happened and the singleLine non-terminal.  Without a simple example to see and debug with, it's hard to say what's going on in your scenario though.

My best advice if you can't give a sample would be to look at our "SyntaxEditor / LL(*) Parser Framework / Callbacks and Error Handling" topic in the documentation that comes with the product.  That walks through in detail how error handling works and gives a number of best practices at the end of the topic.  In addition, you can look at our Getting Started #4d QuickStart to see those best practices in action.

Actipro Software Support

The latest build of this product (v24.1.2) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.