Skip to content

Commit

Permalink
PROX: Tests with RecognitionExceptions removed. All Error Codes in St…
Browse files Browse the repository at this point in the history
…atusCodes.java.

Change-Id: Id6355ddf859f35b8d0f20b4ce53c0f3da2122b03
  • Loading branch information
Bodmo committed Jan 11, 2024
1 parent effac90 commit 78e828c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
8 changes: 1 addition & 7 deletions src/main/antlr/cosmas/c2ps_opPROX.g
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,9 @@ proxTyp : '/' -> ^(TYP PROX) // klassischer Abstand.

// proxDist: e.g. +5w or -s0 or /w2:4 etc.
// kein proxDirection? hier, weil der Default erst innerhalb von Regel proxDirection erzeugt werden kann.
/* incomplete original version:
proxDist: proxDirection (v1=proxDistValue m1=proxMeasure | m2=proxMeasure v2=proxDistValue)

-> {$v1.tree != null}? ^(DIST {$proxDirection.tree} {$v1.tree} {$m1.tree})
-> ^(DIST {$proxDirection.tree} {$v2.tree} {$m2.tree});
*/

// new rule: accepts options in any order:
// count each option type and find out if any one is missing or occures multiple times.
// count each option type and find out if any one is missing or occures multiple times.
// 28.11.23/FB

proxDist[int pos]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ public class c2ps_opPROX
{
// type of an Error CommonToken:
final static int typeERROR = 1;
// error codes returned to client:
final public static int ERR_PROX_UNKNOWN = 300;
final static int ERR_MEAS_NULL = 301;
final static int ERR_MEAS_TOOGREAT = 302;
final static int ERR_VAL_NULL = 303;
final static int ERR_VAL_TOOGREAT = 304;
final static int ERR_DIR_TOOGREAT = 305;
// Prox error codes defined in StatusCodes.java.

private static CommonTree buildErrorTree(String text, int errCode, int typeDIST, int pos) throws RecognitionException
private static CommonTree buildErrorTree(String text, int errCode, int typeDIST, int pos)

{
CommonTree
Expand All @@ -43,24 +37,24 @@ private static CommonTree buildErrorTree(String text, int errCode, int typeDIST,

switch( errCode )
{
case ERR_MEAS_NULL:
case StatusCodes.ERR_PROX_MEAS_NULL:
mess = String.format("Abstandsoperator an der Stelle '%s' es fehlt eine der folgenden Angaben: w,s,p!", text);
errorMes = new CommonTree(new CommonToken(typeERROR, mess));
break;
case ERR_MEAS_TOOGREAT:
case StatusCodes.ERR_PROX_MEAS_TOOGREAT:
mess = String.format("Abstandsoperator an der Stelle '%s': Bitte nur 1 der folgenden Angaben einsetzen: w,s,p! " +
"Falls Mehrfachangabe erwünscht, müssen diese durch Kommata getrennt werden (z.B.: /+w2,s0).", text);
errorMes = new CommonTree(new CommonToken(typeERROR, mess));
break;
case ERR_VAL_NULL:
case StatusCodes.ERR_PROX_VAL_NULL:
mess = String.format("Abstandsoperator an der Stelle '%s': Bitte einen numerischen Wert einsetzen (z.B. /+w5)! ", text);
errorMes = new CommonTree(new CommonToken(typeERROR, mess));
break;
case ERR_VAL_TOOGREAT:
case StatusCodes.ERR_PROX_VAL_TOOGREAT:
mess = String.format("Abstandsoperator an der Stelle '%s': Bitte nur 1 numerischen Wert einsetzen (z.B. /+w5)! ", text);
errorMes = new CommonTree(new CommonToken(typeERROR, mess));
break;
case ERR_DIR_TOOGREAT:
case StatusCodes.ERR_PROX_DIR_TOOGREAT:
mess = String.format("Abstandsoperator an der Stelle '%s': Bitte nur 1 Angabe '+' oder '-' oder keine! ", text);
errorMes = new CommonTree(new CommonToken(typeERROR, mess));
break;
Expand Down Expand Up @@ -97,7 +91,6 @@ private static CommonTree buildErrorTree(String text, int errCode, int typeDIST,

public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text,
int countD, int countM, int countV, int pos)
throws RecognitionException

{
CommonTree tree1 = (CommonTree)ctDir;
Expand All @@ -108,13 +101,13 @@ public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object
text, countM, countD, countV, pos);

if( countM == 0 )
return buildErrorTree(text, ERR_MEAS_NULL, typeDIST, pos);
return buildErrorTree(text, StatusCodes.ERR_PROX_MEAS_NULL, typeDIST, pos);
if( countM > 1 )
return buildErrorTree(text, ERR_MEAS_TOOGREAT, typeDIST, pos);
return buildErrorTree(text, StatusCodes.ERR_PROX_MEAS_TOOGREAT, typeDIST, pos);
if( countV == 0 )
return buildErrorTree(text, ERR_VAL_NULL, typeDIST, pos);
return buildErrorTree(text, StatusCodes.ERR_PROX_VAL_NULL, typeDIST, pos);
if( countV > 1 )
return buildErrorTree(text, ERR_VAL_TOOGREAT, typeDIST, pos);
return buildErrorTree(text, StatusCodes.ERR_PROX_VAL_TOOGREAT, typeDIST, pos);

if( countD == 0 )
{
Expand All @@ -128,7 +121,7 @@ public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object
tree1 = treeDIR;
}
else if( countD > 1 )
return buildErrorTree(text, ERR_DIR_TOOGREAT, typeDIST, pos);
return buildErrorTree(text, StatusCodes.ERR_PROX_DIR_TOOGREAT, typeDIST, pos);

// create DIST tree:
CommonTree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private boolean reportErrorsinTree(Tree node)
int
errPos = node.getChild(0) != null ? Integer.parseInt(node.getChild(0).getText()) : 0;
int
errCode = node.getChild(1) != null ? Integer.parseInt(node.getChild(1).getText()) : c2ps_opPROX.ERR_PROX_UNKNOWN;
errCode = node.getChild(1) != null ? Integer.parseInt(node.getChild(1).getText()) : StatusCodes.ERR_PROX_UNKNOWN;
String
errMess = node.getChild(2) != null ? node.getChild(2).getText() : "Genaue Fehlermeldung nicht auffindbar.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ public class StatusCodes {
public final static int QUERY_TOO_COMPLEX = 311;
public final static int UNKNOWN_QUERY_ERROR = 399;
public final static int SERIALIZATION_FAILED = 300;

// error codes for PROX syntax errors:
final public static int ERR_PROX_UNKNOWN = 320;
public final static int ERR_PROX_MEAS_NULL = 321;
public final static int ERR_PROX_MEAS_TOOGREAT = 322;
public final static int ERR_PROX_VAL_NULL = 323;
public final static int ERR_PROX_VAL_TOOGREAT = 324;
public final static int ERR_PROX_DIR_TOOGREAT = 325;
}

0 comments on commit 78e828c

Please sign in to comment.