diff --git a/de.prob.core/src/de/prob/core/ProblemHandler.java b/de.prob.core/src/de/prob/core/ProblemHandler.java index 30a76a8dd19cc4db1982835c24ba189d96324a44..9cdd906c569c74f62be9ad92bf0aa712ee48d5ba 100644 --- a/de.prob.core/src/de/prob/core/ProblemHandler.java +++ b/de.prob.core/src/de/prob/core/ProblemHandler.java @@ -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); - } - } diff --git a/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java b/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java index 00ced65cbf0e2cea5f19e7d77413e0de83d0d1b6..21733a9353d72f28a6cc14533397ac9c3e943ef3 100644 --- a/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java +++ b/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java @@ -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); } diff --git a/de.prob.core/src/de/prob/core/internal/ProBResultParser.java b/de.prob.core/src/de/prob/core/internal/ProBResultParser.java deleted file mode 100644 index 85eb4960e745ef475fc138e34932bdfd5fdf114b..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/core/internal/ProBResultParser.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * (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 diff --git a/de.prob.core/src/de/prob/core/internal/ResultParserException.java b/de.prob.core/src/de/prob/core/internal/ResultParserException.java deleted file mode 100644 index 5b3b0aa5b1701a441ec386a256c173d5795b60b3..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/core/internal/ResultParserException.java +++ /dev/null @@ -1,18 +0,0 @@ -/** - * (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); - } - -}