From 8ae2553d2c8658afe505b6a09857330be5de0f5f Mon Sep 17 00:00:00 2001 From: lempinen Date: Mon, 8 Aug 2011 10:47:43 +0000 Subject: [PATCH] git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@21689 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../expressionParser/ExpressionParser.java | 523 ++++-------------- 1 file changed, 101 insertions(+), 422 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java index ba268eda..fc72235a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java @@ -54,6 +54,17 @@ public class ExpressionParser implements ExpressionParserConstants { return enumerationReferences; } +/* + Collect EACH function call and all references that are inside the call brackets. + These are later used to exclude spread sheet references out of the normal functions. +*/ + String functionCall = null; + HashMap> functionCallReferences = new HashMap>(); + + public HashMap> getFunctionCallReferences() { + return functionCallReferences; + } + /*** Parser ********************************************************/ // https://javacc.dev.java.net/doc/javaccgrm.html @@ -413,8 +424,10 @@ public class ExpressionParser implements ExpressionParserConstants { default: jj_la1[19] = jj_gen; if (jj_2_1(2147483647)) { + functionCall = null; name(); function_call_args(); + functionCall = null; } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IDENT: @@ -462,6 +475,10 @@ public class ExpressionParser implements ExpressionParserConstants { final public void name() throws ParseException { jj_consume_token(IDENT); + if (functionCall == null) + functionCall = token.image; + else + functionCall += "." + token.image; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 68: jj_consume_token(68); @@ -476,21 +493,23 @@ public class ExpressionParser implements ExpressionParserConstants { final public void component_reference(String prevToken) throws ParseException { jj_consume_token(IDENT); String name = token.image; - // prevToken != null => this is the second part of an enumeration - if(forIndex == true && prevToken != null) { - if(enumerationReferences.get(prevToken) == null) { - enumerationReferences.put(prevToken, new ArrayList()); - } - List list = enumerationReferences.get(prevToken); - list.add(token); - - // forIndex == true, prevToken == null => this is the enumeration - } else if(forIndex == true && prevToken == null) { - if(enumerationReferences.get(name) == null) { - enumerationReferences.put(name, new ArrayList()); - } - List list = enumerationReferences.get(name); - list.add(token); + // forIndex == true and prevToken != null => this is the second part of an enumeration in for-index + if(forIndex == true) { + if(prevToken != null) { + if(enumerationReferences.get(prevToken) == null) { + enumerationReferences.put(prevToken, new ArrayList()); + } + List list = enumerationReferences.get(prevToken); + list.add(token); + + // forIndex == true and prevToken == null => this is the enumeration in for-index + } else { + if(enumerationReferences.get(name) == null) { + enumerationReferences.put(name, new ArrayList()); + } + List list = enumerationReferences.get(name); + list.add(token); + } } else { if(prevToken != null) name = prevToken + "." + name; @@ -499,6 +518,13 @@ public class ExpressionParser implements ExpressionParserConstants { } List list = references.get(name); list.add(token); + + if(functionCall != null) { + if(!functionCallReferences.containsKey(functionCall)) + functionCallReferences.put(functionCall, new ArrayList()); + List functionReferencelist = getFunctionCallReferences().get(functionCall); + functionReferencelist.add(token); + } } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 66: @@ -549,36 +575,60 @@ public class ExpressionParser implements ExpressionParserConstants { final public void function_arguments() throws ParseException { if (jj_2_2(2)) { - expression(); + named_argument(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 21: case 71: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 71: - jj_consume_token(71); - function_arguments(); - break; - case 21: - jj_consume_token(21); - for_indices(); - break; - default: - jj_la1[25] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + jj_consume_token(71); + function_arguments(); break; default: - jj_la1[26] = jj_gen; + jj_la1[25] = jj_gen; ; } } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 6: + case 12: + case 31: + case 33: + case 35: + case 62: + case 64: + case 66: + case 78: + case 79: + case 80: + case 81: case IDENT: - named_arguments(); + case STRING: + case UNSIGNED_INTEGER: + case UNSIGNED_NUMBER: + expression(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 21: + case 71: + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 71: + jj_consume_token(71); + function_arguments(); + break; + case 21: + jj_consume_token(21); + for_indices(); + break; + default: + jj_la1[26] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + default: + jj_la1[27] = jj_gen; + ; + } break; default: - jj_la1[27] = jj_gen; + jj_la1[28] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -594,7 +644,7 @@ public class ExpressionParser implements ExpressionParserConstants { ; break; default: - jj_la1[28] = jj_gen; + jj_la1[29] = jj_gen; break label_8; } jj_consume_token(71); @@ -616,26 +666,19 @@ public class ExpressionParser implements ExpressionParserConstants { forRange.end = token; forRanges.add(forRange); break; - default: - jj_la1[29] = jj_gen; - ; - } - forIndex = false; - } - - final public void named_arguments() throws ParseException { - named_argument(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 71: - jj_consume_token(71); - named_arguments(); - break; default: jj_la1[30] = jj_gen; ; } + forIndex = false; } +/* Removed by Teemu. Refactored in function_arguments) +void named_arguments() : { +} { + named_argument() ( "," named_arguments() )? +} +*/ final public void named_argument() throws ParseException { jj_consume_token(IDENT); jj_consume_token(88); @@ -810,398 +853,34 @@ public class ExpressionParser implements ExpressionParserConstants { finally { jj_save(1, xla); } } - private boolean jj_3R_35() { - if (jj_3R_37()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_38()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_52() { - if (jj_scan_token(68)) return true; - return false; - } - - private boolean jj_3R_31() { - if (jj_3R_35()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_36()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_34() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(78)) { - jj_scanpos = xsp; - if (jj_scan_token(79)) { - jj_scanpos = xsp; - if (jj_scan_token(80)) { - jj_scanpos = xsp; - if (jj_scan_token(81)) return true; - } - } - } - return false; - } - - private boolean jj_3R_26() { - if (jj_scan_token(9)) return true; - return false; - } - - private boolean jj_3R_30() { - if (jj_3R_34()) return true; - return false; - } - - private boolean jj_3R_55() { - if (jj_3R_57()) return true; - return false; - } - - private boolean jj_3R_28() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_30()) jj_scanpos = xsp; - if (jj_3R_31()) return true; - while (true) { - xsp = jj_scanpos; - if (jj_3R_32()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_33() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(72)) { - jj_scanpos = xsp; - if (jj_scan_token(73)) { - jj_scanpos = xsp; - if (jj_scan_token(74)) { - jj_scanpos = xsp; - if (jj_scan_token(75)) { - jj_scanpos = xsp; - if (jj_scan_token(76)) { - jj_scanpos = xsp; - if (jj_scan_token(77)) return true; - } - } - } - } - } - return false; - } - - private boolean jj_3R_50() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_2()) { - jj_scanpos = xsp; - if (jj_3R_55()) return true; - } - return false; - } - - private boolean jj_3_2() { - if (jj_3R_13()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_14()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_22() { - if (jj_scan_token(69)) return true; - return false; - } - - private boolean jj_3R_24() { - if (jj_scan_token(22)) return true; - return false; - } - - private boolean jj_3R_27() { - if (jj_3R_28()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_29()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_46() { - if (jj_scan_token(62)) return true; - return false; - } - - private boolean jj_3R_25() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(12)) jj_scanpos = xsp; - if (jj_3R_27()) return true; - return false; - } - - private boolean jj_3R_51() { - if (jj_3R_56()) return true; - return false; - } - - private boolean jj_3R_23() { - if (jj_3R_25()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_26()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_21() { - if (jj_3R_23()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_24()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_20() { - if (jj_3R_21()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_22()) jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_17() { - if (jj_scan_token(31)) return true; - if (jj_3R_13()) return true; - return false; - } - - private boolean jj_3R_54() { - if (jj_scan_token(71)) return true; - return false; - } - - private boolean jj_3R_13() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_16()) { - jj_scanpos = xsp; - if (jj_3R_17()) return true; - } - return false; - } - - private boolean jj_3R_16() { - if (jj_3R_20()) return true; - return false; - } - - private boolean jj_3R_56() { - if (jj_scan_token(66)) return true; - return false; - } - - private boolean jj_3R_15() { + private boolean jj_3R_14() { if (jj_scan_token(68)) return true; if (jj_3R_12()) return true; return false; } - private boolean jj_3R_19() { - if (jj_scan_token(21)) return true; - return false; - } - - private boolean jj_3R_47() { + private boolean jj_3R_13() { if (jj_scan_token(IDENT)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_51()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_52()) jj_scanpos = xsp; + if (jj_scan_token(88)) return true; return false; } - private boolean jj_3R_53() { - if (jj_3R_13()) return true; - return false; - } - - private boolean jj_3R_49() { + private boolean jj_3_2() { if (jj_3R_13()) return true; return false; } - private boolean jj_3R_48() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_53()) jj_scanpos = xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_54()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3R_12() { - if (jj_scan_token(IDENT)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_15()) jj_scanpos = xsp; - return false; - } - private boolean jj_3_1() { if (jj_3R_12()) return true; if (jj_scan_token(62)) return true; return false; } - private boolean jj_3R_58() { + private boolean jj_3R_12() { if (jj_scan_token(IDENT)) return true; - return false; - } - - private boolean jj_3R_45() { - if (jj_scan_token(87)) return true; - return false; - } - - private boolean jj_3R_57() { - if (jj_3R_58()) return true; - return false; - } - - private boolean jj_3R_44() { - if (jj_scan_token(64)) return true; - if (jj_3R_50()) return true; - return false; - } - - private boolean jj_3R_43() { - if (jj_scan_token(66)) return true; - if (jj_3R_49()) return true; - return false; - } - - private boolean jj_3R_40() { - if (jj_3R_12()) return true; - if (jj_3R_46()) return true; - return false; - } - - private boolean jj_3R_42() { - if (jj_scan_token(62)) return true; - if (jj_3R_48()) return true; - if (jj_scan_token(63)) return true; - return false; - } - - private boolean jj_3R_38() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(86)) { - jj_scanpos = xsp; - if (jj_3R_45()) return true; - } - return false; - } - - private boolean jj_3R_41() { - if (jj_3R_47()) return true; - return false; - } - - private boolean jj_3R_37() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(93)) { - jj_scanpos = xsp; - if (jj_scan_token(92)) { - jj_scanpos = xsp; - if (jj_scan_token(91)) { - jj_scanpos = xsp; - if (jj_scan_token(6)) { - jj_scanpos = xsp; - if (jj_scan_token(33)) { - jj_scanpos = xsp; - if (jj_3R_40()) { - jj_scanpos = xsp; - if (jj_3R_41()) { - jj_scanpos = xsp; - if (jj_3R_42()) { - jj_scanpos = xsp; - if (jj_3R_43()) { - jj_scanpos = xsp; - if (jj_3R_44()) { - jj_scanpos = xsp; - if (jj_scan_token(35)) return true; - } - } - } - } - } - } - } - } - } - } - return false; - } - - private boolean jj_3R_18() { - if (jj_scan_token(71)) return true; - return false; - } - - private boolean jj_3R_14() { Token xsp; xsp = jj_scanpos; - if (jj_3R_18()) { - jj_scanpos = xsp; - if (jj_3R_19()) return true; - } - return false; - } - - private boolean jj_3R_36() { - if (jj_3R_39()) return true; - return false; - } - - private boolean jj_3R_29() { - if (jj_3R_33()) return true; - return false; - } - - private boolean jj_3R_32() { - if (jj_3R_34()) return true; - return false; - } - - private boolean jj_3R_39() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(82)) { - jj_scanpos = xsp; - if (jj_scan_token(83)) { - jj_scanpos = xsp; - if (jj_scan_token(84)) { - jj_scanpos = xsp; - if (jj_scan_token(85)) return true; - } - } - } + if (jj_3R_14()) jj_scanpos = xsp; return false; } @@ -1226,13 +905,13 @@ public class ExpressionParser implements ExpressionParserConstants { jj_la1_init_2(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x100000,0x80001040,0x100000,0x80001040,0x0,0x0,0x400000,0x200,0x1000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x80001040,0x200000,0x200000,0x0,0x0,0x0,0x0,0x80001040,0x0,0x80001040,0x0,0x0,0x0,0x0,0x0,}; + jj_la1_0 = new int[] {0x100000,0x80001040,0x100000,0x80001040,0x0,0x0,0x400000,0x200,0x1000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x80001040,0x0,0x200000,0x200000,0x80001040,0x0,0x0,0x80001040,0x0,0x80001040,0x0,0x0,0x0,0x0,0x0,}; } private static void jj_la1_init_1() { - jj_la1_1 = new int[] {0x0,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x40000008,0x0,0x0,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x200,0x0,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,}; + jj_la1_1 = new int[] {0x0,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x40000008,0x0,0x0,0x0,0x4000000a,0x0,0x0,0x0,0x4000000a,0x0,0x200,0x4000000a,0x0,0x4000000a,0x0,0x0,0x0,0x0,0x0,}; } private static void jj_la1_init_2() { - jj_la1_2 = new int[] {0x0,0x3c03c005,0x0,0x3c03c005,0x20,0x20,0x0,0x0,0x0,0x3f00,0x3f00,0x3c000,0x3c000,0x3c000,0x3c0000,0xc00000,0xc00000,0x3c0000,0x40,0x38000000,0x4000005,0x10,0x4,0x10,0x3c03c005,0x80,0x80,0x4000000,0x80,0x0,0x80,0x3c03c005,0x80,0x3c03c005,0x80,0x80,0x20,0x14000020,0x14000000,}; + jj_la1_2 = new int[] {0x0,0x3c03c005,0x0,0x3c03c005,0x20,0x20,0x0,0x0,0x0,0x3f00,0x3f00,0x3c000,0x3c000,0x3c000,0x3c0000,0xc00000,0xc00000,0x3c0000,0x40,0x38000000,0x4000005,0x10,0x4,0x10,0x3c03c005,0x80,0x80,0x80,0x3c03c005,0x80,0x0,0x3c03c005,0x80,0x3c03c005,0x80,0x80,0x20,0x14000020,0x14000000,}; } final private JJCalls[] jj_2_rtns = new JJCalls[2]; private boolean jj_rescan = false; -- 2.47.1