]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Unit validation for whitespaced variable names
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 24 Oct 2013 07:04:13 +0000 (07:04 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 24 Oct 2013 07:04:13 +0000 (07:04 +0000)
fixes #4424

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28110 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitParser.java
org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitParser.jj
org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitParser.jjt
org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ComponentIdentity.java
org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/IfThenElse.java
org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Term.java

index eff84e4320495b19c87ec9e7f41fdc9105b042b9..7b0111abaf06a13f461362057739ee412603491d 100644 (file)
@@ -1110,6 +1110,14 @@ public class UnitParser/*@bgen(jjtree)*/implements UnitParserTreeConstants, Unit
   jjtn000.jjtSetFirstToken(getToken(1));\r
     try {\r
       jj_consume_token(IDENT);\r
+      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {\r
+      case IDENT:\r
+        jj_consume_token(IDENT);\r
+        break;\r
+      default:\r
+        jj_la1[27] = jj_gen;\r
+        ;\r
+      }\r
     } finally {\r
     if (jjtc000) {\r
       jjtree.closeNodeScope(jjtn000, true);\r
@@ -1146,7 +1154,7 @@ public class UnitParser/*@bgen(jjtree)*/implements UnitParserTreeConstants, Unit
         function_arguments();\r
         break;\r
       default:\r
-        jj_la1[27] = jj_gen;\r
+        jj_la1[28] = jj_gen;\r
         ;\r
       }\r
       parenthesis_close();\r
@@ -1187,7 +1195,7 @@ public class UnitParser/*@bgen(jjtree)*/implements UnitParserTreeConstants, Unit
           function_arguments();\r
           break;\r
         default:\r
-          jj_la1[28] = jj_gen;\r
+          jj_la1[29] = jj_gen;\r
           ;\r
         }\r
       } else {\r
@@ -1222,18 +1230,18 @@ public class UnitParser/*@bgen(jjtree)*/implements UnitParserTreeConstants, Unit
               for_indices();\r
               break;\r
             default:\r
-              jj_la1[29] = jj_gen;\r
+              jj_la1[30] = jj_gen;\r
               jj_consume_token(-1);\r
               throw new ParseException();\r
             }\r
             break;\r
           default:\r
-            jj_la1[30] = jj_gen;\r
+            jj_la1[31] = jj_gen;\r
             ;\r
           }\r
           break;\r
         default:\r
-          jj_la1[31] = jj_gen;\r
+          jj_la1[32] = jj_gen;\r
           jj_consume_token(-1);\r
           throw new ParseException();\r
         }\r
@@ -1275,7 +1283,7 @@ public class UnitParser/*@bgen(jjtree)*/implements UnitParserTreeConstants, Unit
           ;\r
           break;\r
         default:\r
-          jj_la1[32] = jj_gen;\r
+          jj_la1[33] = jj_gen;\r
           break label_7;\r
         }\r
         jj_consume_token(69);\r
@@ -1317,7 +1325,7 @@ public class UnitParser/*@bgen(jjtree)*/implements UnitParserTreeConstants, Unit
         expression();\r
         break;\r
       default:\r
-        jj_la1[33] = jj_gen;\r
+        jj_la1[34] = jj_gen;\r
         ;\r
       }\r
     } catch (Throwable jjte000) {\r
@@ -1407,7 +1415,7 @@ void named_arguments() : {
         expression();\r
         break;\r
       default:\r
-        jj_la1[34] = jj_gen;\r
+        jj_la1[35] = jj_gen;\r
         ;\r
       }\r
       label_8:\r
@@ -1417,7 +1425,7 @@ void named_arguments() : {
           ;\r
           break;\r
         default:\r
-          jj_la1[35] = jj_gen;\r
+          jj_la1[36] = jj_gen;\r
           break label_8;\r
         }\r
         jj_consume_token(69);\r
@@ -1441,7 +1449,7 @@ void named_arguments() : {
           expression();\r
           break;\r
         default:\r
-          jj_la1[36] = jj_gen;\r
+          jj_la1[37] = jj_gen;\r
           ;\r
         }\r
       }\r
