Posted By:
Hans_Nielsen
Posted On:
Friday, November 14, 2008 10:02 AM
This simple grammar illustrates the problem: grammar problem; start : description ' ' body; description :'des' SEP ID+; body :'body' SEP ID+; SEP : ':'; ID : 'a'..'z'; When trying to parse the following string: des:problem body:thisbodyisaproblem I get a no viable alternative exception. Apparently this happens because the string 'body', which is part of the body-rule also appears as a substring of 'thisbodyisaproblem'. As a counterexample the following string causes NO problems: des:problem body:thisisaproblem Generally the problem occurs if either 'des' or 'body' appears in the text matched by I
More>>
This simple grammar illustrates the problem:
grammar problem;
start : description ' ' body;
description :'des' SEP ID+;
body :'body' SEP ID+;
SEP : ':';
ID : 'a'..'z';
When trying to parse the following string:
des:problem body:thisbodyisaproblem
I get a no viable alternative exception. Apparently this happens because the string 'body', which is part of the body-rule also appears as a substring of 'thisbodyisaproblem'.
As a counterexample the following string causes NO problems:
des:problem body:thisisaproblem
Generally the problem occurs if either 'des' or 'body' appears in the text matched by ID+.
Why does this happen and how can I fix it?
<<Less