def parse(actions, spdOutput, two_stageParsing): tokens = CommonTokenStream(SPDGrammarLexer(InputStream(spdOutput))) parser = SPDGrammarParser(tokens) visitor = SPDGrammarVisitorImplementation(actions) if not two_stageParsing: visitor.visit(parser.json()) return visitor._errors parser._interp.predictionMode = PredictionMode.SLL parser.removeErrorListeners() parser._errHandler = BailErrorStrategy() try: visitor.visit(parser.json()) except RuntimeError as exception: if isinstance(exception, RecognitionException): tokens.seek(0) parser.addErrorListener(ConsoleErrorListener.INSTANCE) parser._errHandler = DefaultErrorStrategy() parser._interp.predictionMode = PredictionMode.LL visitor.visit(parser.json()) return visitor._errors
def parse(atom): tokens = CommonTokenStream(ASPGrammarLexer(InputStream(atom))) parser = ASPGrammarParser(tokens) visitor = ASPParser() parser._interp.predictionMode = PredictionMode.SLL parser.removeErrorListeners() parser._errHandler = BailErrorStrategy() try: visitor.visit(parser.output()) except RuntimeError as exception: if isinstance(exception, RecognitionException): tokens.seek(0) parser.addErrorListener(ConsoleErrorListener.INSTANCE) parser._errHandler = DefaultErrorStrategy() parser._interp.predictionMode = PredictionMode.LL visitor.visit(parser.output()) return visitor
def parse(answerSets, dlvhexOutput, two_stageParsing): tokens = CommonTokenStream(DLVHEXLexer(InputStream(dlvhexOutput))) parser = DLVHEXParser(tokens) visitor = DLVHEXParserVisitorImplementation(answerSets) if not two_stageParsing: visitor.visit(parser.output()) return parser._interp.predictionMode = PredictionMode.SLL parser.removeErrorListeners() parser._errHandler = BailErrorStrategy() try: visitor.visit(parser.output()) except RuntimeError as exception: if isinstance(exception, RecognitionException): tokens.seek(0) parser.addErrorListener(ConsoleErrorListener.INSTANCE) parser._errHandler = DefaultErrorStrategy() parser._interp.predictionMode = PredictionMode.LL visitor.visit(parser.output())