From 056f0db0d5a70b39e62b2b7dae9034154523fa4c Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 11 Jan 2013 11:12:53 +0000 Subject: [PATCH] Allow function calls as enumeration indexes (fixes #3977) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26600 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../expressionParser/ExpressionParser.java | 99 ++++++++++++------- .../expressionParser/ExpressionParser.jj | 20 +++- .../ExpressionParserTokenManager.java | 5 + 3 files changed, 86 insertions(+), 38 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 74bd7544..f833fdbd 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java @@ -1,6 +1,8 @@ /* Generated By:JavaCC: Do not edit this line. ExpressionParser.java */ package org.simantics.sysdyn.expressionParser; +import java.util.Set; +import java.util.HashSet; import java.util.List; import java.util.ArrayList; import java.util.HashMap; @@ -798,33 +800,48 @@ void named_arguments() : { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 67: jj_consume_token(67); - currentRange.add(token); + currentRange.add(token); break; - case IDENT: - case UNSIGNED_INTEGER: - rangeIndex(rangeToken, false); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 67: - jj_consume_token(67); - rangeIndex(rangeToken, true); - break; - default: - jj_la1[36] = jj_gen; - ; - } + default: + jj_la1[37] = jj_gen; + if (jj_2_3(2147483647)) { + functionCall = null; + name(); + function_call_args(); + functionCall = null; + rangeToken.image = ""; + rangeToken.endColumn = token.endColumn; + rangeToken.endLine = token.endLine; + currentRange.add(rangeToken); + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case IDENT: + case UNSIGNED_INTEGER: + rangeIndex(rangeToken, true); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 67: + jj_consume_token(67); + rangeIndex(rangeToken, false); + break; + default: + jj_la1[36] = jj_gen; + ; + } rangeToken.endColumn = token.endColumn; rangeToken.endLine = token.endLine; currentRange.add(rangeToken); - break; - default: - jj_la1[37] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); + break; + default: + jj_la1[38] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } } } - final public void rangeIndex(Token rangeToken, boolean second) throws ParseException { - if(second) + final public void rangeIndex(Token rangeToken, boolean first) throws ParseException { + if(!first) rangeToken.image = rangeToken.image + ":"; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case UNSIGNED_INTEGER: @@ -836,7 +853,7 @@ void named_arguments() : { rangeToken.image = rangeToken.image + token.image; break; default: - jj_la1[38] = jj_gen; + jj_la1[39] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -856,6 +873,13 @@ void named_arguments() : { finally { jj_save(1, xla); } } + private boolean jj_2_3(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_3(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + private boolean jj_3R_14() { if (jj_scan_token(66)) return true; if (jj_3R_12()) return true; @@ -887,6 +911,12 @@ void named_arguments() : { return false; } + private boolean jj_3_3() { + if (jj_3R_12()) return true; + if (jj_scan_token(60)) return true; + return false; + } + /** Generated Token Manager. */ public ExpressionParserTokenManager token_source; SimpleCharStream jj_input_stream; @@ -898,7 +928,7 @@ void named_arguments() : { private Token jj_scanpos, jj_lastpos; private int jj_la; private int jj_gen; - final private int[] jj_la1 = new int[39]; + final private int[] jj_la1 = new int[40]; static private int[] jj_la1_0; static private int[] jj_la1_1; static private int[] jj_la1_2; @@ -908,15 +938,15 @@ void named_arguments() : { 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,0x0,0x200000,0x200000,0x80001040,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,0x0,}; } private static void jj_la1_init_1() { - jj_la1_1 = new int[] {0x0,0x5000000a,0x0,0x5000000a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x50000008,0x0,0x0,0x0,0x5000000a,0x0,0x0,0x0,0x5000000a,0x0,0x200,0x5000000a,0x0,0x5000000a,0x0,0x0,0x0,0x0,0x0,}; + jj_la1_1 = new int[] {0x0,0x5000000a,0x0,0x5000000a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x50000008,0x0,0x0,0x0,0x5000000a,0x0,0x0,0x0,0x5000000a,0x0,0x200,0x5000000a,0x0,0x5000000a,0x0,0x0,0x0,0x0,0x0,0x0,}; } private static void jj_la1_init_2() { - jj_la1_2 = new int[] {0x0,0xf00f001,0x0,0xf00f001,0x8,0x8,0x0,0x0,0x0,0xfc0,0xfc0,0xf000,0xf000,0xf000,0xf0000,0x300000,0x300000,0xf0000,0x10,0xe000000,0x1000001,0x4,0x1,0x4,0xf00f001,0x20,0x20,0x20,0xf00f001,0x20,0x0,0xf00f001,0x20,0xf00f001,0x20,0x20,0x8,0x5000008,0x5000000,}; + jj_la1_2 = new int[] {0x0,0xf00f001,0x0,0xf00f001,0x8,0x8,0x0,0x0,0x0,0xfc0,0xfc0,0xf000,0xf000,0xf000,0xf0000,0x300000,0x300000,0xf0000,0x10,0xe000000,0x1000001,0x4,0x1,0x4,0xf00f001,0x20,0x20,0x20,0xf00f001,0x20,0x0,0xf00f001,0x20,0xf00f001,0x20,0x20,0x8,0x8,0x5000000,0x5000000,}; } - final private JJCalls[] jj_2_rtns = new JJCalls[2]; + final private JJCalls[] jj_2_rtns = new JJCalls[3]; private boolean jj_rescan = false; private int jj_gc = 0; @@ -931,7 +961,7 @@ void named_arguments() : { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < 40; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -946,7 +976,7 @@ void named_arguments() : { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < 40; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -957,7 +987,7 @@ void named_arguments() : { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < 40; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -968,7 +998,7 @@ void named_arguments() : { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < 40; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -978,7 +1008,7 @@ void named_arguments() : { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < 40; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -988,7 +1018,7 @@ void named_arguments() : { token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 39; i++) jj_la1[i] = -1; + for (int i = 0; i < 40; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -1105,7 +1135,7 @@ void named_arguments() : { la1tokens[jj_kind] = true; jj_kind = -1; } - for (int i = 0; i < 39; i++) { + for (int i = 0; i < 40; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1< currentRange) : { Token rangeToken = new Token(token.kind, ""); rangeToken.beginColumn = token.beginColumn + 1; rangeToken.beginLine = token.beginLine; -} { ":" { currentRange.add(token); +} { ":" { currentRange.add(token); } - | rangeIndex(rangeToken, false) ( ":" rangeIndex(rangeToken, true))? { + | LOOKAHEAD( name() "(" ) + { + functionCall = null; + } + name() function_call_args() + { + functionCall = null; + rangeToken.image = ""; + rangeToken.endColumn = token.endColumn; + rangeToken.endLine = token.endLine; + currentRange.add(rangeToken); + } + | rangeIndex(rangeToken, true) ( ":" rangeIndex(rangeToken, false))? { rangeToken.endColumn = token.endColumn; rangeToken.endLine = token.endLine; currentRange.add(rangeToken); } } -void rangeIndex(Token rangeToken, boolean second) : { - if(second) +void rangeIndex(Token rangeToken, boolean first) : { + if(!first) rangeToken.image = rangeToken.image + ":"; } { { rangeToken.image = rangeToken.image + token.image; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserTokenManager.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserTokenManager.java index c32723e2..7c7a5cfc 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserTokenManager.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParserTokenManager.java @@ -1,5 +1,10 @@ /* Generated By:JavaCC: Do not edit this line. ExpressionParserTokenManager.java */ package org.simantics.sysdyn.expressionParser; +import java.util.Set; +import java.util.HashSet; +import java.util.List; +import java.util.ArrayList; +import java.util.HashMap; /** Token Manager. */ public class ExpressionParserTokenManager implements ExpressionParserConstants -- 2.47.1