Problem Creating Grammar

SyntaxEditor for WPF Forum

Posted 11 years ago by Ryan Howard
Version: 12.2.0573
Avatar

Hi,

I'm trying to create some editor error syntax highlighting, however I'm running into an issue with what it is and isn't catching.

I simplified it way down, and just have a sample below, I'm hoping this will resolve some of my other small syntax issues I'm seeing (there's some obvious stuff I left out): 

var @select = new Terminal(SOQLTokenId.SelectTrigger, "SELECT") { ErrorAlias = "'SELECT'" };
var @semiColon = new Terminal(SOQLTokenId.SemiColon, "SemiColon") { ErrorAlias = "';'" };

var statement = new NonTerminal("Statement");

this.Root = new NonTerminal("CompilationUnit");

statement.CanMatchCallback = CanAlwaysMatch;
Root.Production = statement.ZeroOrMore();

statement.Production = @select + @select; //doesn't work
//statement.Production = @select + @semiColon; //works perfectly

 Using the first version of the setting on "statement", I type "select select" and get the squiggly line error and it doesn't work at all (displaying the error "'SELECT'" expected. Using the second version of the setting on "statement", I type "select;" and it works perfectly.

Is it not possible to have two Terminals back-to-back of each other? I realize that anyone will probably just suggest using doing something like @select.ZeroOrMore, however this seems to relate back to some other problems I'm having that I need to understand. Primarily that it doesn't seem to be able to differentiate from an identifier and a standard terminal(like @select).

 

Thanks,

Ryan

Comments (2)

Answer - Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ryan,

That should work fine assuming your token reader is filtering out whitespace tokens.  You can look at our Simple language for an example of that.  We basically block the parser from receiving whitespace tokens there.

My guess is that you are allowing the parser to see them and it fails on the space since your grammar says it wants a SELECT next.

This sort of thing you can also determine pretty easily if you use the Language Designer app and load up your grammar in the debugger.  Since there you can see which token it's on, which tokens are expected next, etc.


Actipro Software Support

Posted 11 years ago by Ryan Howard
Avatar

Sweet! That was exactly the problem, I wired up a parser that doesn't receive whitespace and it's working now. Thanks.

 

-Ryan

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

Add Comment

Please log in to a validated account to post comments.