@@ -1223,6 +1223,7 @@ else if (t2 == null)
12231223 }
12241224 }
12251225 }
1226+
12261227 if (tt == null )
12271228 { System .err .println ("!!ERROR!!: Invalid map/function type, it must have 2 type arguments: " + showLexicals (st ,en ));
12281229 return null ;
@@ -3084,14 +3085,15 @@ public Expression parse_basic_expression(int bc, int pstart, int pend, Vector en
30843085
30853086 if (pstart < pend && "]" .equals (lexicals .get (pend ) + "" ) &&
30863087 "[" .equals (lexicals .get (pstart +1 ) + "" ))
3087- { String ss = lexicals .elementAt (pstart ).toString ();
3088+ { // iden[indexes]
3089+
3090+ String ss = lexicals .elementAt (pstart ).toString ();
30883091 BasicExpression ee = new BasicExpression (ss ,0 );
30893092 Expression op = ee .checkIfSetExpression ();
30903093 // Expression op = parse_basic_expression(bc,pstart,pstart);
30913094 Expression arg = parse_additive_expression (bc ,pstart +2 ,pend -1 ,entities ,types );
30923095 if (arg == null )
3093- { // System.err.println("ERROR: Invalid array argument: " + showLexicals(pstart+2,pend-1));
3094- Vector args = parse_array_index_sequence (bc ,pstart +2 ,pend -1 ,entities ,types );
3096+ { Vector args = parse_array_index_sequence (bc ,pstart +2 ,pend -1 ,entities ,types );
30953097 if (args != null )
30963098 { Expression opx = defineArrayIndex (op ,args ,entities ,types );
30973099 System .out .println (">>> Array index sequence: " + args + " for " + opx );
@@ -3108,19 +3110,30 @@ else if (op != null && op instanceof BasicExpression) // must be
31083110 }
31093111
31103112 if (pstart < pend && "]" .equals (lexicals .get (pend -1 ) + "" ) &&
3111- "[" .equals (lexicals .get (pstart +1 ) + "" )) // be[arrind].be2
3112- { String tail = lexicals .get (pend ) + "" ;
3113+ "[" .equals (lexicals .get (pstart +1 ) + "" ) &&
3114+ (lexicals .get (pend ) + "" ).charAt (0 ) == '.' )
3115+ { // be[inds].f
3116+
3117+ String tail = lexicals .get (pend ) + "" ;
31133118 if (tail .charAt (0 ) == '.' )
31143119 { tail = tail .substring (1 ,tail .length ()); }
3120+
31153121 Expression op = parse_basic_expression (bc ,pstart ,pstart ,entities ,types );
31163122 Expression arg = parse_additive_expression (bc ,pstart +2 ,pend -2 ,entities ,types );
31173123 if (arg == null )
31183124 { // System.err.println("ERROR: Invalid array argument: " + showLexicals(pstart+2,pend-2));
3125+ /* Vector args = parse_array_index_sequence(bc,pstart+2,pend-2,entities,types);
3126+ if (args != null)
3127+ { Expression opx = defineArrayIndex(op,args,entities,types);
3128+ System.out.println(">>> Array index sequence: " + args + " for " + opx);
3129+ return opx;
3130+ } */
31193131 }
31203132 else if (op != null && op instanceof BasicExpression ) // must be
31213133 { BasicExpression beop = (BasicExpression ) op ;
31223134 beop .setArrayIndex (arg );
3123- BasicExpression te = // new BasicExpression(ss,0); // (ss) surely?
3135+ BasicExpression te =
3136+ // new BasicExpression(ss,0); // (ss) surely?
31243137 new BasicExpression (tail ,0 );
31253138 Expression ef = te .checkIfSetExpression ();
31263139 if (ef != null && (ef instanceof BasicExpression ))
@@ -3176,8 +3189,8 @@ else if (op != null && op instanceof BasicExpression) // must be
31763189 if (ve != null )
31773190 { BasicExpression beop = (BasicExpression ) op ;
31783191 String tail = strs .substring (1 ,strs .length ());
3179- BasicExpression rees = new BasicExpression (tail , 0 );
3180- rees .setObjectRef (beop );
3192+ BasicExpression rees = new BasicExpression (tail , 0 );
3193+ rees .setObjectRef (beop );
31813194 rees .setIsEvent ();
31823195 rees .setParameters (ve );
31833196 System .out .println ("*** Parsed extended call expression " + rees );
@@ -3188,37 +3201,52 @@ else if (op != null && op instanceof BasicExpression) // must be
31883201 }
31893202 }
31903203
3191- /* if (pstart < pend &&
3192- "[".equals(lexicals.get(pstart+1) + "")) // be[arrind].something
3193- { for (int k = pstart + 2; k < pend; k++)
3194- { String kstring = lexicals.get(k) + "";
3195- if ("]".equals(kstring))
3196- { Expression op = parse_basic_expression(bc,pstart,pstart);
3197- Expression arg = parse_factor_expression(bc,pstart+2,k-1);
3204+ if (pstart < pend &&
3205+ "[" .equals (lexicals .get (pstart +1 ) + "" ) &&
3206+ "]" .equals (lexicals .get (pend -1 ) + "" ) &&
3207+ (lexicals .get (pend ) + "" ).charAt (0 ) == '.' )
3208+ { // iden[ ... ].f valid basic expression before .f
3209+
3210+ Expression op = parse_basic_expression (
3211+ bc ,pstart ,pend -1 ,entities ,types );
3212+ String tail = lexicals .get (pend ) + "" ;
3213+ if (tail .charAt (0 ) == '.' )
3214+ { tail = tail .substring (1 ,tail .length ()); }
3215+
3216+ if (op instanceof BasicExpression ) // must be
3217+ { BasicExpression beop = (BasicExpression ) op ;
3218+ BasicExpression rees = new BasicExpression (tail , 0 );
3219+ rees .setObjectRef (beop );
3220+ System .out .println (">>> Parsed array 2 expression: " + rees );
3221+ return rees ;
3222+ }
3223+ // return null;
3224+ }
3225+
3226+ if (pstart + 1 < pend &&
3227+ "]" .equals (lexicals .get (pend ) + "" ))
3228+ { // be [ ind ] valid basic expression be
3229+
3230+ for (int k = pend -1 ; k >= pstart ; k --)
3231+ { String lex = lexicals .get (k ) + "" ;
3232+ if ("[" .equals (lex ))
3233+ { Expression op = parse_basic_expression (
3234+ bc ,pstart ,k -1 ,entities ,types );
31983235
3199- String tail = lexicals.get(k+1) + "";
3200- if (tail.charAt(0) == '.')
3201- { tail = tail.substring(1,tail.length()); }
32023236 if (op instanceof BasicExpression ) // must be
32033237 { BasicExpression beop = (BasicExpression ) op ;
3204- beop.setArrayIndex(arg);
3205- Expression te = parse_basic_expression(bc,k+1,pend);
3206- if (te != null)
3207- { if (te instanceof BasicExpression)
3208- { BasicExpression bte = (BasicExpression) te;
3209- bte.setData(tail);
3210- bte.setObjectRef(beop);
3211- System.out.println("Parsed array 2 expression: " + bte);
3212- return bte;
3213- }
3214- else
3215- { return null; }
3216- }
3217- }
3218- }
3219- }
3220- return null;
3221- } */
3238+ Expression arg = parse_additive_expression (
3239+ bc ,k +1 ,pend -1 ,entities ,types );
3240+ if (arg != null && beop .arrayIndex == null )
3241+ { beop .setArrayIndex (arg );
3242+ System .out .println (">>> Parsed array 3 expression: " + beop );
3243+ return beop ;
3244+ }
3245+ }
3246+ }
3247+ }
3248+ // return null;
3249+ }
32223250
32233251 if (pstart + 2 < pend )
32243252 { for (int i = pstart + 1 ; i < pend ; i ++)
@@ -5043,10 +5071,6 @@ public static String isKeywordOrPart(String st, String[] mess)
50435071 return "then" ;
50445072 }
50455073
5046- if ("else" .startsWith (st ))
5047- { mess [0 ] = "else part of if-expression or if-statement" ;
5048- return "else" ;
5049- }
50505074
50515075 if ("while" .startsWith (st ))
50525076 { mess [0 ] = "Unbounded loop statement: while expr do statement\n Can only be used in an activity" ;
@@ -5136,6 +5160,13 @@ public static String isKeywordOrPart(String st, String[] mess)
51365160 return "assert" ;
51375161 }
51385162
5163+ if (st .length () > 2 )
5164+ { if ("else" .startsWith (st ))
5165+ { mess [0 ] = "else part of if-expression or if-statement" ;
5166+ return "else" ;
5167+ }
5168+ }
5169+
51395170 if (st .length () > 3 )
51405171 { if ("reference" .startsWith (st ))
51415172 { mess [0 ] = "reference declaration, eg: reference name : Type;\n Type is a class type or collection (of class element type)" ;
@@ -5235,6 +5266,18 @@ public static String isKeywordOrPart(String st, String[] mess)
52355266 return "arg->reverse()" ;
52365267 }
52375268
5269+ if ("->restrict" .startsWith (st ))
5270+ { mess [0 ] = "arg->restrict(keys) operator on maps.\n " +
5271+ "Returns submap of arg: elements with key in keys" ;
5272+ return "arg->restrict(keys)" ;
5273+ }
5274+
5275+ if ("->antirestrict" .startsWith (st ))
5276+ { mess [0 ] = "arg->antirestrict(keys) operator on maps.\n " +
5277+ "Returns submap of arg: elements with key not in keys" ;
5278+ return "arg->antirestrict(keys)" ;
5279+ }
5280+
52385281 if ("->first" .startsWith (st ))
52395282 { mess [0 ] = "arg->first() operator on non-empty strings, sequences\n " +
52405283 "Returns arg->at(1)" ;
@@ -9724,7 +9767,7 @@ public static void main(String[] args)
97249767 // Type xx = c.parseType(0,c.lexicals.size()-1,exs, new Vector());
97259768
97269769 // c.nospacelexicalanalysis("arr[x][y]");
9727- c .nospacelexicalanalysis ("(OclFile.newOclFile( \" (text) \" )).setReadOnly() " );
9770+ c .nospacelexicalanalysis ("Worksheets[Y].Range[X].Value " );
97289771 // c.nospacelexicalanalysis("(OclFile.newOclFile_Read(OclFile.newOclFile(s))).readObject()");
97299772
97309773 // c.nospacelexicalanalysis("(MyString).subrange((MyString)->indexOf((MyString)->trim()))");
0 commit comments