public static ParsingResult parseText(Grammar g, LexerGrammar lg, String startRuleName, final VirtualFile grammarFile, String inputText) throws IOException { ANTLRInputStream input = new ANTLRInputStream(inputText); LexerInterpreter lexEngine; lexEngine = lg.createLexerInterpreter(input); SyntaxErrorListener syntaxErrorListener = new SyntaxErrorListener(); lexEngine.removeErrorListeners(); lexEngine.addErrorListener(syntaxErrorListener); CommonTokenStream tokens = new TokenStreamSubset(lexEngine); return parseText(g, lg, startRuleName, grammarFile, syntaxErrorListener, tokens, 0); }
public LexerInterpreter createLexerInterpreter(CharStream input) { if (this.isParser()) { throw new IllegalStateException("A lexer interpreter can only be created for a lexer or combined grammar."); } if (this.isCombined()) { return implicitLexer.createLexerInterpreter(input); } char[] serializedAtn = ATNSerializer.getSerializedAsChars(atn); ATN deserialized = new ATNDeserializer().deserialize(serializedAtn); return new LexerInterpreter(fileName, getVocabulary(), Arrays.asList(getRuleNames()), ((LexerGrammar)this).modes.keySet(), deserialized, input); }