How to skip the incorrect token when parsing?

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Peter Luo - AIMNEXT
Version: 4.0.0285

I defined a semantic parser for a language(it looks a bit like PASCAL or VB.NET) with the grammar designer, and the "If" statement like this:
If condition Then
But if the user typed like this:
If True xxxx Then

The "xxxx" is invalid, after parsing there will be a red squiggle under the "xxxx", and the tip is "Then expected.", but the "Then" is existing.

And my grammar xml like this:
"LogicalExpression<@ out expression @><-->"
if(expression == null)
  this.ReportSyntaxError(ResourceTools.GetResourceString("Condition") + 
'THEN<- ->'
["StatementList<@ out exeStatementList @><- ->"]
Is there any way to resolve this? Or how did you resolve this problem in your VB.NET add-on?

Thanks a lot!

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Peter,

In that case I think the "Then expected." error is somewhat correct since a Then is expected where the xxxx is. Offhand I believe that is what you'd see in the VB.NET add-on language, although there we also have to handle single-line If statements so it does work out a bit different.

One thing that can help you is if you do some 'if' checks in code for the look-ahead token like with this condition:
this.TokenIs(this.LookAheadToken, VBTokenID.Then)
That will return true if the next token is a Then.

Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.