Error reporting question for blocks

SyntaxEditor for WPF Forum

Posted 2 years ago by Scott Haney
Version: 18.1.0671


I have a language that supports function definitions like:

function f


function f

There can be zero or more statements in the block delimited by either curly braces or begin/end.

My question concerns the error that is reported if one, say, omits the close curly for the block. Right now, the parser puts a squiggle directly after the function name f and presents the error "Function definition expected." This isn't wrong, but I would prefer the squiggle to go after the open curly and the error to be "'}' expected.

The grammar is pretty much what one would expect:

functionDeclaration.Production = function + identifier + block;

block.Production = (curlyBraceBlock | beginEndBlock);

    = openCurlyBrace + statement.ZeroOrMore() + closeCurlyBrace.OnErrorContinue();

    = begin + statement.ZeroOrMore() + end.OnErrorContinue();

This gives the behavior I described above. However, I write the function declaration production as follows

functionDefinition.Production = function + identifier + curlyBraceBlack;

then I do get the desired error, but I am not supporting the begin/end construct. Can you suggest an approach for supporting the two block variants and getting the error to reference the missing curly (or end)?

Thanks in advance,

Scott Haney

Comments (2)

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

Hi Scott,

Nothing stands out as being wrong with what you have above.  That is, assuming you don't have other things like can-match callbacks, etc. in play here.  Unless I'm missing something, I would expect the first code snippet and the second's error report to be the same for the same document text.

As a first step, you could try using our Language Designer app's LL Parser Debugger to step through the grammar.  That should help you see what's going on a bit better.  

If that doesn't help, please make a new simple sample project that shows this and email it to our support address, referencing this thread in your e-mail.  Then we'll take a look and debug it.  Be sure to exclude any bin/obj folders that are in the ZIP, and rename the .zip file extension so it doesn't get spam blocked.  Thanks!

Actipro Software Support

Posted 2 years ago by Scott Haney

Since you didn't see anything obvious, I looked deeper and found that a can-match callback used to disambiguate between a curly brace block and an operation on a list (e.g. {3, 1, 2}.Sort()) was returning false for an unbalanced close curly brace. Changing the return value to true enables the OnErrorContinue() to work as desired.

The usual cautionary tale about simplifying examples...

Thanks for your reply and your offer to debug. Great support as always.

The latest build of this product (v2019.1 build 0686) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.