Try this
(
<AT>
{ axis = Axis.attribute; }
|
LOOKAHEAD( <IDENTIFIER> <DOUBLE_COLON> )
t = <IDENTIFIER>
{ axis = Axis.valueOf(t.image); }
<DOUBLE_COLON>
|
{}
)
--Edit--
I'd forgotten to answer the second question: "Why doesn't the given snippet work?"
The look ahead spec that you have only applies to the alternation. I'm suprised JavaCC doesn't give you a warning, as the LOOKAHEAD is on the last alternative and hence useless. By the time the parser gets to the LOOKAHEAD, it has already decided (on the basis of the next token being an identifier) to process the part inside the (...)?
Another solution is thus
( LOOKAHEAD( <AT> | <IDENTIFIER> <DOUBLE_COLON> )
(<AT> {...} | <IDENTIFIER> {...} <DOUBLE_COLON> )
)?