Preconditions and postconditions for operations and ErlParserRules.g [message #573582] |
Mon, 10 August 2009 21:27 |
|
Hello everyone,
I tried adding a precondition executable annotation to an operation
which I'd use as part of an EVL module, and ran into some problems.
For instance, the canonical example from the Epsilon book shows several
parsing errors:
$pre i > 0 <-- **here**
$post _result > self <- **and here**
operation Integer add(i : Integer) : Integer {
return self + i;
}
I've been poking around the grammar files and EVL files can contain
annotationBlock symbols, which are formed by one or more annotations,
which can be either Annotations (@likethis) or executableAnnotations
(the $pre and $post lines in the previous example, if I'm not mistaken).
However, Evl.g also imports the ErlParserRules.g, which define the pre
and post named blocks like this:
pre
: p='pre'^ NAME? statementBlock
{$p.setType(PRE);}
;
post
: p='post'^ NAME? statementBlock
{$p.setType(POST);}
;
I don't know much about ANTLR (I have only used JavaCC and flex/bison),
but from what I've been able to debug, it seems that the lexer processes
the 'pre' as the ERL 'pre': it goes to EvlLexer#mT__131, which contains
a 'match("pre");' line, instead of Evl_EolLexerRules#mNAME.
However, the scanner does use the executableAnnotation rule, but since
there's the wrong token in the stream, it reports a parse error.
If I change it to this, it works, but obviously they're not interpreted
as preconditions and postconditions anymore:
$Pre i > 0
$Post _result > self
operation Integer add(i : Integer) : Integer {
return self + i;
}
This also parses correctly:
pre { i > 0; }
post { _result > self; }
operation Integer add(i : Integer) : Integer {
return self + i;
}
I'm not sure how to deal with this problem. Perhaps we could change the
name for the precondition and postcondition executable annotations to
$requires and $ensures, as in JML, or simply $Pre and $Post? However,
the "$pre ..." syntax would still fail, though it's valid, according to
the documentation. :-/
Regards,
Antonio
|
|
|
Powered by
FUDForum. Page generated in 0.03845 seconds