Skip to content
Snippets Groups Projects
Commit 6aaa5dd5 authored by dgelessus's avatar dgelessus
Browse files

Use ProBResultParser from answerparser library instead of own version

parent b772f9e3
No related branches found
No related tags found
No related merge requests found
Pipeline #122223 passed
......@@ -10,7 +10,6 @@ import java.util.List;
import de.prob.cli.CliException;
import de.prob.core.command.CommandException;
import de.prob.core.internal.ResultParserException;
import de.prob.logging.Logger;
public class ProblemHandler {
......@@ -113,26 +112,4 @@ public class ProblemHandler {
Logger.notifyUser(message, t);
throw new CliException(message, t, true);
}
/**
*
* Notifies the User about a fatal problem by adding a
* {@link Logger#FATALERROR} to the log. This method takes a message
* describing the problem and the causing exception.
*
* Note: Calling this method logs the problem and throws a CliException that
* wraps the original problem
*
* @param message
* Description of the problem
* @param throwable
* Causing exception
* @throws ResultParserException
*/
public static void handleResultPareserException(final String message,
final Throwable t) throws ResultParserException {
Logger.notifyUser(message, t);
throw new ResultParserException(message, t);
}
}
......@@ -25,6 +25,8 @@ import de.prob.core.sablecc.node.Start;
import de.prob.exceptions.ProBException;
import de.prob.logging.Logger;
import de.prob.parser.BindingGenerator;
import de.prob.parser.ProBResultParser;
import de.prob.parser.ResultParserException;
import de.prob.prolog.output.PrologTermStringOutput;
import de.prob.prolog.term.PrologTerm;
......@@ -72,14 +74,7 @@ public class AnimatorImpl {
return item == null ? null : item.getState();
}
public synchronized Start sendCommandImpl(final String command)
throws ProBException {
String input = connector.sendCommand(command);
return parseResult(input);
}
private Start parseResult(final String input) throws CliException,
ResultParserException {
private Start parseResult(final String input) {
if (input == null)
return null;
else
......@@ -158,13 +153,17 @@ public class AnimatorImpl {
PrologTermStringOutput pto = new PrologTermStringOutput();
command.writeCommand(pto);
final String query = pto.fullstop().toString();
final Start ast = sendCommandImpl(query);
String input;
synchronized (this) {
input = connector.sendCommand(query);
}
Map<String, PrologTerm> bindings;
try {
final Start ast = parseResult(input);
bindings = BindingGenerator.createBindingMustNotFail(query, ast);
} catch (de.prob.parser.ResultParserException e) {
Logger.notifyUser(e.getMessage());
throw new CommandException(e.getMessage());
} catch (ResultParserException e) {
Logger.notifyUser(e.getMessage(), e);
throw new CommandException(e.getMessage(), e);
}
return new SimplifiedROMap<String, PrologTerm>(bindings);
}
......
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.prob.core.internal;
import java.io.IOException;
import java.io.PushbackReader;
import java.io.StringReader;
import de.prob.core.ProblemHandler;
import de.prob.core.sablecc.lexer.Lexer;
import de.prob.core.sablecc.lexer.LexerException;
import de.prob.core.sablecc.node.Start;
import de.prob.core.sablecc.parser.Parser;
import de.prob.core.sablecc.parser.ParserException;
import de.prob.exceptions.ProBAssertionFailed;
import de.prob.logging.Logger;
public final class ProBResultParser {
private ProBResultParser() {
throw new UnsupportedOperationException(
"not intended for instantiation");
}
public static Start parse(final String prologAnswer)
throws ResultParserException, ProBAssertionFailed {
Logger.assertProB("prologAnswer.length() != 0",
prologAnswer.length() != 0);
final PushbackReader codeReader = new PushbackReader(new StringReader(
prologAnswer), prologAnswer.length());
final Lexer lexer = new Lexer(codeReader);
final Parser parser = new Parser(lexer);
Start parseResult = null;
try {
parseResult = parser.parse();
} catch (final ParserException e) {
String message = "Internal Error while parsing ProB Answer. This ist most likly a bug in the Resultparser. String was: '"
+ prologAnswer
+ "'. Last Token was '"
+ e.getToken()
+ "': " + e.getLocalizedMessage();
ProblemHandler.handleResultPareserException(message, e);
} catch (final LexerException e) {
String message = "Internal Error while parsing ProB Answer. This ist most likly a bug in the Resultparser String was: '"
+ prologAnswer + "': " + e.getLocalizedMessage();
ProblemHandler.handleResultPareserException(message, e);
} catch (final IOException e) {
String message = "Internal Error while parsing ProB Answer. This ist most likly a bug in the Resultparser String was: "
+ prologAnswer + "': " + e.getLocalizedMessage();
ProblemHandler.handleResultPareserException(message, e);
}
return parseResult;
}
}
\ No newline at end of file
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen,
* Heinrich Heine Universitaet Duesseldorf
* This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.prob.core.internal;
import de.prob.exceptions.ProBException;
public class ResultParserException extends ProBException {
private static final long serialVersionUID = 4607280354438003272L;
public ResultParserException(final String message, final Throwable t) {
super(message, t, true);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment