PROX: return exact error messasge about prox options.

Change-Id: Ifc3f1f7ef86ac699a3ce1671e790d09cd4ed54e1
diff --git a/src/main/antlr/cosmas/c2ps_opPROX.g b/src/main/antlr/cosmas/c2ps_opPROX.g
index bb1fb18..a4ff2cb 100644
--- a/src/main/antlr/cosmas/c2ps_opPROX.g
+++ b/src/main/antlr/cosmas/c2ps_opPROX.g
@@ -57,9 +57,13 @@
 // but how to handle multiple values for those options?
 // 28.11.23/FB
 
-proxDist:	(m=proxMeasure|d=proxDirection|v=proxDistValue)+
+proxDist
+@init{ int countM=0;}
+	:
+		((m=proxMeasure {countM++;})|d=proxDirection|v=proxDistValue)+ {countM == 1}? 
 		      
-		->  {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text)};
+	->  {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 
 // set in c2ps_opPROX.encodeDIST() now.
@@ -74,8 +78,16 @@
 		-> {$m2.text != null}? ^(RANGE $m1  $m2)
 		->				       ^(RANGE VAL0 $m1);
 
+/* calling c2ps_opPROX.checkMeasure() as a check will not compile by ANTLR,
+   reason unknown! 01.12.23/FB
 proxMeasure
-	:	(meas='w'|meas='s'|meas='p'|meas='t') -> {c2ps_opPROX.checkMeasure($meas)} ;  // {c2ps_opPROX.checkMeasure($meas)} ? ^(MEAS $meas);
+	:	(meas='w'|meas='s'|meas='p'|meas='t') -> {c2ps_opPROX.checkMeasure($meas)} ? ^(MEAS $meas) ;  
+*/
+
+// mentioning >1 measures will be checked/rejected in c2ps_opPROX.encodeDIST(). 
+
+proxMeasure
+	:	(meas='w'|meas='s'|meas='p'|meas='t') -> ^(MEAS $meas) ;  
 
 proxDistMin
 	:	DISTVALUE;
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 6458dd3..873f914 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
@@ -2,6 +2,8 @@
 
 import org.antlr.runtime.*;
 import org.antlr.runtime.tree.*;
+import de.ids_mannheim.korap.query.serialize.util.Antlr3DescriptiveErrorListener;
+import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
 
 /*
  * parses Opts of PROX: /w3:4,s0,min or %w3:4,s0,min.
@@ -19,15 +21,29 @@
 	 * 28.11.23/FB
 	 */
 	
-	public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text)
+	public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text) throws RecognitionException 
 	{
+		boolean multiple = false;
 		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.");
+		
 		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);
+			//de.ids_mannheim.korap.query.serialize.Antlr3AbstractQueryProcessor.reportError(mess);
+			//reportError(mess);
+			RecognitionException re = new RecognitionException();
+			throw re;
+			}
+			
+		
 		System.err.printf("Debug: encodeDIST: ctDir='%s': %d ctMeas='%s': %d ctVal='%s': %d.\n",
 				tree1 != null ? tree1.toStringTree() : "null",
 				tree1 != null ? tree1.getChildCount() : 0,
@@ -62,6 +78,12 @@
 		return tree;
 	} // encodeDIST
 	
+	public static boolean checkDIST(String input)
+	
+	{
+		return true;
+	}
+	
 	public static Tree check (String input, int index) {
         ANTLRStringStream ss = new ANTLRStringStream(input);
         c2ps_opPROXLexer lex = new c2ps_opPROXLexer(ss);
@@ -88,6 +110,12 @@
         return tree;
     }
 
+	public static boolean checkFalse()
+	{
+	
+	return false; // testwise	
+	}
+	
 	public static boolean checkMeasure( Object measure)
 	{
 		System.err.printf("Debug: checkMeasure: measure = %s.\n",