From 0022e81b1b3796142c8094de11cfeafff7dd8d8c Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Wed, 8 Aug 2012 06:57:05 +0000 Subject: [PATCH] Parser handles invalid literals (too big etc.) + tidy up of parser error reporting code. git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@5520 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/parser/PrismParser.java | 548 ++++++++++++++++-------------- prism/src/parser/PrismParser.jj | 42 ++- 2 files changed, 315 insertions(+), 275 deletions(-) diff --git a/prism/src/parser/PrismParser.java b/prism/src/parser/PrismParser.java index 60182b44..b2aa1dab 100644 --- a/prism/src/parser/PrismParser.java +++ b/prism/src/parser/PrismParser.java @@ -274,15 +274,31 @@ public class PrismParser implements PrismParserConstants { */ protected PrismLangException generateSyntaxError(ParseException e) { - if (e == null || e.currentToken == null) return new PrismLangException("Syntax error"); - else if (e.currentToken.next == null) { - ExpressionIdent tmp = new ExpressionIdent(e.currentToken.image); - tmp.setPosition(e.currentToken); - return new PrismLangException("Syntax error", tmp); - } else { - ExpressionIdent tmp = new ExpressionIdent(e.currentToken.next.image); - tmp.setPosition(e.currentToken.next); - return new PrismLangException("Syntax error", tmp); + if (e == null) return new PrismLangException("Syntax error"); + // No token: was prob created manually so use message if present + if (e.currentToken == null) { + String msg = e.getMessage(); + String exMsg = "Syntax error"; + if (msg != null && msg.length() > 0) + exMsg += ": " + msg; + return new PrismLangException(exMsg); + } + // Use current/next token to find location of error + // But don't use error message if too long (esp if generated by JavaCC) + else { + ExpressionIdent tmp; + if (e.currentToken.next == null) { + tmp = new ExpressionIdent(e.currentToken.image); + tmp.setPosition(e.currentToken); + } else { + tmp = new ExpressionIdent(e.currentToken.next.image); + tmp.setPosition(e.currentToken.next); + } + String msg = e.getMessage(); + String exMsg = "Syntax error"; + if (msg != null && msg.length() > 0 && msg.length() < 50) + exMsg += ": " + msg; + return new PrismLangException(exMsg, tmp); } } @@ -2325,7 +2341,10 @@ public class PrismParser implements PrismParserConstants { } catch (NumberFormatException e) { // Need to catch this because some matches for regexp REG_INT // are not valid integers (e.g. too big). - {if (true) throw generateParseException();} + ParseException ex = new ParseException("Invalid integer literal"); + ex.currentToken = getToken(0); + {if (true) throw ex;} + // NB: can't call generateParseException() here; it crashes } break; case REG_DOUBLE: @@ -2336,7 +2355,8 @@ public class PrismParser implements PrismParserConstants { } catch (NumberFormatException e) { // Need to catch this because some matches for regexp REG_DOUBLE // may not be valid doubles. - {if (true) throw generateParseException();} + ParseException ex = new ParseException("Invalid double literal"); + // NB: can't call generateParseException() here; it crashes } break; case TRUE: @@ -3093,28 +3113,6 @@ public class PrismParser implements PrismParserConstants { finally { jj_save(13, xla); } } - static private boolean jj_3R_70() { - if (jj_scan_token(IFF)) return true; - if (jj_3R_69()) return true; - return false; - } - - static private boolean jj_3R_59() { - if (jj_3R_69()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_70()) { jj_scanpos = xsp; break; } - } - return false; - } - - static private boolean jj_3R_60() { - if (jj_scan_token(IMPLIES)) return true; - if (jj_3R_59()) return true; - return false; - } - static private boolean jj_3R_51() { if (jj_3R_59()) return true; Token xsp; @@ -3125,18 +3123,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_141() { - if (jj_scan_token(EQ)) return true; - if (jj_scan_token(QMARK)) return true; - return false; - } - - static private boolean jj_3R_140() { - if (jj_3R_85()) return true; - if (jj_3R_35()) return true; - return false; - } - static private boolean jj_3R_52() { if (jj_scan_token(QMARK)) return true; if (jj_3R_51()) return true; @@ -3151,6 +3137,22 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_119() { + if (jj_scan_token(S)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_140()) { + jj_scanpos = xsp; + if (jj_3R_141()) return true; + } + if (jj_scan_token(LBRACKET)) return true; + if (jj_3R_35()) return true; + xsp = jj_scanpos; + if (jj_3R_142()) jj_scanpos = xsp; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + static private boolean jj_3_12() { if (jj_3R_30()) return true; if (jj_scan_token(LPARENTH)) return true; @@ -3169,22 +3171,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_119() { - if (jj_scan_token(S)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_140()) { - jj_scanpos = xsp; - if (jj_3R_141()) return true; - } - if (jj_scan_token(LBRACKET)) return true; - if (jj_3R_35()) return true; - xsp = jj_scanpos; - if (jj_3R_142()) jj_scanpos = xsp; - if (jj_scan_token(RBRACKET)) return true; - return false; - } - static private boolean jj_3R_49() { if (jj_3R_51()) return true; Token xsp; @@ -3193,38 +3179,38 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_67() { - if (jj_3R_30()) return true; + static private boolean jj_3R_139() { + if (jj_3R_162()) return true; return false; } - static private boolean jj_3R_65() { - if (jj_3R_30()) return true; + static private boolean jj_3R_175() { + if (jj_scan_token(MAX)) return true; return false; } - static private boolean jj_3R_63() { + static private boolean jj_3R_67() { if (jj_3R_30()) return true; return false; } - static private boolean jj_3R_61() { - if (jj_3R_30()) return true; + static private boolean jj_3R_174() { + if (jj_scan_token(MIN)) return true; return false; } - static private boolean jj_3R_139() { - if (jj_3R_162()) return true; + static private boolean jj_3R_65() { + if (jj_3R_30()) return true; return false; } - static private boolean jj_3R_175() { - if (jj_scan_token(MAX)) return true; + static private boolean jj_3R_63() { + if (jj_3R_30()) return true; return false; } - static private boolean jj_3R_174() { - if (jj_scan_token(MIN)) return true; + static private boolean jj_3R_61() { + if (jj_3R_30()) return true; return false; } @@ -3254,6 +3240,18 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_172() { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_174()) { + jj_scanpos = xsp; + if (jj_3R_175()) return true; + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + static private boolean jj_3R_55() { if (jj_scan_token(GE)) return true; Token xsp; @@ -3287,15 +3285,15 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_172() { + static private boolean jj_3R_162() { if (jj_scan_token(LBRACE)) return true; + if (jj_3R_35()) return true; + if (jj_scan_token(RBRACE)) return true; Token xsp; - xsp = jj_scanpos; - if (jj_3R_174()) { - jj_scanpos = xsp; - if (jj_3R_175()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_172()) { jj_scanpos = xsp; break; } } - if (jj_scan_token(RBRACE)) return true; return false; } @@ -3321,18 +3319,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_162() { - if (jj_scan_token(LBRACE)) return true; - if (jj_3R_35()) return true; - if (jj_scan_token(RBRACE)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_172()) { jj_scanpos = xsp; break; } - } - return false; - } - static private boolean jj_3R_40() { if (jj_3R_49()) return true; return false; @@ -3380,6 +3366,13 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_161() { + if (jj_scan_token(MAX)) return true; + if (jj_scan_token(EQ)) return true; + if (jj_scan_token(QMARK)) return true; + return false; + } + static private boolean jj_3R_37() { Token xsp; xsp = jj_scanpos; @@ -3390,8 +3383,14 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_161() { - if (jj_scan_token(MAX)) return true; + static private boolean jj_3R_160() { + if (jj_scan_token(MIN)) return true; + if (jj_scan_token(EQ)) return true; + if (jj_scan_token(QMARK)) return true; + return false; + } + + static private boolean jj_3R_159() { if (jj_scan_token(EQ)) return true; if (jj_scan_token(QMARK)) return true; return false; @@ -3402,8 +3401,8 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_160() { - if (jj_scan_token(MIN)) return true; + static private boolean jj_3R_138() { + if (jj_scan_token(PMAX)) return true; if (jj_scan_token(EQ)) return true; if (jj_scan_token(QMARK)) return true; return false; @@ -3414,7 +3413,8 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_159() { + static private boolean jj_3R_137() { + if (jj_scan_token(PMIN)) return true; if (jj_scan_token(EQ)) return true; if (jj_scan_token(QMARK)) return true; return false; @@ -3430,17 +3430,20 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_138() { - if (jj_scan_token(PMAX)) return true; - if (jj_scan_token(EQ)) return true; - if (jj_scan_token(QMARK)) return true; - return false; - } - - static private boolean jj_3R_137() { - if (jj_scan_token(PMIN)) return true; - if (jj_scan_token(EQ)) return true; - if (jj_scan_token(QMARK)) return true; + static private boolean jj_3R_136() { + if (jj_scan_token(P)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_158()) { + jj_scanpos = xsp; + if (jj_3R_159()) { + jj_scanpos = xsp; + if (jj_3R_160()) { + jj_scanpos = xsp; + if (jj_3R_161()) return true; + } + } + } return false; } @@ -3460,23 +3463,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_136() { - if (jj_scan_token(P)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_158()) { - jj_scanpos = xsp; - if (jj_3R_159()) { - jj_scanpos = xsp; - if (jj_3R_160()) { - jj_scanpos = xsp; - if (jj_3R_161()) return true; - } - } - } - return false; - } - static private boolean jj_3R_118() { Token xsp; xsp = jj_scanpos; @@ -3514,11 +3500,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3_4() { - if (jj_scan_token(LABEL)) return true; - return false; - } - static private boolean jj_3R_117() { if (jj_scan_token(LPARENTH)) return true; if (jj_3R_35()) return true; @@ -3526,6 +3507,11 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3_4() { + if (jj_scan_token(LABEL)) return true; + return false; + } + static private boolean jj_3_3() { if (jj_scan_token(LABEL)) return true; if (jj_scan_token(DQUOTE)) return true; @@ -3537,11 +3523,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_35() { - if (jj_3R_36()) return true; - return false; - } - static private boolean jj_3R_128() { if (jj_scan_token(FALSE)) return true; return false; @@ -3552,6 +3533,11 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_35() { + if (jj_3R_36()) return true; + return false; + } + static private boolean jj_3R_126() { if (jj_scan_token(REG_DOUBLE)) return true; return false; @@ -3583,25 +3569,18 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_131() { - if (jj_scan_token(MAX)) return true; - return false; - } - static private boolean jj_3R_95() { if (jj_scan_token(LE)) return true; return false; } - static private boolean jj_3_8() { - if (jj_scan_token(OR)) return true; - if (jj_scan_token(OR)) return true; - if (jj_scan_token(OR)) return true; + static private boolean jj_3R_94() { + if (jj_scan_token(GE)) return true; return false; } - static private boolean jj_3R_94() { - if (jj_scan_token(GE)) return true; + static private boolean jj_3R_131() { + if (jj_scan_token(MAX)) return true; return false; } @@ -3631,6 +3610,13 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3_8() { + if (jj_scan_token(OR)) return true; + if (jj_scan_token(OR)) return true; + if (jj_scan_token(OR)) return true; + return false; + } + static private boolean jj_3R_132() { if (jj_3R_35()) return true; Token xsp; @@ -3693,6 +3679,11 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_34() { + if (jj_scan_token(REG_IDENTPRIME)) return true; + return false; + } + static private boolean jj_3R_130() { if (jj_scan_token(MIN)) return true; return false; @@ -3711,8 +3702,8 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_34() { - if (jj_scan_token(REG_IDENTPRIME)) return true; + static private boolean jj_3R_154() { + if (jj_scan_token(OR)) return true; return false; } @@ -3722,11 +3713,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_154() { - if (jj_scan_token(OR)) return true; - return false; - } - static private boolean jj_3R_129() { if (jj_scan_token(LPARENTH)) return true; if (jj_3R_132()) return true; @@ -3747,11 +3733,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_112() { - if (jj_3R_124()) return true; - return false; - } - static private boolean jj_3R_151() { if (jj_scan_token(MAX)) return true; return false; @@ -3762,6 +3743,16 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_112() { + if (jj_3R_124()) return true; + return false; + } + + static private boolean jj_3R_28() { + if (jj_scan_token(REG_IDENT)) return true; + return false; + } + static private boolean jj_3R_111() { if (jj_3R_123()) return true; return false; @@ -3772,8 +3763,8 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_28() { - if (jj_scan_token(REG_IDENT)) return true; + static private boolean jj_3R_149() { + if (jj_scan_token(INIT)) return true; return false; } @@ -3792,11 +3783,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_149() { - if (jj_scan_token(INIT)) return true; - return false; - } - static private boolean jj_3R_107() { if (jj_3R_119()) return true; return false; @@ -3807,29 +3793,19 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_105() { - if (jj_3R_117()) return true; - return false; - } - - static private boolean jj_3R_104() { - if (jj_3R_116()) return true; - return false; - } - static private boolean jj_3R_156() { if (jj_scan_token(COMMA)) return true; if (jj_3R_35()) return true; return false; } - static private boolean jj_3R_103() { - if (jj_3R_115()) return true; + static private boolean jj_3R_105() { + if (jj_3R_117()) return true; return false; } - static private boolean jj_3R_102() { - if (jj_3R_114()) return true; + static private boolean jj_3R_104() { + if (jj_3R_116()) return true; return false; } @@ -3838,8 +3814,8 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_101() { - if (jj_3R_113()) return true; + static private boolean jj_3R_103() { + if (jj_3R_115()) return true; return false; } @@ -3853,8 +3829,8 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_91() { - if (jj_scan_token(MINUS)) return true; + static private boolean jj_3R_102() { + if (jj_3R_114()) return true; return false; } @@ -3863,6 +3839,16 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_101() { + if (jj_3R_113()) return true; + return false; + } + + static private boolean jj_3R_91() { + if (jj_scan_token(MINUS)) return true; + return false; + } + static private boolean jj_3R_124() { if (jj_scan_token(FILTER)) return true; if (jj_scan_token(LPARENTH)) return true; @@ -3932,13 +3918,13 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_97() { - if (jj_3R_100()) return true; + static private boolean jj_3R_177() { + if (jj_3R_35()) return true; return false; } - static private boolean jj_3R_177() { - if (jj_3R_35()) return true; + static private boolean jj_3R_97() { + if (jj_3R_100()) return true; return false; } @@ -3948,6 +3934,18 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_123() { + if (jj_scan_token(DQUOTE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_148()) { + jj_scanpos = xsp; + if (jj_3R_149()) return true; + } + if (jj_scan_token(DQUOTE)) return true; + return false; + } + static private boolean jj_3R_88() { Token xsp; xsp = jj_scanpos; @@ -3965,18 +3963,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_123() { - if (jj_scan_token(DQUOTE)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_148()) { - jj_scanpos = xsp; - if (jj_3R_149()) return true; - } - if (jj_scan_token(DQUOTE)) return true; - return false; - } - static private boolean jj_3R_98() { if (jj_scan_token(TIMES)) return true; return false; @@ -4065,12 +4051,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_81() { - if (jj_3R_85()) return true; - if (jj_3R_80()) return true; - return false; - } - static private boolean jj_3R_170() { if (jj_scan_token(F)) return true; if (jj_3R_35()) return true; @@ -4091,13 +4071,9 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_78() { + static private boolean jj_3R_81() { + if (jj_3R_85()) return true; if (jj_3R_80()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_81()) { jj_scanpos = xsp; break; } - } return false; } @@ -4124,18 +4100,12 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_79() { - if (jj_3R_82()) return true; - if (jj_3R_78()) return true; - return false; - } - - static private boolean jj_3R_77() { - if (jj_3R_78()) return true; + static private boolean jj_3R_78() { + if (jj_3R_80()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_79()) { jj_scanpos = xsp; break; } + if (jj_3R_81()) { jj_scanpos = xsp; break; } } return false; } @@ -4152,6 +4122,22 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_79() { + if (jj_3R_82()) return true; + if (jj_3R_78()) return true; + return false; + } + + static private boolean jj_3R_77() { + if (jj_3R_78()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_79()) { jj_scanpos = xsp; break; } + } + return false; + } + static private boolean jj_3R_33() { if (jj_scan_token(AND)) return true; if (jj_3R_32()) return true; @@ -4213,27 +4199,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_74() { - if (jj_scan_token(AND)) return true; - if (jj_3R_73()) return true; - return false; - } - - static private boolean jj_3R_31() { - if (jj_3R_32()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_33()) { jj_scanpos = xsp; break; } - } - return false; - } - - static private boolean jj_3_5() { - if (jj_3R_29()) return true; - return false; - } - static private boolean jj_3R_142() { if (jj_3R_162()) return true; return false; @@ -4246,16 +4211,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_71() { - if (jj_3R_73()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_74()) { jj_scanpos = xsp; break; } - } - return false; - } - static private boolean jj_3R_145() { if (jj_scan_token(RMAX)) return true; if (jj_scan_token(EQ)) return true; @@ -4270,13 +4225,9 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_29() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_31()) { - jj_scanpos = xsp; - if (jj_scan_token(49)) return true; - } + static private boolean jj_3R_74() { + if (jj_scan_token(AND)) return true; + if (jj_3R_73()) return true; return false; } @@ -4293,6 +4244,41 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_31() { + if (jj_3R_32()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_33()) { jj_scanpos = xsp; break; } + } + return false; + } + + static private boolean jj_3_5() { + if (jj_3R_29()) return true; + return false; + } + + static private boolean jj_3R_71() { + if (jj_3R_73()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_74()) { jj_scanpos = xsp; break; } + } + return false; + } + + static private boolean jj_3R_29() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_31()) { + jj_scanpos = xsp; + if (jj_scan_token(49)) return true; + } + return false; + } + static private boolean jj_3R_164() { if (jj_3R_85()) return true; if (jj_3R_35()) return true; @@ -4318,12 +4304,6 @@ public class PrismParser implements PrismParserConstants { return false; } - static private boolean jj_3R_72() { - if (jj_scan_token(OR)) return true; - if (jj_3R_71()) return true; - return false; - } - static private boolean jj_3R_120() { Token xsp; xsp = jj_scanpos; @@ -4342,6 +4322,12 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_72() { + if (jj_scan_token(OR)) return true; + if (jj_3R_71()) return true; + return false; + } + static private boolean jj_3R_69() { if (jj_3R_71()) return true; Token xsp; @@ -4352,6 +4338,40 @@ public class PrismParser implements PrismParserConstants { return false; } + static private boolean jj_3R_70() { + if (jj_scan_token(IFF)) return true; + if (jj_3R_69()) return true; + return false; + } + + static private boolean jj_3R_59() { + if (jj_3R_69()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_70()) { jj_scanpos = xsp; break; } + } + return false; + } + + static private boolean jj_3R_60() { + if (jj_scan_token(IMPLIES)) return true; + if (jj_3R_59()) return true; + return false; + } + + static private boolean jj_3R_141() { + if (jj_scan_token(EQ)) return true; + if (jj_scan_token(QMARK)) return true; + return false; + } + + static private boolean jj_3R_140() { + if (jj_3R_85()) return true; + if (jj_3R_35()) return true; + return false; + } + static private boolean jj_initialized_once = false; /** Generated Token Manager. */ static public PrismParserTokenManager token_source; diff --git a/prism/src/parser/PrismParser.jj b/prism/src/parser/PrismParser.jj index 7a7de295..5b146b86 100644 --- a/prism/src/parser/PrismParser.jj +++ b/prism/src/parser/PrismParser.jj @@ -307,15 +307,31 @@ public class PrismParser */ protected PrismLangException generateSyntaxError(ParseException e) { - if (e == null || e.currentToken == null) return new PrismLangException("Syntax error"); - else if (e.currentToken.next == null) { - ExpressionIdent tmp = new ExpressionIdent(e.currentToken.image); - tmp.setPosition(e.currentToken); - return new PrismLangException("Syntax error", tmp); - } else { - ExpressionIdent tmp = new ExpressionIdent(e.currentToken.next.image); - tmp.setPosition(e.currentToken.next); - return new PrismLangException("Syntax error", tmp); + if (e == null) return new PrismLangException("Syntax error"); + // No token: was prob created manually so use message if present + if (e.currentToken == null) { + String msg = e.getMessage(); + String exMsg = "Syntax error"; + if (msg != null && msg.length() > 0) + exMsg += ": " + msg; + return new PrismLangException(exMsg); + } + // Use current/next token to find location of error + // But don't use error message if too long (esp if generated by JavaCC) + else { + ExpressionIdent tmp; + if (e.currentToken.next == null) { + tmp = new ExpressionIdent(e.currentToken.image); + tmp.setPosition(e.currentToken); + } else { + tmp = new ExpressionIdent(e.currentToken.next.image); + tmp.setPosition(e.currentToken.next); + } + String msg = e.getMessage(); + String exMsg = "Syntax error"; + if (msg != null && msg.length() > 0 && msg.length() < 20) + exMsg += ": " + msg; + return new PrismLangException(exMsg, tmp); } } @@ -1378,7 +1394,10 @@ Expression ExpressionLiteral(boolean prop, boolean pathprop) : } catch (NumberFormatException e) { // Need to catch this because some matches for regexp REG_INT // are not valid integers (e.g. too big). - throw generateParseException(); + ParseException ex = new ParseException("Invalid integer literal"); + ex.currentToken = getToken(0); + throw ex; + // NB: can't call generateParseException() here; it crashes }} | { @@ -1388,7 +1407,8 @@ Expression ExpressionLiteral(boolean prop, boolean pathprop) : } catch (NumberFormatException e) { // Need to catch this because some matches for regexp REG_DOUBLE // may not be valid doubles. - throw generateParseException(); + ParseException ex = new ParseException("Invalid double literal"); + // NB: can't call generateParseException() here; it crashes }} | { ret = new ExpressionLiteral(TypeBool.getInstance(), new Boolean(true)); }