PROX: emit a meaningfull error message: wip.
Change-Id: Ia0fa8d2d7e08dbf3cbdcdbe542b531446b668bb9
diff --git a/src/main/antlr/cosmas/c2ps_opPROX.g b/src/main/antlr/cosmas/c2ps_opPROX.g
index a4ff2cb..3bb6cd6 100644
--- a/src/main/antlr/cosmas/c2ps_opPROX.g
+++ b/src/main/antlr/cosmas/c2ps_opPROX.g
@@ -21,6 +21,21 @@
@header {package de.ids_mannheim.korap.query.parse.cosmas;}
@lexer::header {package de.ids_mannheim.korap.query.parse.cosmas;}
+@members {
+ public void displayRecognitionError(String[] tokenNames,
+ RecognitionException e) {
+ String hdr = getErrorHeader(e);
+ String msg = getErrorMessage(e, tokenNames);
+ 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...");
+
+ // Now do something with hdr and msg...
+ }
+}
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//
// PROX-Lexer
@@ -59,8 +74,16 @@
proxDist
@init{ int countM=0;}
+@rulecatch
+ {
+ catch (RecognitionException(re)
+ {
+ reportError(re);
+ }
+ }
:
- ((m=proxMeasure {countM++;})|d=proxDirection|v=proxDistValue)+ {countM == 1}?
+ //((m=proxMeasure {countM++;})|d=proxDirection|v=proxDistValue)+ {countM == 1}?
+ ((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)};
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 873f914..201ed74 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
@@ -23,23 +23,28 @@
public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text) throws RecognitionException
{
- boolean multiple = false;
+ boolean multiple = true;
CommonTree tree1 = (CommonTree)ctDir;
CommonTree tree2 = (CommonTree)ctMeas;
CommonTree tree3 = (CommonTree)ctVal;
- addError(StatusCodes.MALFORMED_QUERY,
- "Could not parse query. Please make sure it is well-formed.");
+ //addError(StatusCodes.MALFORMED_QUERY,
+ // "Could not parse query. Please make sure it is well-formed.");
System.err.printf("Debug: encodeDIST: scanned input='%s'.\n", text);
if( multiple == true )
{
- String mess = String.format("line 0:%d '%s' expecting only 1 of 'wsp'!\n",
- 23, text);
+ String mess = String.format("line 0:%d %s expecting only 1 of 'wsp'!\n",
+ 2345, text);
//de.ids_mannheim.korap.query.serialize.Antlr3AbstractQueryProcessor.reportError(mess);
//reportError(mess);
RecognitionException re = new RecognitionException();
+ re.c = '/';
+ re.charPositionInLine = 4;
+ re.index = 1;
+ re.line = 123;
+
throw re;
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index cc03439..4c36a1d 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -18,6 +18,7 @@
import de.ids_mannheim.korap.util.StringUtils;
import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.FailedPredicateException;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.Tree;
import org.antlr.v4.runtime.tree.ParseTree;
@@ -1760,8 +1761,13 @@
org.antlr.runtime.CommonTokenStream tokens =
new org.antlr.runtime.CommonTokenStream(lex); // v3
- // System.out.printf("parseCosmasQuery: tokens = %d\n", tokens.size());
- // System.out.printf("parseCosmasQuery: tokens = %s\n", tokens.toString());
+ System.out.printf("parseCosmasQuery: tokens = %d\n", tokens.size());
+ System.out.printf("parseCosmasQuery: tokens = %s\n", tokens.toString());
+ System.out.printf("parseCosmasQuery: tokens[] = ");
+ for(int i=0; i<tokens.size(); i++)
+ System.out.printf("%s ", tokens.get(i).toString());
+
+ System.out.println();
parser = new c2psParser(tokens);
@@ -1776,12 +1782,20 @@
tree = (Tree) c2Return.getTree();
if (DEBUG) log.debug(tree.toStringTree());
}
+ catch (FailedPredicateException fe)
+ {
+ System.out.printf("parseCosmasQuery: FailedPredicateException!\n");
+ addError(StatusCodes.MALFORMED_QUERY,
+ "failed predicate on prox something.");
+ }
catch (RecognitionException e) {
- log.error(
+ System.out.printf("parseCosmasQuery: RecognitionException!\n");
+ log.error(
"Could not parse query. Please make sure it is well-formed.");
addError(StatusCodes.MALFORMED_QUERY,
"Could not parse query. Please make sure it is well-formed.");
}
+
String treestring = tree.toStringTree();
boolean erroneous = false;
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr3DescriptiveErrorListener.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr3DescriptiveErrorListener.java
index 6e574fd..f317c18 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr3DescriptiveErrorListener.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr3DescriptiveErrorListener.java
@@ -31,6 +31,10 @@
@Override
public void reportError (String error) {
+
+ System.err.printf("Debug: reportError (err): entering for error = '%s'.\n", error);
+ System.out.printf("Debug: reportError (out): entering for error = '%s'.\n", error);
+
String charPositionStr = null;
String offendingSymbol = null;
String expected = null;
@@ -52,17 +56,26 @@
public ArrayList<Object> generateFullErrorMsg () {
- ArrayList<Object> errorSpecs = new ArrayList<Object>();
+
+ ArrayList<Object> errorSpecs = new ArrayList<Object>();
String msg = getDetailedErrorMessage();
errorSpecs.add(StatusCodes.MALFORMED_QUERY);
errorSpecs.add(msg);
errorSpecs.add(getCharPosition());
+
+ System.err.printf("Debug: generateFullErrorMsg: msg = '%s'.\n", msg);
+
return errorSpecs;
}
private String getDetailedErrorMessage () {
- // default message, in case no detailed info is available;
+
+ System.err.printf("Debug: getDetailedErrorMessage: pos=%d expected='%s' offend='%s' query='%s'.\n",
+ charPosition, expected != null ? expected : "null", offendingSymbol != null ? offendingSymbol : "null",
+ query != null ? query : "null");
+
+ // default message, in case no detailed info is available;
String msg = "Malformed query. Could not parse.";
char offendingSymbol = query.charAt(0);
if (query.length() > charPosition)