@@ -1482,7 +1490,7 @@ void named_arguments() : {
           ;\r
           break;\r
         default:\r
-          jj_la1[37] = jj_gen;\r
+          jj_la1[38] = jj_gen;\r
           break label_9;\r
         }\r
         jj_consume_token(69);\r
@@ -1526,7 +1534,7 @@ void named_arguments() : {
           ;\r
           break;\r
         default:\r
-          jj_la1[38] = jj_gen;\r
+          jj_la1[39] = jj_gen;\r
           break label_10;\r
         }\r
         jj_consume_token(69);\r
@@ -1567,7 +1575,7 @@ void named_arguments() : {
         jj_consume_token(67);\r
         break;\r
       default:\r
-        jj_la1[40] = jj_gen;\r
+        jj_la1[41] = jj_gen;\r
         if (jj_2_3(2147483647)) {\r
           function_call();\r
         } else {\r
@@ -1581,12 +1589,12 @@ void named_arguments() : {
               rangeIndex();\r
               break;\r
             default:\r
-              jj_la1[39] = jj_gen;\r
+              jj_la1[40] = jj_gen;\r
               ;\r
             }\r
             break;\r
           default:\r
-            jj_la1[41] = jj_gen;\r
+            jj_la1[42] = jj_gen;\r
             jj_consume_token(-1);\r
             throw new ParseException();\r
           }\r
@@ -1629,7 +1637,7 @@ void named_arguments() : {
         jj_consume_token(IDENT);\r
         break;\r
       default:\r
-        jj_la1[42] = jj_gen;\r
+        jj_la1[43] = jj_gen;\r
         jj_consume_token(-1);\r
         throw new ParseException();\r
       }\r
@@ -1715,7 +1723,7 @@ void named_arguments() : {
   private Token jj_scanpos, jj_lastpos;\r
   private int jj_la;\r
   private int jj_gen;\r
-  final private int[] jj_la1 = new int[43];\r
+  final private int[] jj_la1 = new int[44];\r
   static private int[] jj_la1_0;\r
   static private int[] jj_la1_1;\r
   static private int[] jj_la1_2;\r
@@ -1725,13 +1733,13 @@ void named_arguments() : {
       jj_la1_init_2();\r
    }\r
    private static void jj_la1_init_0() {\r
-      jj_la1_0 = new int[] {0x1040,0x80001041,0x80001040,0x100000,0x0,0x0,0x400000,0x200,0x1000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x40,0x0,0x0,0x0,0x80001040,0x0,0x200000,0x200000,0x80001040,0x0,0x0,0x80001040,0x0,0x80001040,0x0,0x0,0x0,0x0,0x0,0x0,};\r
+      jj_la1_0 = new int[] {0x1040,0x80001041,0x80001040,0x100000,0x0,0x0,0x400000,0x200,0x1000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x40,0x0,0x0,0x0,0x0,0x80001040,0x0,0x200000,0x200000,0x80001040,0x0,0x0,0x80001040,0x0,0x80001040,0x0,0x0,0x0,0x0,0x0,0x0,};\r
    }\r
    private static void jj_la1_init_1() {\r
-      jj_la1_1 = new int[] {0x5000000a,0x5000000a,0x5000000a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x50000008,0x2,0x0,0x0,0x0,0x5000000a,0x0,0x0,0x0,0x5000000a,0x0,0x200,0x5000000a,0x0,0x5000000a,0x0,0x0,0x0,0x0,0x0,0x0,};\r
+      jj_la1_1 = new int[] {0x5000000a,0x5000000a,0x5000000a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x50000008,0x2,0x0,0x0,0x0,0x0,0x5000000a,0x0,0x0,0x0,0x5000000a,0x0,0x200,0x5000000a,0x0,0x5000000a,0x0,0x0,0x0,0x0,0x0,0x0,};\r
    }\r
    private static void jj_la1_init_2() {\r
-      jj_la1_2 = new int[] {0xf00f001,0xf00f001,0xf00f001,0x0,0x8,0x8,0x0,0x0,0x0,0xfc0,0xfc0,0xf000,0xf000,0xf000,0xf0000,0xf0000,0x300000,0x300000,0x50000,0xa0000,0x10,0xe000000,0x1000001,0xe000000,0x4,0x1,0x4,0xf00f001,0x20,0x20,0x20,0xf00f001,0x20,0x0,0xf00f001,0x20,0xf00f001,0x20,0x20,0x8,0x8,0x5000000,0x5000000,};\r
+      jj_la1_2 = new int[] {0xf00f001,0xf00f001,0xf00f001,0x0,0x8,0x8,0x0,0x0,0x0,0xfc0,0xfc0,0xf000,0xf000,0xf000,0xf0000,0xf0000,0x300000,0x300000,0x50000,0xa0000,0x10,0xe000000,0x1000001,0xe000000,0x4,0x1,0x4,0x1000000,0xf00f001,0x20,0x20,0x20,0xf00f001,0x20,0x0,0xf00f001,0x20,0xf00f001,0x20,0x20,0x8,0x8,0x5000000,0x5000000,};\r
    }\r
   final private JJCalls[] jj_2_rtns = new JJCalls[3];\r
   private boolean jj_rescan = false;\r
@@ -1748,7 +1756,7 @@ void named_arguments() : {
     token = new Token();\r
     jj_ntk = -1;\r
     jj_gen = 0;\r
-    for (int i = 0; i < 43; i++) jj_la1[i] = -1;\r
+    for (int i = 0; i < 44; i++) jj_la1[i] = -1;\r
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();\r
   }\r
 \r
@@ -1764,7 +1772,7 @@ void named_arguments() : {
     jj_ntk = -1;\r
     jjtree.reset();\r
     jj_gen = 0;\r
-    for (int i = 0; i < 43; i++) jj_la1[i] = -1;\r
+    for (int i = 0; i < 44; i++) jj_la1[i] = -1;\r
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();\r
   }\r
 \r
@@ -1775,7 +1783,7 @@ void named_arguments() : {
     token = new Token();\r
     jj_ntk = -1;\r
     jj_gen = 0;\r
-    for (int i = 0; i < 43; i++) jj_la1[i] = -1;\r
+    for (int i = 0; i < 44; i++) jj_la1[i] = -1;\r
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();\r
   }\r
 \r
@@ -1787,7 +1795,7 @@ void named_arguments() : {
     jj_ntk = -1;\r
     jjtree.reset();\r
     jj_gen = 0;\r
-    for (int i = 0; i < 43; i++) jj_la1[i] = -1;\r
+    for (int i = 0; i < 44; i++) jj_la1[i] = -1;\r
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();\r
   }\r
 \r
@@ -1797,7 +1805,7 @@ void named_arguments() : {
     token = new Token();\r
     jj_ntk = -1;\r
     jj_gen = 0;\r
-    for (int i = 0; i < 43; i++) jj_la1[i] = -1;\r
+    for (int i = 0; i < 44; i++) jj_la1[i] = -1;\r
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();\r
   }\r
 \r
@@ -1808,7 +1816,7 @@ void named_arguments() : {
     jj_ntk = -1;\r
     jjtree.reset();\r
     jj_gen = 0;\r
-    for (int i = 0; i < 43; i++) jj_la1[i] = -1;\r
+    for (int i = 0; i < 44; i++) jj_la1[i] = -1;\r
     for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();\r
   }\r
 \r
@@ -1925,7 +1933,7 @@ void named_arguments() : {
       la1tokens[jj_kind] = true;\r
       jj_kind = -1;\r
     }\r
-    for (int i = 0; i < 43; i++) {\r
+    for (int i = 0; i < 44; i++) {\r
       if (jj_la1[i] == jj_gen) {\r
         for (int j = 0; j < 32; j++) {\r
           if ((jj_la1_0[i] & (1<<j)) != 0) {\r
index d0dc7828eb0c75fb4e9d6f75ccbb074127f88625..16eab62e35bb4b6539926e273017f935cf443098 100644 (file)
@@ -863,7 +863,7 @@ void component_identity() : {/*@bgen(jjtree) component_identity */
 /*@egen*/\r
 } {/*@bgen(jjtree) component_identity */\r
   try {\r
-/*@egen*/\r  <IDENT>/*@bgen(jjtree)*/\r
+/*@egen*/\r  <IDENT> (<IDENT>)?/*@bgen(jjtree)*/\r
   } finally {\r
     if (jjtc000) {\r
       jjtree.closeNodeScope(jjtn000, true);\r
index c6e3c4fad943760150b3d03382ad620ec1953d57..c6428eecc3452a23ed9384876a4f20c4d7d87151 100644 (file)
@@ -210,7 +210,7 @@ void component_reference() : {
 }\r
 \r
 void component_identity() : {\r
-} {\r  <IDENT>\r
+} {\r  <IDENT> (<IDENT>)?\r
 }\r  \r
 \r
 void function_call_args() : {\r
index c32b47f67578d3a62c44f774d5343a0e917a4a00..8d90375e12dda2ea902a783672376e25aada9fbf 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.unitParser.nodes;\r
 \r
+import org.simantics.sysdyn.unitParser.Token;\r
 import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
 \r
 /**\r
@@ -23,5 +24,19 @@ public class ComponentIdentity extends UnitCheckingNode {
     public ComponentIdentity(int id) {\r
         super(id);\r
     }\r
+    \r
+    @Override\r
+    public String printNode() {\r
+        StringBuilder sb = new StringBuilder();\r
+        Token token = jjtGetFirstToken();\r
+        sb.append(token.image);\r
+\r
+        while(token != null && !token.equals(jjtGetLastToken())) {\r
+            sb.append(" ");\r
+            token = token.next;\r
+            sb.append(token.image);\r
+        }\r
+        return sb.toString();\r
+    }\r
 \r
 }\r
index f5942e4e49d017ee79cf3eae931355f6244a4a56..3529a15e9b34807bfc33e2012e168d1434acec8f 100644 (file)
@@ -46,8 +46,8 @@ public class IfThenElse extends UnitCheckingNode {
                 } else {\r
                     if(!base.equals(candidateUnits)) {\r
                         base.equals(candidateUnits);\r
-                        throw new UnitCheckingException("Conditional results do not have same units: \n" +\r
-                        printNode() + "\n" + \r
+                        throw new UnitCheckingException("Conditional results do not have same units: " +\r
+                        printNode() + " -> " + \r
                                 baseNode.printNode() + " [" + base.getFullUnit() + "] <-> " +\r
                                 candidateNode.printNode() + " [" + candidateUnits.getFullUnit() + "]"\r
                                 );\r
index 33a37fd327faf968247ffc24ee655a0c68dc72d3..d8b454e67f6ef8f7bbc84de83aa3f266684b8fbb 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.sysdyn.unitParser.nodes;
 \r
 import java.util.HashMap;\r
 \r
+import org.simantics.sysdyn.unitParser.Token;\r
 import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
 import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
 import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
@@ -76,5 +77,27 @@ public class Term extends UnitCheckingNode {
 //        System.out.println("Term: " + printNode() + " [" + result.getFullUnit() + " : " + result.getUnitType() + "]");\r
         return result;\r
     }\r
+    \r
+    @Override\r
+    public String printNode() {\r
+        StringBuilder sb = new StringBuilder();\r
+        Token token = jjtGetFirstToken();\r
+        sb.append(token.image);\r
+\r
+        Token prevToken = null;\r
+        while(token != null && !token.equals(jjtGetLastToken())) {\r
+            prevToken = token;\r
+            token = token.next;\r
+            if(!token.image.equals("[") \r
+                    && !token.image.equals("]")\r
+                    && !prevToken.image.equals("[")\r
+                    && !prevToken.image.equals("]")\r
+                    && !token.image.equals(".")\r
+                    && !prevToken.image.equals("."))\r
+                sb.append(" ");\r
+            sb.append(token.image);\r
+        }\r
+        return sb.toString();\r
+    }\r
 \r
 }\r