Skip to content

Commit

Permalink
Prox...
Browse files Browse the repository at this point in the history
Change-Id: I4287658e0157593eb934fe1723df8ea1bb4fdc26
  • Loading branch information
Bodmo committed Dec 20, 2023
1 parent fe13cc4 commit 0711f07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
21 changes: 6 additions & 15 deletions src/main/antlr/cosmas/c2ps_opPROX.g
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,16 @@ proxDist: proxDirection (v1=proxDistValue m1=proxMeasure | m2=proxMeasure v2=pro
*/

// new rule: accepts options in any order:
// but how to handle multiple values for those options?
// count each option type and find out if any one is missing or occures multiple times.
// 28.11.23/FB

proxDist
@init{ int countM=0;}
@init{ int countM=0; int countD=0; int countV=0;}
:
//((m=proxMeasure {countM++;})|d=proxDirection|v=proxDistValue)+ {countM == 1}?

((m=proxMeasure {countM++;})|d=proxDirection|v=proxDistValue)+

-> {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text, countM)};
(m=proxMeasure {countM++;}|d=proxDirection {countD++;}|v=proxDistValue {countV++;} )+

-> {c2ps_opPROX.encodeDIST(DIST, DIR, $d.tree, $m.tree, $v.tree, $proxDist.text, $proxDist.index, countD, countM, countV)};

// -> {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.
Expand All @@ -117,12 +114,6 @@ proxDistValue : (m1=proxDistMin ) (':' m2=proxDistMax)?
-> {$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)} ? ^(MEAS $meas) ;
*/

// mentioning >1 measures will be checked/rejected in c2ps_opPROX.encodeDIST().

proxMeasure
Expand All @@ -137,4 +128,4 @@ proxDistMax
proxGroup
: 'min' -> ^(GRP MIN)
| 'max' -> ^(GRP MAX);


Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ private static boolean duplicateOptions(String text)
* 28.11.23/FB
*/

public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text, int countM)
//throws C2RecognitionException
public static Object encodeDIST(int typeDIST, int typeDIR, Object ctDir, Object ctMeas, Object ctVal, String text, int start,
int countD, int countM, int countV)

{
boolean multiple = false;
CommonTree tree1 = (CommonTree)ctDir;
CommonTree tree2 = (CommonTree)ctMeas;
CommonTree tree3 = (CommonTree)ctVal;

System.err.printf("Debug: encodeDIST: scanned input='%s' countM=%d.\n", text, countM);
//String text = "for debugging only";
int pos = -1;
System.err.printf("Debug: encodeDIST: scanned input='%s' start=%d countM=%d countD=%d countV=%d.\n",
text, start, countM, countD, countV);


if( duplicateOptions(text) == true )
{
CommonTree errorTree, errorNode, errorPos, errorArg, errorMes;
Expand Down

0 comments on commit 0711f07

Please sign in to comment.