/** * Clear the DFA cache if --purge option is set. * * @param parser current SwiftParser instance */ private void clearDFACache(SwiftParser parser) { numFiles.incrementAndGet(); if (numFiles.compareAndSet(numberOfFilesBeforePurge, 0)) { parser.getInterpreter().clearDFA(); } }
/** Get all file contents into input doc list */ public static List<InputDocument> load(List<String> fileNames, LangDescriptor language) throws Exception { List<InputDocument> documents = new ArrayList<>(); for (String fileName : fileNames) { documents.add( parse(fileName, language) ); } if ( documents.size()>0 ) { documents.get(0).parser.getInterpreter().clearDFA(); // free up memory } return documents; }
public void clearDFA() { if (parser != null) parser.getInterpreter().clearDFA(); if (lexer != null) lexer.getInterpreter().clearDFA(); }
private static Translation_unitContext slowParse( InputStream inputStream, ParseTreeListener listener) throws IOException { GLSLParser parser = getParser(inputStream, listener); try { Translation_unitContext tu = parser.translation_unit(); if (parser.getNumberOfSyntaxErrors() > 0) { throw new RuntimeException("Syntax errors occurred during parsing"); } return tu; } finally { parser.getInterpreter().clearDFA(); } }
private static void modifyInterpreter(final NaturalLanguageStrategyParser p) { final int originalSize = p.getInterpreter().decisionToDFA.length; final DFA[] emptyDFA = new DFA[originalSize]; // give our own array so the static one isn't used final ParserATNSimulator newInterpreter = new ParserATNSimulator(p, p.getATN(), emptyDFA, new PredictionContextCache()); newInterpreter.clearDFA(); // initialize our array so that the parser functions properly p.setInterpreter(newInterpreter); // replace the interpreter to bypass all static caches }
private static void modifyInterpreter(final NaturalLanguageStrategyParser p) { final int originalSize = p.getInterpreter().decisionToDFA.length; final DFA[] emptyDFA = new DFA[originalSize]; // give our own array so the static one isn't used final ParserATNSimulator newInterpreter = new ParserATNSimulator(p, p.getATN(), emptyDFA, new PredictionContextCache()); newInterpreter.clearDFA(); // initialize our array so that the parser functions properly p.setInterpreter(newInterpreter); // replace the interpreter to bypass all static caches }
private static Translation_unitContext tryFastParse( InputStream inputStream, ParseTreeListener listener) throws IOException { GLSLParser parser = getParser(inputStream, listener); parser.setErrorHandler(new BailErrorStrategy()); parser.getInterpreter().setPredictionMode(PredictionMode.SLL); Translation_unitContext result = parser.translation_unit(); parser.getInterpreter().clearDFA(); return result; }