Reporting compiler like errors in the syntax editor

SyntaxEditor for WPF Forum

Posted 2 years ago by Josh
Version: 18.1.0


Take the following code:

int currentTime = clock(sec);

In our application, the clock function will return the current clock in the specified time unit as its parameter.  

Trying to use the clock function thats not nested within another statement or expression is invalid.

How can we check for this and report an error so it shows up in the syntax editor?  Should we be handling this in the grammar?  Should we be post-processing the AST?  What is the recommended way to do this?

Comments (1)

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

Hi Josh,

You would want to do that kind of checking within an IParser service for the syntax language.  Then you'd report the errors within the IParseData object passed back by the IParser.Parse method as described in this documentation topic.

If you register the language services seen in our Getting Started #5 QuickStart, that adds a tagger that will watch for parse errors and render them as squiggles.  Then another service will show quick info for the squiggles when hovered over.

I assume based on the code snippet above that you are using the C# language from our .NET Languages Add-on?  If so, you'd probably need to unregister the default CSharpParser language service, write your own IParser class that "wraps" a CSharpParser, and register that as the language's parser instead.  Your wrapper parser should call into the wrapped CSharpParser first for its IParseData results.  Then run your validation routines after by examining the AST, etc. and add any errors into that parse data or a custom implementation of IParseData.

Actipro Software Support

The latest build of this product (v24.1.2) 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.