>-- SYSDYN.SysdynModel.solver --> L0.String <R L0.HasProperty : L0.FunctionalRelation
>-- SYSDYN.SysdynModel.variableFilter --> L0.String <R L0.HasProperty : L0.FunctionalRelation
>-- SYSDYN.SysdynModel.fmuFile --> L0.ByteArray <R L0.HasProperty
+ >-- SYSDYN.SysdynModel.timeUnit --> L0.String <R L0.HasProperty : L0.FunctionalRelation
// >-- SYSDYN.SysdynModel.exeFile --> L0.ByteArray <R L0.HasProperty
@L0.assert SYSDYN.SysdynModel.startTime 0.0
@L0.assert SYSDYN.SysdynModel.stopTime 10.0
@L0.assert SYSDYN.SysdynModel.solver "euler"
+ @L0.assert SYSDYN.SysdynModel.timeUnit "month"
//#####################################################################
// Configuration
public final Resource SysdynModel_startTime_Inverse;\r
public final Resource SysdynModel_stopTime;\r
public final Resource SysdynModel_stopTime_Inverse;\r
+ public final Resource SysdynModel_timeUnit;\r
+ public final Resource SysdynModel_timeUnit_Inverse;\r
public final Resource SysdynModel_tolerance;\r
public final Resource SysdynModel_tolerance_Inverse;\r
public final Resource SysdynModel_variableFilter;\r
public static final String SysdynModel_startTime_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/startTime/Inverse";\r
public static final String SysdynModel_stopTime = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/stopTime";\r
public static final String SysdynModel_stopTime_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/stopTime/Inverse";\r
+ public static final String SysdynModel_timeUnit = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/timeUnit";\r
+ public static final String SysdynModel_timeUnit_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/timeUnit/Inverse";\r
public static final String SysdynModel_tolerance = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/tolerance";\r
public static final String SysdynModel_tolerance_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/tolerance/Inverse";\r
public static final String SysdynModel_variableFilter = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/variableFilter";\r
SysdynModel_startTime_Inverse = getResourceOrNull(graph, URIs.SysdynModel_startTime_Inverse);\r
SysdynModel_stopTime = getResourceOrNull(graph, URIs.SysdynModel_stopTime);\r
SysdynModel_stopTime_Inverse = getResourceOrNull(graph, URIs.SysdynModel_stopTime_Inverse);\r
+ SysdynModel_timeUnit = getResourceOrNull(graph, URIs.SysdynModel_timeUnit);\r
+ SysdynModel_timeUnit_Inverse = getResourceOrNull(graph, URIs.SysdynModel_timeUnit_Inverse);\r
SysdynModel_tolerance = getResourceOrNull(graph, URIs.SysdynModel_tolerance);\r
SysdynModel_tolerance_Inverse = getResourceOrNull(graph, URIs.SysdynModel_tolerance_Inverse);\r
SysdynModel_variableFilter = getResourceOrNull(graph, URIs.SysdynModel_variableFilter);\r
}\r
\r
});\r
+ \r
+ \r
+ TrackedCombo timeUnit = new TrackedCombo(composite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);\r
+ timeUnit.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
+\r
+ @Override\r
+ public Map<String, Object> perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+\r
+ Map<String, Object> map = new HashMap<String, Object>();\r
+ map.put("year", "year");\r
+ map.put("month", "month");\r
+ map.put("day", "day");\r
+ map.put("hour", "hour");\r
+ map.put("min", "min");\r
+ map.put("s", "s");\r
+ return map;\r
+ }\r
+ });\r
+ \r
+ timeUnit.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+ String s = graph.getPossibleRelatedValue(input, SysdynResource.getInstance(graph).SysdynModel_timeUnit);\r
+ return s != null ? s : "month";\r
+ }\r
+ });\r
+ \r
+ timeUnit.addModifyListener(new ComboStringPropertyModifier<Resource>() {\r
+\r
+ @Override\r
+ public void applyText(WriteGraph graph, Resource input, String text)\r
+ throws DatabaseException {\r
+ graph.claimLiteral(input, SysdynResource.getInstance(graph).SysdynModel_timeUnit, text);\r
+ }\r
+ });\r
\r
\r
// Scrolled composite settings\r
Object expr = sm.getMapping().get(expression);\r
\r
if(expr != null && var != null && expr instanceof IExpression && var instanceof IndependentVariable) {\r
- String result = ((IExpression)expr).matchUnits(graph, sm.getMapping());\r
+ String result = ((IExpression)expr).validateUnits(graph, sm);\r
if(result != null) {\r
Issue issue = new StandardIssue(SR.Validations_UnitWarning, independentVariable, expression, unitResource);\r
issues.add(issue);\r
}\r
\r
Object expr = sm.getMapping().get(contexts.get(1));\r
- String result = ((IExpression)expr).matchUnits(graph, sm.getMapping());\r
+ String result = ((IExpression)expr).validateUnits(graph, sm);\r
return result;\r
}\r
\r
*******************************************************************************/\r
package org.simantics.sysdyn.representation.expressions;\r
\r
+import org.simantics.db.ReadGraph;\r
import org.simantics.objmap.annotations.GraphType;\r
import org.simantics.objmap.annotations.RelatedValue;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.representation.IndependentVariable;\r
import org.simantics.sysdyn.representation.Variability;\r
import org.simantics.sysdyn.representation.utils.FormatUtils;\r
import org.simantics.sysdyn.representation.utils.IndexUtils;\r
+import org.simantics.sysdyn.representation.utils.UnitUtils;\r
\r
/**\r
* Representation of a delay expression. The order of the \r
return "This + is + not + a + parameter + at + any + time";\r
}\r
\r
+ \r
+ @Override\r
+ public String validateUnits(ReadGraph graph, SysdynModel model) {\r
+ if(parent.getUnit() == null)\r
+ return "Unit not defined for " + parent.getName();\r
+ \r
+ String result = UnitUtils.matchUnits(graph, model, parent.getParentConfiguration(), parent.getUnit(), equation);\r
+ if(result == null)\r
+ result = UnitUtils.matchUnits(graph, model, parent.getParentConfiguration(), parent.getUnit(), initialValue);\r
+ if(result == null)\r
+ result = UnitUtils.matchUnits(graph, model, parent.getParentConfiguration(), UnitUtils.getTimeUnit(graph, model), delayTime);\r
+ \r
+ return result;\r
+ }\r
\r
}\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.objmap.IMapping;\r
import org.simantics.objmap.annotations.RelatedElement;\r
import org.simantics.objmap.annotations.RelatedValue;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.representation.IndependentVariable;\r
import org.simantics.sysdyn.representation.utils.UnitUtils;\r
\r
}\r
\r
@Override\r
- public String matchUnits() {\r
- return UnitUtils.matchUnits(null, null, parent, getExpression());\r
+ public String validateUnits() {\r
+ return validateUnits(null, null);\r
}\r
\r
@Override\r
- public String matchUnits(ReadGraph graph, IMapping mapping) {\r
- return UnitUtils.matchUnits(graph, mapping, parent, getExpression());\r
+ public String validateUnits(ReadGraph graph, SysdynModel model) {\r
+ return UnitUtils.matchUnits(graph, model, parent.getParentConfiguration(), parent.getUnit(), getExpression());\r
}\r
}\r
package org.simantics.sysdyn.representation.expressions;\r
\r
import org.simantics.db.ReadGraph;\r
-import org.simantics.objmap.IMapping;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
\r
\r
/**\r
* Match the units of this expression to units of its variable\r
* @return null if match, Error message otherwise\r
*/\r
- String matchUnits();\r
+ String validateUnits();\r
\r
/**\r
* Match the units of this expression to units of its variable. \r
* \r
* Requests units of referred variables for request listening\r
* @param graph ReadGraph\r
- * @param mapping ObjMap mapping\r
+ * @param model SysdynModel (with mapping)\r
* @return null if match, ERror message otherwise\r
*/\r
- String matchUnits(ReadGraph graph, IMapping mapping);\r
+ String validateUnits(ReadGraph graph, SysdynModel model);\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.representation.expressions;\r
\r
+import org.simantics.db.ReadGraph;\r
import org.simantics.objmap.annotations.GraphType;\r
import org.simantics.objmap.annotations.RelatedValue;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.representation.utils.FormatUtils;\r
import org.simantics.sysdyn.representation.utils.IndexUtils;\r
import org.simantics.sysdyn.representation.utils.SheetFormatUtils;\r
+import org.simantics.sysdyn.representation.utils.UnitUtils;\r
\r
/**\r
* Representation of a withlookup expression\r
return "interpolate(" + equation + ", " + lookupTable + ")";\r
}\r
\r
+ @Override\r
+ public String validateUnits(ReadGraph graph, SysdynModel model) {\r
+ if(parent.getUnit() == null)\r
+ return "Unit not defined for " + parent.getName();\r
+ \r
+ String result = UnitUtils.expressionUnitsValid(graph, model, parent.getParentConfiguration(), equation);\r
+ if(result == null) {\r
+ result = UnitUtils.expressionUnitsValid(graph, model, parent.getParentConfiguration(), equation);\r
+ }\r
+ \r
+ return result;\r
+ }\r
}\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
import org.simantics.db.exception.ServiceException;\r
-import org.simantics.objmap.IMapping;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.IElement;\r
import org.simantics.sysdyn.representation.Module;\r
\r
public class UnitUtils {\r
\r
- public static String matchUnits(ReadGraph graph, IMapping mapping, Variable variable, String expression) {\r
- if(variable.getUnit() == null)\r
- return "Unit not defined for " + variable.getName();\r
+ public static String expressionUnitsValid(ReadGraph graph, SysdynModel model, Configuration configuration, String expression) {\r
+ try {\r
+ StringReader reader = new StringReader(expression);\r
+ UnitParser parser = new UnitParser(reader);\r
+ UnitCheckingNode node = (UnitCheckingNode) parser.expr();\r
+ reader.close();\r
+ Set<String> components = UnitUtils.findComponents(node);\r
+ HashMap<String, String> units = UnitUtils.findUnits(graph, model, configuration, components);\r
+ \r
+ try {\r
+ node.getUnits(units);\r
+ } catch (UnitCheckingException e) {\r
+ return e.getMessage();\r
+ }\r
+ \r
+ } catch (ParseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ public static String matchUnits(ReadGraph graph, SysdynModel model, Configuration configuration, String unit, String expression) {\r
+ if(unit == null)\r
+ return "Unit not defined";\r
try {\r
\r
StringReader rightReader = new StringReader(expression);\r
UnitCheckingNode right = (UnitCheckingNode) rightParser.expr();\r
rightReader.close();\r
Set<String> components = findComponents(right);\r
- HashMap<String, String> units = findUnits(graph, mapping, variable, components);\r
+ HashMap<String, String> units = findUnits(graph, model, configuration, components);\r
\r
- StringReader leftReader = new StringReader(variable.getUnit());\r
+ StringReader leftReader = new StringReader(unit);\r
UnitParser leftParser = new UnitParser(leftReader);\r
UnitCheckingNode left = (UnitCheckingNode) leftParser.expr();\r
leftReader.close();\r
return e.getMessage();\r
}\r
\r
-// node.dump("");\r
} catch (ParseException e) {\r
e.printStackTrace();\r
}\r
}\r
\r
\r
- private static HashMap<String, String> findUnits(ReadGraph graph, IMapping mapping, Variable variable, Set<String> components) {\r
+ public static HashMap<String, String> findUnits(ReadGraph graph, SysdynModel model, Configuration configuration, Set<String> components) {\r
HashMap<String, String> units = new HashMap<String, String>();\r
- Configuration configuration = variable.getParentConfiguration();\r
for(String component : components) {\r
Variable var = getElement(configuration, component);\r
if(var != null) {\r
\r
// Support listening, if graph and mapping exists\r
- if(graph != null && mapping != null) {\r
- Resource varResource = mapping.inverseGet(var);\r
+ if(graph != null && model != null) {\r
+ Resource varResource = model.getMapping().inverseGet(var);\r
if(varResource != null) {\r
try {\r
graph.getPossibleRelatedValue(varResource, SysdynResource.getInstance(graph).Variable_unit);\r
}\r
}\r
\r
- \r
+ units.put("time", getTimeUnit(graph, model));\r
\r
return units;\r
}\r
\r
+ public static String getTimeUnit(ReadGraph graph, SysdynModel model) {\r
+ try {\r
+ Resource modelResource = graph.getPossibleObject(model.getConfigurationResource(), SimulationResource.getInstance(graph).IsConfigurationOf);\r
+ if(modelResource != null) {\r
+ String timeUnit = graph.getPossibleRelatedValue(modelResource, SysdynResource.getInstance(graph).SysdynModel_timeUnit);\r
+ if(timeUnit == null)\r
+ timeUnit = "month";\r
+ return timeUnit;\r
+ }\r
+ \r
+ } catch (ManyObjectsForFunctionalRelationException e) {\r
+ e.printStackTrace();\r
+ } catch (ServiceException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ return null;\r
+ }\r
+ \r
private static Variable getElement(Configuration configuration, String name) {\r
String[] elements = name.split("\\.");\r
String element = elements[0];\r
return null;\r
}\r
\r
- private static Set<String> findComponents(UnitCheckingNode node) {\r
+ public static Set<String> findComponents(UnitCheckingNode node) {\r
HashSet<String> components = new HashSet<String>();\r
addComponents(node, components);\r
return components;\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser;\r
\r
-import java.util.ArrayList;\r
import java.util.HashMap;\r
\r
import org.simantics.sysdyn.unitParser.nodes.UnitResult;\r
String node = printNode();\r
result.append(node);\r
} else {\r
- for(UnitCheckingNode node : getChildren()) {\r
- result.appendResult(node.getUnits(units));\r
+ for(int i = 0; i < jjtGetNumChildren(); i++) {\r
+ result.appendResult(((UnitCheckingNode)jjtGetChild(i)).getUnits(units));\r
}\r
}\r
return result; \r
}\r
\r
- protected ArrayList<UnitCheckingNode> getChildren() {\r
- ArrayList<UnitCheckingNode> children = new ArrayList<UnitCheckingNode>();\r
- for(int i = 0; i < jjtGetNumChildren(); i++) {\r
- children.add((UnitCheckingNode)jjtGetChild(i));\r
- }\r
- return children;\r
- }\r
-\r
-\r
public String printNode() {\r
StringBuilder sb = new StringBuilder();\r
Token token = jjtGetFirstToken();\r
\r
import org.simantics.sysdyn.unitParser.nodes.AddOp;\r
import org.simantics.sysdyn.unitParser.nodes.Arithmetic;\r
+import org.simantics.sysdyn.unitParser.nodes.ArrayDefinition;\r
import org.simantics.sysdyn.unitParser.nodes.ComponentIdentity;\r
import org.simantics.sysdyn.unitParser.nodes.ComponentReference;\r
import org.simantics.sysdyn.unitParser.nodes.ComponentReferenceFull;\r
import org.simantics.sysdyn.unitParser.nodes.Condition;\r
import org.simantics.sysdyn.unitParser.nodes.Divide;\r
+import org.simantics.sysdyn.unitParser.nodes.Expression;\r
import org.simantics.sysdyn.unitParser.nodes.ForIndex;\r
+import org.simantics.sysdyn.unitParser.nodes.FunctionArguments;\r
+import org.simantics.sysdyn.unitParser.nodes.FunctionCall;\r
import org.simantics.sysdyn.unitParser.nodes.IfThenElse;\r
import org.simantics.sysdyn.unitParser.nodes.Multiplication;\r
import org.simantics.sysdyn.unitParser.nodes.RelOp;\r
constructors.put("term", Term.class);\r
constructors.put("arithmetic_expression", Arithmetic.class);\r
constructors.put("ifthenelse", IfThenElse.class);\r
+ constructors.put("array_definition", ArrayDefinition.class);\r
\r
constructors.put("component_reference_full", ComponentReferenceFull.class);\r
constructors.put("value", Value.class);\r
constructors.put("component_identity", ComponentIdentity.class);\r
constructors.put("condition", Condition.class);\r
constructors.put("for_index", ForIndex.class);\r
+ constructors.put("function_call", FunctionCall.class);\r
+ constructors.put("function_arguments", FunctionArguments.class);\r
+ constructors.put("expression", Expression.class);\r
+\r
\r
}\r
\r
jj_consume_token(65);\r
break;\r
case 62:\r
- jj_consume_token(62);\r
- function_arguments();\r
- jj_consume_token(63);\r
+ array_definition();\r
break;\r
case 35:\r
jj_consume_token(35);\r
}\r
}\r
\r
+ final public void array_definition() throws ParseException {\r
+ /*@bgen(jjtree) array_definition */\r
+ UnitCheckingNode jjtn000 = (UnitCheckingNode)UnitCheckingNodeFactory.jjtCreate(JJTARRAY_DEFINITION);\r
+ boolean jjtc000 = true;\r
+ jjtree.openNodeScope(jjtn000);\r
+ jjtn000.jjtSetFirstToken(getToken(1));\r
+ try {\r
+ jj_consume_token(62);\r
+ function_arguments();\r
+ jj_consume_token(63);\r
+ } catch (Throwable jjte000) {\r
+ if (jjtc000) {\r
+ jjtree.clearNodeScope(jjtn000);\r
+ jjtc000 = false;\r
+ } else {\r
+ jjtree.popNode();\r
+ }\r
+ if (jjte000 instanceof RuntimeException) {\r
+ {if (true) throw (RuntimeException)jjte000;}\r
+ }\r
+ if (jjte000 instanceof ParseException) {\r
+ {if (true) throw (ParseException)jjte000;}\r
+ }\r
+ {if (true) throw (Error)jjte000;}\r
+ } finally {\r
+ if (jjtc000) {\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtn000.jjtSetLastToken(getToken(0));\r
+ }\r
+ }\r
+ }\r
+\r
final public void function_call() throws ParseException {\r
/*@bgen(jjtree) function_call */\r
UnitCheckingNode jjtn000 = (UnitCheckingNode)UnitCheckingNodeFactory.jjtCreate(JJTFUNCTION_CALL);\r
default:\r
jj_la1[40] = jj_gen;\r
if (jj_2_3(2147483647)) {\r
- name();\r
- function_call_args();\r
+ function_call();\r
} else {\r
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {\r
case IDENT:\r
finally { jj_save(2, xla); }\r
}\r
\r
- private boolean jj_3_2() {\r
- if (jj_3R_13()) return true;\r
- return false;\r
- }\r
-\r
- private boolean jj_3R_11() {\r
- if (jj_scan_token(IDENT)) return true;\r
- Token xsp;\r
- xsp = jj_scanpos;\r
- if (jj_3R_14()) jj_scanpos = xsp;\r
- return false;\r
- }\r
-\r
private boolean jj_3R_14() {\r
if (jj_scan_token(66)) return true;\r
if (jj_3R_11()) return true;\r
return false;\r
}\r
\r
+ private boolean jj_3_2() {\r
+ if (jj_3R_13()) return true;\r
+ return false;\r
+ }\r
+\r
+ private boolean jj_3R_11() {\r
+ if (jj_scan_token(IDENT)) return true;\r
+ Token xsp;\r
+ xsp = jj_scanpos;\r
+ if (jj_3R_14()) jj_scanpos = xsp;\r
+ return false;\r
+ }\r
+\r
private boolean jj_3_1() {\r
if (jj_3R_11()) return true;\r
if (jj_3R_12()) return true;\r
/*| "(" output_expression_list() ")"*/ // Not needed, replaced with following:\r
| parenthesis_expression()\r
| "[" expression_list() ( ";" expression_list() )* "]"\r
- | "{" function_arguments() "}"\r
+ | array_definition()\r
| "end"/*@bgen(jjtree)*/\r
} catch (Throwable jjte000) {\r
if (jjtc000) {\r
/*@egen*/\r
}\r
\r
+void array_definition() : {/*@bgen(jjtree) array_definition */\r
+ UnitCheckingNode jjtn000 = (UnitCheckingNode)UnitCheckingNodeFactory.jjtCreate(JJTARRAY_DEFINITION);\r
+ boolean jjtc000 = true;\r
+ jjtree.openNodeScope(jjtn000);\r
+ jjtn000.jjtSetFirstToken(getToken(1));\r
+/*@egen*/\r
+} {/*@bgen(jjtree) array_definition */\r
+ try {\r
+/*@egen*/\r
+ "{" function_arguments() "}"/*@bgen(jjtree)*/\r
+ } catch (Throwable jjte000) {\r
+ if (jjtc000) {\r
+ jjtree.clearNodeScope(jjtn000);\r
+ jjtc000 = false;\r
+ } else {\r
+ jjtree.popNode();\r
+ }\r
+ if (jjte000 instanceof RuntimeException) {\r
+ throw (RuntimeException)jjte000;\r
+ }\r
+ if (jjte000 instanceof ParseException) {\r
+ throw (ParseException)jjte000;\r
+ }\r
+ throw (Error)jjte000;\r
+ } finally {\r
+ if (jjtc000) {\r
+ jjtree.closeNodeScope(jjtn000, true);\r
+ jjtn000.jjtSetLastToken(getToken(0));\r
+ }\r
+ }\r
+/*@egen*/\r
+}\r
+\r
void function_call() : {/*@bgen(jjtree) function_call */\r
UnitCheckingNode jjtn000 = (UnitCheckingNode)UnitCheckingNodeFactory.jjtCreate(JJTFUNCTION_CALL);\r
boolean jjtc000 = true;\r
} {/*@bgen(jjtree) subscript */\r
try {\r
/*@egen*/\r ":"\r
- | LOOKAHEAD( name() parenthesis_open() ) name() function_call_args()\r
+ | LOOKAHEAD( name() parenthesis_open() ) function_call()\r
| rangeIndex() ( ":" rangeIndex())?/*@bgen(jjtree)*/\r
} catch (Throwable jjte000) {\r
if (jjtc000) {\r
/*| "(" output_expression_list() ")"*/ // Not needed, replaced with following:\r
| parenthesis_expression()\r
| "[" expression_list() ( ";" expression_list() )* "]"\r
- | "{" function_arguments() "}"\r
+ | array_definition()\r
| "end"\r
}\r
\r
component_reference()\r
}\r
\r
+void array_definition() : {\r
+} {\r
+ "{" function_arguments() "}"\r
+}\r
+\r
void function_call() : {\r
} {\r
name() function_call_args()\r
\r
void subscript() : {\r
} {\r ":"\r
- | LOOKAHEAD( name() parenthesis_open() ) name() function_call_args()\r
+ | LOOKAHEAD( name() parenthesis_open() ) function_call()\r
| rangeIndex() ( ":" rangeIndex())?\r
}\r
\r
public int JJTDIVIDE = 15;\r
public int JJTPRIMARY = 16;\r
public int JJTCOMPONENT_REFERENCE_FULL = 17;\r
- public int JJTFUNCTION_CALL = 18;\r
- public int JJTPARENTHESIS_EXPRESSION = 19;\r
- public int JJTVALUE = 20;\r
- public int JJTPARENTHESIS_OPEN = 21;\r
- public int JJTPARENTHESIS_CLOSE = 22;\r
- public int JJTNAME = 23;\r
- public int JJTCOMPONENT_REFERENCE = 24;\r
- public int JJTCOMPONENT_IDENTITY = 25;\r
- public int JJTFUNCTION_CALL_ARGS = 26;\r
- public int JJTFUNCTION_ARGUMENTS = 27;\r
- public int JJTFOR_INDICES = 28;\r
- public int JJTFOR_INDEX = 29;\r
- public int JJTNAMED_ARGUMENT = 30;\r
- public int JJTOUTPUT_EXPRESSION_LIST = 31;\r
- public int JJTEXPRESSION_LIST = 32;\r
- public int JJTARRAY_SUBSCRIPTS = 33;\r
- public int JJTSUBSCRIPT = 34;\r
- public int JJTRANGEINDEX = 35;\r
+ public int JJTARRAY_DEFINITION = 18;\r
+ public int JJTFUNCTION_CALL = 19;\r
+ public int JJTPARENTHESIS_EXPRESSION = 20;\r
+ public int JJTVALUE = 21;\r
+ public int JJTPARENTHESIS_OPEN = 22;\r
+ public int JJTPARENTHESIS_CLOSE = 23;\r
+ public int JJTNAME = 24;\r
+ public int JJTCOMPONENT_REFERENCE = 25;\r
+ public int JJTCOMPONENT_IDENTITY = 26;\r
+ public int JJTFUNCTION_CALL_ARGS = 27;\r
+ public int JJTFUNCTION_ARGUMENTS = 28;\r
+ public int JJTFOR_INDICES = 29;\r
+ public int JJTFOR_INDEX = 30;\r
+ public int JJTNAMED_ARGUMENT = 31;\r
+ public int JJTOUTPUT_EXPRESSION_LIST = 32;\r
+ public int JJTEXPRESSION_LIST = 33;\r
+ public int JJTARRAY_SUBSCRIPTS = 34;\r
+ public int JJTSUBSCRIPT = 35;\r
+ public int JJTRANGEINDEX = 36;\r
\r
\r
public String[] jjtNodeName = {\r
"divide",\r
"primary",\r
"component_reference_full",\r
+ "array_definition",\r
"function_call",\r
"parenthesis_expression",\r
"value",\r
"rangeIndex",\r
};\r
}\r
-/* JavaCC - OriginalChecksum=e2f99f7df8969b486d8da5159d18ad81 (do not edit this line) */\r
+/* JavaCC - OriginalChecksum=9313cac9e0951f8836c120d51f6c620b (do not edit this line) */\r
for(int i = 0; i < jjtGetNumChildren(); i++) {\r
candidateNode = ((UnitCheckingNode)jjtGetChild(i));\r
UnitResult candidateUnits = candidateNode.getUnits(units);\r
- if(candidateUnits.getUnitType() == UnitType.OPERATOR || candidateUnits.getUnitType() == UnitType.ANY) {\r
- result.setUnitType(candidateUnits.getUnitType());\r
+ if(candidateUnits.getUnitType() == UnitType.OPERATOR) {\r
continue;\r
- } else if(base == null) {\r
+ } else if(base == null || result.getUnitType() == UnitType.SCALAR || result.getUnitType() == UnitType.ANY) {\r
base = ((UnitCheckingNode)jjtGetChild(i));\r
result.appendResult(base.getUnits(units));\r
continue;\r
+ } else if(candidateUnits.getUnitType() == UnitType.SCALAR) {\r
+ continue;\r
} else {\r
operator = ((UnitCheckingNode)jjtGetChild(i-1));\r
if(!result.equals(candidateUnits)) {\r
}\r
}\r
}\r
-\r
+// System.out.println("Arithmetic: " + printNode() + " [" + result.getFullUnit() + " : " + result.getUnitType() + "]");\r
return result;\r
}\r
\r
import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
import org.simantics.sysdyn.unitParser.UnitParser;\r
+import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
\r
/**\r
* See UnitCheckingNodeFactory for mapping\r
@Override\r
public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
String node = printNode();\r
- node = printNode();\r
+ \r
+ if("dmnl".equals(node)) {\r
+ UnitResult result = new UnitResult();\r
+ result.setUnitType(UnitType.DMNL);\r
+ return result;\r
+ }\r
+ \r
if(units != null) {\r
if(!units.containsKey(node))\r
throw new UnitCheckingException("No units defined for " + node);\r
current = ((UnitCheckingNode)jjtGetChild(i));\r
UnitResult currentUnits = current.getUnits(units);\r
\r
- if(currentUnits.getUnitType() == UnitType.OPERATOR) {\r
+ if(currentUnits.getUnitType() == UnitType.ANY) {\r
+ result = new UnitResult();\r
+ result.setUnitType(UnitType.ANY);\r
+ return result;\r
+ } else if(currentUnits.getUnitType() == UnitType.OPERATOR) {\r
continue;\r
} else if(base == null) {\r
base = current;\r
operator = ((UnitCheckingNode)jjtGetChild(i-1));\r
\r
if(operator instanceof Multiplication) {\r
- if(currentUnits.getUnitType() != UnitType.ANY) {\r
+ UnitType unitType = currentUnits.getUnitType();\r
+ if(unitType != UnitType.SCALAR && unitType != UnitType.DMNL) {\r
result.append(operator.printNode());\r
result.appendResult(currentUnits);\r
}\r
- } else if(operator instanceof Divide){\r
+ } else if(operator instanceof Divide) {\r
result.append(operator.printNode());\r
result.addAllDividers(currentUnits.getDividers());\r
result.addAllDividers(currentUnits.getDividents());\r
- result.setUnitType(currentUnits.getUnitType());\r
\r
- if(currentUnits.getUnitType() == UnitType.ANY)\r
+ UnitType unitType = currentUnits.getUnitType();\r
+ result.setUnitType(unitType);\r
+ if(unitType == UnitType.SCALAR || unitType == UnitType.DMNL)\r
result.append("1");\r
else\r
result.append(currentUnits.getFullUnit());\r
}\r
}\r
}\r
- \r
+// System.out.println("Term: " + printNode() + " [" + result.getFullUnit() + " : " + result.getUnitType() + "]");\r
return result;\r
}\r
\r
*/\r
public class UnitResult {\r
\r
- public enum UnitType {NORMAL, ANY, DMNL, OPERATOR};\r
+ public enum UnitType {NORMAL, ANY, DMNL, OPERATOR, SCALAR};\r
\r
private ArrayList<String> dividers = new ArrayList<String>();\r
private ArrayList<String> dividents = new ArrayList<String>();\r
private StringBuilder fullUnit = new StringBuilder();\r
- private UnitType unitType = UnitType.NORMAL;\r
+ private UnitType unitType;\r
+ \r
+ public UnitResult() {\r
+ setUnitType(UnitType.NORMAL);\r
+ }\r
\r
public void appendResult(UnitResult result) {\r
addAllDividents(result.getDividents());\r
if(getUnitType() == UnitType.ANY || other.getUnitType() == UnitType.ANY)\r
return true;\r
\r
+ if(getUnitType() != other.getUnitType())\r
+ return true;\r
+ \r
ArrayList<String> copyDividers1 = new ArrayList<String>(dividers);\r
ArrayList<String> copyDividents1 = new ArrayList<String>(dividents);\r
reduceUnitLists(dividents, copyDividents1, copyDividers1);\r
public void setUnitType(UnitType unitType) {\r
this.unitType = unitType;\r
}\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return getCleanFullUnit();\r
+ }\r
}\r
@Override\r
public UnitResult getUnits(HashMap<String, String> units) throws UnitCheckingException {\r
UnitResult result = super.getUnits(units);\r
- result.setUnitType(UnitType.ANY);\r
+ result.setUnitType(UnitType.SCALAR);\r
return result;\r
}\r
}\r