1 from .DLVHEXLexer
import DLVHEXLexer
2 from .DLVHEXParser
import DLVHEXParser
3 from .DLVHEXParserVisitor
import DLVHEXParserVisitor
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 visitModel(self, ctx):
19 return self.visitChildren(ctx)
21 def visitLevel(self, ctx):
23 ctx.INTEGER(1).getText(),
24 ctx.INTEGER(0).getText())
26 def visitPredicate_atom(self, ctx):
29 def visitWitness(self, ctx):
32 return self.visitChildren(ctx)
35 def parse(answerSets, dlvhexOutput, two_stageParsing):
36 tokens = CommonTokenStream(
DLVHEXLexer(InputStream(dlvhexOutput)))
40 if not two_stageParsing:
41 visitor.visit(parser.output())
45 parser._interp.predictionMode = PredictionMode.SLL
46 parser.removeErrorListeners()
47 parser._errHandler = BailErrorStrategy()
50 visitor.visit(parser.output())
51 except RuntimeError
as exception:
52 if isinstance(exception, RecognitionException):
54 parser.addErrorListener(ConsoleErrorListener.INSTANCE)
55 parser._errHandler = DefaultErrorStrategy()
56 parser._interp.predictionMode = PredictionMode.LL
57 visitor.visit(parser.output())