public static LinkedListTree parseRegexpLiteral( LinkedListToken startMarker, AS3Lexer lexer, CharStream cs, LinkedListTokenStream stream) throws RecognitionException { String tail = cs.substring(cs.index(), cs.size() - 1); int initialTailLength = tail.length(); RegexSimpleParser parser; try { parser = regexpParserOn(new StringReader(tail), stream); } catch (IOException e) { // TODO: better exception type? throw new RuntimeException(e); } LinkedListTree ast = AS3FragmentParser.tree(parser.regexpLiteral()); tail = parser.getInputTail(); // skip over the regexp in the original, underlying CharStream cs.seek(cs.index() + (initialTailLength - tail.length())); LinkedListTokenSource source = (LinkedListTokenSource) stream.getTokenSource(); stream.setTokenSource(source); // cause any remembered RegexpSimple state to be dropped stream.scrub(1); // erase the subsequent token that the RegexpSimple parser got from this stream source.setDelegate(lexer); return ast; }