}\r
return result;\r
}\r
- \r
- \r
+\r
+\r
public static String rangeToIndexes(Variable variable, String range) {\r
- if(variable == null)\r
- return range;\r
+ if(variable == null)\r
+ return range;\r
StringBuilder sb = new StringBuilder();\r
ArrayIndexes arrayIndexes = variable.getArrayIndexes();\r
if(arrayIndexes == null || range == null)\r
else\r
sb.append(rangeToken);\r
}\r
- \r
+\r
}\r
return sb.toString();\r
}\r
- \r
+\r
private static String fixForRangeEnumerations(Variable variable, String equation) {\r
- ExpressionParser parser = new ExpressionParser(new StringReader(equation));\r
- try {\r
- parser.expr();\r
- for(ForRange forRange : parser.getForRanges()) {\r
- if(forRange.start.equals(forRange.end)) {\r
- Variable v = getVariable(variable.getParentConfiguration(), forRange.start.image);\r
- if(v instanceof Enumeration) {\r
- equation = equation.replaceAll("in[\\s]*" + forRange.start.image + "($|[^\\.])", "in " + forRange.start.image + ".elements$1");\r
- }\r
- }\r
- }\r
- } catch (ParseException e) {\r
+ ExpressionParser parser = new ExpressionParser(new StringReader(equation));\r
+ try {\r
+ parser.expr();\r
+ for(ForRange forRange : parser.getForRanges()) {\r
+ if(forRange.start.equals(forRange.end)) {\r
+ Variable v = getVariable(variable.getParentConfiguration(), forRange.start.image);\r
+ if(v instanceof Enumeration) {\r
+ equation = equation.replaceAll("in[\\s]*" + forRange.start.image + "($|[^\\.])", "in " + forRange.start.image + ".elements$1");\r
+ }\r
+ }\r
+ }\r
+ } catch (ParseException e) {\r
e.printStackTrace();\r
}\r
return equation;\r
}\r
- \r
+\r
public static String equationRangesToIndexes(Variable variable, String equation) {\r
- if(equation == null || !equation.contains("[")) return equation;\r
- \r
- StringBuilder result = new StringBuilder();\r
- String delimiters = "+-*/(){}[],. ";\r
- StringTokenizer st = new StringTokenizer(equation, delimiters, true);\r
- String prevToken = st.nextToken();\r
- result.append(prevToken);\r
- while (st.hasMoreTokens()) {\r
- String nextToken = st.nextToken();\r
- if (nextToken.equals("[")) {\r
- StringBuilder range = new StringBuilder();\r
- range.append("[");\r
- String rangeToken = st.nextToken();\r
- while(!rangeToken.equals("]")) {\r
- range.append(rangeToken);\r
- rangeToken = st.nextToken();\r
- }\r
- range.append("]");\r
- \r
- Variable prevVar = getVariable(variable.getParentConfiguration(), prevToken.trim());\r
- result.append(rangeToIndexes(prevVar, range.toString()));\r
- } else {\r
- result.append(nextToken);\r
- }\r
- prevToken = nextToken;\r
- }\r
- \r
- equation = fixForRangeEnumerations(variable, result.toString());\r
- return equation;\r
+ if(equation == null) return equation;\r
+\r
+ if(equation.contains("[")) {\r
+ StringBuilder result = new StringBuilder();\r
+ String delimiters = "+-*/(){}[],. ";\r
+ StringTokenizer st = new StringTokenizer(equation, delimiters, true);\r
+ String prevToken = st.nextToken();\r
+ result.append(prevToken);\r
+ while (st.hasMoreTokens()) {\r
+ String nextToken = st.nextToken();\r
+ if (nextToken.equals("[")) {\r
+ StringBuilder range = new StringBuilder();\r
+ range.append("[");\r
+ String rangeToken = st.nextToken();\r
+ while(!rangeToken.equals("]")) {\r
+ range.append(rangeToken);\r
+ rangeToken = st.nextToken();\r
+ }\r
+ range.append("]");\r
+\r
+ Variable prevVar = getVariable(variable.getParentConfiguration(), prevToken.trim());\r
+ result.append(rangeToIndexes(prevVar, range.toString()));\r
+ } else {\r
+ result.append(nextToken);\r
+ }\r
+ prevToken = nextToken;\r
+ }\r
+ equation = fixForRangeEnumerations(variable, result.toString());\r
+ } else if(equation.contains("{")){\r
+ // Cases where there are {something for i in Enum} without [] brackets\r
+ equation = fixForRangeEnumerations(variable, equation);\r
+ }\r
+\r
+ return equation;\r
}\r
- \r
+\r
private static Variable getVariable(Configuration configuration, String name) {\r
for(IElement element : configuration.getElements()) {\r
if(element instanceof Variable) {\r