> line 1:8 extraneous input '<' expecting {HIALPHA, LOALPHA}
> line 1:12 mismatched input '<EOF>' expecting '<'
>
> ## enter name: <foo
>
> for the input
>
> keyword <foo
Which is correct since '<' is not valid after 'keyword'.
>
> while I would have expected this 'name' rule never to have be called since '<' is not part of valid characters for 'name' rule. Is there something wrong in my grammar or is this a bug in Antlr?
Imagine how the parser works. After matching 'keyword' it continued with the next expected input, which is the name rule, so it entered it, which is why your enterName function has been called. At this point it's not clear yet if that rule matches or not. Which is why I prefer to implement the exit* variants instead. Using enter* is probably more useful if you need to set up something that gets modified during the match process in that particular rule (or subsequent rules called by it).
I don't know however why the context gives you '<foo' as text. In fact, it shouldn't have any text yet as we just entered the name rule and the context has just been freshly created without any further updates. The text for a context is created by concatenating all text from its children separated by comma. On enter however there shouldn't be any children yet. If you can step through the ANTLR runtime I'd recommend to do so to see from which context this text actually comes from.
Mike
--
www.soft-gems.net