1 package it.unical.mat.parsers.asp.dlvhex;
3 import it.unical.mat.parsers.asp.ASPDataCollection;
4 import org.antlr.v4.runtime.BailErrorStrategy;
5 import org.antlr.v4.runtime.CharStreams;
6 import org.antlr.v4.runtime.CommonTokenStream;
7 import org.antlr.v4.runtime.ConsoleErrorListener;
8 import org.antlr.v4.runtime.DefaultErrorStrategy;
9 import org.antlr.v4.runtime.RecognitionException;
10 import org.antlr.v4.runtime.atn.PredictionMode;
16 this.answerSets = answerSets;
21 answerSets.addAnswerSet();
23 return visitChildren(ctx);
28 answerSets.storeCost(Integer.parseInt(ctx.INTEGER(1).getText()), Integer.parseInt(ctx.INTEGER(0).getText()));
35 answerSets.storeAtom(ctx.getText());
42 answerSets.addAnswerSet();
44 return visitChildren(ctx);
47 public static void parse(
final ASPDataCollection answerSets,
final String atomsList,
final boolean two_stageParsing) {
48 final CommonTokenStream tokens =
new CommonTokenStream(
new DLVHEXLexer(CharStreams.fromString(atomsList)));
52 if(!two_stageParsing) {
53 visitor.visit(parser.output());
58 parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
59 parser.removeErrorListeners();
60 parser.setErrorHandler(
new BailErrorStrategy());
63 visitor.visit(parser.output());
64 }
catch (
final RuntimeException exception) {
65 if(exception.getClass() == RuntimeException.class && exception.getCause() instanceof RecognitionException) {
67 parser.addErrorListener(ConsoleErrorListener.INSTANCE);
68 parser.setErrorHandler(
new DefaultErrorStrategy());
69 parser.getInterpreter().setPredictionMode(PredictionMode.LL);
70 visitor.visit(parser.output());