Force an error in the OnSuccess callback

SyntaxEditor for WPF Forum

Posted 5 months ago by Bernd Timmermann - Manager, TSE GmbH
Version: 23.1.3
Avatar

The point is to mark Break as an error outside of a Breakable statement (repeat, while, for, switch, do).
Of course, you could use child states, but that leads to a lot of duplication of pattern groups, since you have to support most patterns from the default state in the new "BreakableStatements" state as well.
One idea is to have a "BreakableLevel" counter in the custom parse data, and increment it on each Breakable-Statement-Start token (in its OnSuccess-Callback), and decrement it on each Breakable-Statement-End token.
So from the custom parse data in an "OnSuccess" callback  associated with a "Break" production, I can see that the context for that statement is not correct (BreakableLevel = 0). Now I want to create a specific error like "Break not allowed outside a Breakable statement".
Unfortunately, I can't find a way to do this inside an "OnSuccess" callback.
Any idea how to force a successfully parsed statement to log an error?

thxinadv

Comments (1)

Posted 5 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The callbacks such as OnSuccess are all passed an IParserState object.  That state object has a ReportError method on it that you can pass a ParseError instance to, which will be a custom parse error.  The ParseError lets you indicate the error level, a string description, and a position (line/col) range.  The state.TokenReader has an OffsetToPosition utility method on it where you can convert integer offsets to TextPosition objects, since the parse error takes a TextPositionRange.

Similar to what you are trying to do, we use that method to report extra parse errors in our own grammars that may have required additional code-behind logic to locate.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.