
Hi,
I have a language that supports function definitions like:
function f
{
}
or
function f
begin
end
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);
curlyBraceBlock.Production
= openCurlyBrace + statement.ZeroOrMore() + closeCurlyBrace.OnErrorContinue();
beginEndBlock.Production
= 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