From 6c999e77c9365f54f334fab61f9af4b2203bcf35 Mon Sep 17 00:00:00 2001 From: Daniel Plagge <plagge@cs.uni-duesseldorf.de> Date: Thu, 17 Mar 2011 13:31:15 +0000 Subject: [PATCH] inglorious fix: when detecting an EOF in the lexer, throw a runtime exception to stop the evaluation loop. git-svn-id: https://cobra.cs.uni-duesseldorf.de/prob/trunk/experimental/plagge/probkodkod@7393 7aec93f6-bc54-0410-ac70-7d7c9efa889a --- src/de/stups/probkodkod/EOFLexer.java | 8 ++++++-- src/de/stups/probkodkod/KodkodInteraction.java | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/de/stups/probkodkod/EOFLexer.java b/src/de/stups/probkodkod/EOFLexer.java index a066969..1f0d9eb 100644 --- a/src/de/stups/probkodkod/EOFLexer.java +++ b/src/de/stups/probkodkod/EOFLexer.java @@ -19,7 +19,6 @@ import de.stups.probkodkod.parser.node.Token; * @author plagge */ public class EOFLexer extends Lexer { - public EOFLexer(final PushbackReader in) { super(in); } @@ -39,10 +38,15 @@ public class EOFLexer extends Lexer { } private Token filter(Token token) { - if (token instanceof TFullstop) { + if (token instanceof EOF) + throw new AbortException(); + else if (token instanceof TFullstop) { token = new EOF(); } return token; } + public static class AbortException extends RuntimeException { + private static final long serialVersionUID = 4042645224685292559L; + } } diff --git a/src/de/stups/probkodkod/KodkodInteraction.java b/src/de/stups/probkodkod/KodkodInteraction.java index 0bbfd5c..4fbecfe 100644 --- a/src/de/stups/probkodkod/KodkodInteraction.java +++ b/src/de/stups/probkodkod/KodkodInteraction.java @@ -48,10 +48,14 @@ public class KodkodInteraction { final Lexer lexer = new EOFLexer(in); final Parser parser = new Parser(lexer); - while (!session.isStopped()) { - final Start tree = parser.parse(); - tree.apply(analysis); - pto.flush(); + try { + while (!session.isStopped()) { + final Start tree = parser.parse(); + tree.apply(analysis); + pto.flush(); + } + } catch (EOFLexer.AbortException e) { + logger.info("EOF reached"); } logger.info("Kodkod session finished"); -- GitLab