I use ANTLR in the Eclipse environment.
I want to pass an attribute (n.text
) to another rule (description
) and also use a semantic predicate in the latter rule to validate the input in relation to n.text
. Here is my code:
useCaseSpecification
: n=useCase '='
description[$n.text]
;
useCase
: ucID=('UC' INTEGER)? ucName
;
ucName
: caren io
;
caren
: 'create' | 'creates' | alter | read | 'erase' | 'erases' | notify
;
/* ..more code */
description[String str]
: 'Description' ':' primaryActor (useCase {str==$useCase.text}?) /* more grammar */
;
I tried many alternatives for the semantic predicate expression, such as {str.equals($useCase.text)}
, but nothing. It seems that the parser does not make the validation.
When I run the interpreter with an example, it allows every input of useCase type. For example, if the input is:
create a Prescription = Description: a doctor create a Prescription /* ... */
that should be correct.
If the input, is:
create a Prescription = Description: a doctor create a Rrrrescription /* ... */
that should be wrong.