I have a grammar which worked already and i reactivated. Now it does not work any more. The point is two rules
parseRule
@init {
this.targets = new HashSet<Category>();
} // init
: (|->)? Name ( Trans '(' parseTargets ')' ) (->|)?
{
Category cat = new Category($Name.text);
if ($Startup.text != null) {
this.carGr.addStart(cat);
}
if ($Finish.text != null) {
this.carGr.addStop(cat);
}
this.carGr.addRule(cat, targets);
}
;
Very simple, neglecting the optional parts, i just parse a name and targets as follows:
parseTargets : (Name parseTargets?)
{System.out.println("targets: "+targets);
System.out.println("name: "+$Name.text);
if ($Name.text != null){
this.targets.add(new Category($Name.text));}};
I think, in each instance parsed, Name must be present and thus: $Name.text!=null. So I dont need the if. The truth is different. Who can explain me???