1 from .DLVLexer
import DLVLexer
2 from .DLVParser
import DLVParser
3 from .DLVParserVisitor
import DLVParserVisitor
4 from antlr4
import PredictionMode
5 from antlr4.CommonTokenStream
import CommonTokenStream
6 from antlr4.error.ErrorListener
import ConsoleErrorListener
7 from antlr4.error.Errors
import RecognitionException
8 from antlr4.error.ErrorStrategy
import BailErrorStrategy, DefaultErrorStrategy
9 from antlr4.InputStream
import InputStream
13 def __init__(self, answerSets):
16 def visitSimpleModel(self, ctx):
19 return self.visitChildren(ctx)
21 def visitWeightedModel(self, ctx):
24 return self.visitChildren(ctx)
26 def visitWitness(self, ctx):
29 return self.visitChildren(ctx)
31 def visitCost_level(self, ctx):
33 ctx.INTEGER_CONSTANT(1).getText(),
34 ctx.INTEGER_CONSTANT(0).getText())
36 def visitPredicate(self, ctx):
40 def parse(answerSets, dlvOutput, two_stageParsing):
41 tokens = CommonTokenStream(
DLVLexer(InputStream(dlvOutput)))
45 if not two_stageParsing:
46 visitor.visit(parser.output())
50 parser._interp.predictionMode = PredictionMode.SLL
51 parser.removeErrorListeners()
52 parser._errHandler = BailErrorStrategy()
55 visitor.visit(parser.output())
56 except RuntimeError
as exception:
57 if isinstance(exception, RecognitionException):
59 parser.addErrorListener(ConsoleErrorListener.INSTANCE)
60 parser._errHandler = DefaultErrorStrategy()
61 parser._interp.predictionMode = PredictionMode.LL
62 visitor.visit(parser.output())