PROX: emit a meaningfull error message: WIP.
Change-Id: I0d78abab2c03a874f690187d9e33adc356fcf53b
diff --git a/src/main/antlr/cosmas/c2ps_opPROX.g b/src/main/antlr/cosmas/c2ps_opPROX.g
index 3bb6cd6..14756d5 100644
--- a/src/main/antlr/cosmas/c2ps_opPROX.g
+++ b/src/main/antlr/cosmas/c2ps_opPROX.g
@@ -18,7 +18,9 @@
DIR; PLUS; MINUS; BOTH;
GRP; MIN; MAX; }
-@header {package de.ids_mannheim.korap.query.parse.cosmas;}
+@header {package de.ids_mannheim.korap.query.parse.cosmas;
+ import de.ids_mannheim.korap.util.C2RecognitionException;}
+
@lexer::header {package de.ids_mannheim.korap.query.parse.cosmas;}
@members {
@@ -29,13 +31,32 @@
System.err.println("Debug: displayRecognitionError: hdr = " + hdr + ".");
System.err.println("Debug: displayRecognitionError: msg='" + msg + "'.");
System.err.println("Debug: displayRecognitionError: e = " + e.toString() + ".");
-
- emitErrorMessage(hdr + " prox options mismatch...");
+
+ if( e instanceof C2RecognitionException )
+ {
+ C2RecognitionException c2e = (C2RecognitionException) e;
+ String c2msg = hdr + ": PROX options mismatch at '" + c2e.getMismatchedToken() + "'...";
+
+ emitErrorMessage(c2msg);
+ }
+ else
+ emitErrorMessage(hdr + " prox options mismatch...");
// Now do something with hdr and msg...
}
}
+@rulecatch {
+ catch (C2RecognitionException c2e) {
+ //Custom handling of an exception. Any java code is allowed.
+ System.err.printf("Debug: overall rulecatch for c2ps_opPROX: c2RecognitionException.\n");
+ //reportError(c2e);
+ //recover(c2e.input, (RecognitionException) c2e);
+ //throw (RecognitionException)c2e;
+ //System.err.printf("Debug: overall rulecatch: back from reportError(c2e).\n");
+ }
+} // rulecatch
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//
// PROX-Lexer
@@ -76,8 +97,13 @@
@init{ int countM=0;}
@rulecatch
{
- catch (RecognitionException(re)
+ catch (RecognitionException re)
{
+ if( re instanceOf C2RecognitionException )
+ System.err.printf("Debug: catched in proxDist: C2RecognitionException!\n");
+ else
+ System.err.printf("Debug: catched in proxDist: RecognitionException!\n");
+
reportError(re);
}
}
@@ -86,6 +112,7 @@
((m=proxMeasure)|d=proxDirection|v=proxDistValue)+
-> {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text)};
+
// -> {c2ps_opPROX.checkDIST($proxDist.text) == true } ? {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text)};
// new rule accepts only '+' and '-'; default tree for direction is
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java
index 201ed74..133fa58 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java
@@ -4,6 +4,7 @@
import org.antlr.runtime.tree.*;
import de.ids_mannheim.korap.query.serialize.util.Antlr3DescriptiveErrorListener;
import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
+import de.ids_mannheim.korap.util.*;
/*
* parses Opts of PROX: /w3:4,s0,min or %w3:4,s0,min.
@@ -21,7 +22,8 @@
* 28.11.23/FB
*/
- public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text) throws RecognitionException
+ public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text)
+ throws C2RecognitionException
{
boolean multiple = true;
CommonTree tree1 = (CommonTree)ctDir;
@@ -39,11 +41,11 @@
2345, text);
//de.ids_mannheim.korap.query.serialize.Antlr3AbstractQueryProcessor.reportError(mess);
//reportError(mess);
- RecognitionException re = new RecognitionException();
+ C2RecognitionException re = new C2RecognitionException(text);
re.c = '/';
- re.charPositionInLine = 4;
+ re.charPositionInLine = 15; //tokenPos;
re.index = 1;
- re.line = 123;
+ re.line = 0;
throw re;
}
diff --git a/src/main/java/de/ids_mannheim/korap/util/C2RecognitionException.java b/src/main/java/de/ids_mannheim/korap/util/C2RecognitionException.java
new file mode 100644
index 0000000..92ba9ef
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/util/C2RecognitionException.java
@@ -0,0 +1,27 @@
+package de.ids_mannheim.korap.util;
+
+import org.antlr.runtime.*;
+
+/* general String manipulation functions moved
+ * from de.ids_mannheim.de.korap.query.parse.cosmas.c2ps_opREG.java and Cosmas2QueryProcessor.java.
+ * 24.10.23/FB
+ */
+
+public final class C2RecognitionException extends RecognitionException {
+
+ private static final boolean DEBUG = false;
+ public String mismatchedToken;
+
+ public C2RecognitionException(String mismatchedToken)
+
+ {
+ this.mismatchedToken = mismatchedToken;
+
+ } // constructor C2RecognitionException
+
+ public String getMismatchedToken()
+ {
+ return this.mismatchedToken;
+ }
+
+}