using addError() for error messages in PROX: WIP.
Change-Id: Ibb00c2587085df265d03a0356d83c9e2d60d225c
diff --git a/src/main/antlr/cosmas/c2ps.g b/src/main/antlr/cosmas/c2ps.g
index f0eba80..dd750f3 100644
--- a/src/main/antlr/cosmas/c2ps.g
+++ b/src/main/antlr/cosmas/c2ps.g
@@ -275,7 +275,7 @@
op2 : (opPROX | opIN | opOV | opAND | opOR | opNOT) ;
// AST with Options for opPROX is returned by c2ps_opPROX.check():
-opPROX : OP_PROX -> ^(OPPROX {c2ps_opPROX.check($OP_PROX.text, $OP_PROX.index)} );
+opPROX : OP_PROX -> ^(OPPROX {c2ps_opPROX.check($OP_PROX.text, $OP_PROX.pos)} );
opIN : OP_IN -> {c2ps_opIN.check($OP_IN.text, $OP_IN.index)};
diff --git a/src/main/antlr/cosmas/c2ps_opPROX.g b/src/main/antlr/cosmas/c2ps_opPROX.g
index 9b6c5cb..ab0f4cb 100644
--- a/src/main/antlr/cosmas/c2ps_opPROX.g
+++ b/src/main/antlr/cosmas/c2ps_opPROX.g
@@ -73,7 +73,7 @@
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-opPROX : proxTyp proxDist (',' proxDist)* (',' proxGroup)?
+opPROX[int pos] : proxTyp proxDist[$pos] (',' proxDist[$pos])* (',' proxGroup)?
-> ^(PROX_OPTS {$proxTyp.tree} ^(DIST_LIST proxDist+) {$proxGroup.tree});
@@ -93,12 +93,12 @@
// count each option type and find out if any one is missing or occures multiple times.
// 28.11.23/FB
-proxDist
+proxDist[int pos]
@init{ int countM=0; int countD=0; int countV=0;}
:
((m=proxMeasure {countM++;})|(d=proxDirection {countD++;})|(v=proxDistValue {countV++;}) )+
- -> {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text, countD, countM, countV)};
+ -> {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text, countD, countM, countV, $pos)};
// 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 2f81b5c..82bc9b9 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.Antlr3AbstractQueryProcessor;
import de.ids_mannheim.korap.query.serialize.util.Antlr3DescriptiveErrorListener;
import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
import de.ids_mannheim.korap.util.*;
@@ -10,7 +12,7 @@
* parses Opts of PROX: /w3:4,s0,min or %w3:4,s0,min.
*/
-public class c2ps_opPROX
+public class c2ps_opPROX
{
final static int typeERROR = 1; // type of an Error CommonToken.
@@ -20,7 +22,7 @@
final static int ERR_VAL_TOOGREAT = 303;
final static int ERR_DIR_TOOGREAT = 304;
- private static CommonTree buildErrorTree_Prox(String text, int errCode, int typeDIST)
+ private static CommonTree buildErrorTree(String text, int errCode, int typeDIST, int pos)
{
CommonTree
@@ -70,6 +72,9 @@
errorNode.addChild(errorArg);
errorNode.addChild(errorMes);
+ // test - 09.01.24/FB
+ //addError("ab");
+
return errorTree;
}
@@ -91,24 +96,24 @@
*/
public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text,
- int countD, int countM, int countV)
+ int countD, int countM, int countV, int pos)
{
CommonTree tree1 = (CommonTree)ctDir;
CommonTree tree2 = (CommonTree)ctMeas;
CommonTree tree3 = (CommonTree)ctVal;
- //System.err.printf("Debug: encodeDIST: scanned input='%s' countM=%d countD=%d countV=%d.\n",
- // text, countM, countD, countV);
+ System.err.printf("Debug: encodeDIST: scanned input='%s' countM=%d countD=%d countV=%d pos=%d.\n",
+ text, countM, countD, countV, pos);
if( countM == 0 )
- return buildErrorTree_Prox(text, ERR_MEAS_NULL, typeDIST);
+ return buildErrorTree(text, ERR_MEAS_NULL, typeDIST, pos);
if( countM > 1 )
- return buildErrorTree_Prox(text, ERR_MEAS_TOOGREAT, typeDIST);
+ return buildErrorTree(text, ERR_MEAS_TOOGREAT, typeDIST, pos);
if( countV == 0 )
- return buildErrorTree_Prox(text, ERR_VAL_NULL, typeDIST);
+ return buildErrorTree(text, ERR_VAL_NULL, typeDIST, pos);
if( countV > 1 )
- return buildErrorTree_Prox(text, ERR_VAL_TOOGREAT, typeDIST);
+ return buildErrorTree(text, ERR_VAL_TOOGREAT, typeDIST, pos);
if( countD == 0 )
{
@@ -122,7 +127,7 @@
tree1 = treeDIR;
}
else if( countD > 1 )
- return buildErrorTree_Prox(text, ERR_DIR_TOOGREAT, typeDIST);
+ return buildErrorTree(text, ERR_DIR_TOOGREAT, typeDIST, pos);
// create DIST tree:
CommonTree
@@ -143,21 +148,22 @@
return true;
}
- public static Tree check (String input, int index) {
+ public static Tree check (String input, int pos)
+ {
ANTLRStringStream ss = new ANTLRStringStream(input);
c2ps_opPROXLexer lex = new c2ps_opPROXLexer(ss);
CommonTokenStream tokens = new CommonTokenStream(lex);
c2ps_opPROXParser g = new c2ps_opPROXParser(tokens);
c2ps_opPROXParser.opPROX_return c2PQReturn = null;
- /*
- System.out.println("check opPROX:" + index + ": " + input);
+ /**/
+ System.out.printf("check opPROX: pos=%d input='%s'.\n", pos, input);
System.out.flush();
- */
+ /**/
try {
- c2PQReturn = g.opPROX();
- }
+ c2PQReturn = g.opPROX(pos);
+ }
catch (RecognitionException e) {
e.printStackTrace();
}
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 381c35e..47eb907 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
@@ -1851,19 +1851,29 @@
}
String treestring = tree.toStringTree();
-
+ System.err.printf("Debug: parseCosmasQuery: tree = '%s'.\n", treestring);
+
boolean erroneous = false;
if (parser.failed() || parser.getNumberOfSyntaxErrors() > 0) {
erroneous = true;
tree = null;
}
+ System.err.printf("Debug: parseCosmasQuery: failed=%b no. of synt. err = %d.\n",
+ parser.failed(), parser.getNumberOfSyntaxErrors());
+
if (erroneous || treestring.contains("<mismatched token")
|| treestring.contains("<error")
- || treestring.contains("<unexpected")) {
- log.error(errorListener.generateFullErrorMsg().toString());
+ || treestring.contains("<unexpected"))
+ {
+ System.err.printf("Debug: parseCosmasQuery: tree: '%s'.\n", treestring);
+ System.err.printf("Debug: parseCosmasQuery: FullErrorMsg: '%s'.\n", errorListener.generateFullErrorMsg().toString());
+ log.error(errorListener.generateFullErrorMsg().toString());
addError(errorListener.generateFullErrorMsg());
}
+
+ addError(1234, "Test-Message");
+
return tree;
}
}