(refs #7619) Better parenthese in derived show 24/1224/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 15 Nov 2017 07:11:32 +0000 (09:11 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 15 Nov 2017 07:11:32 +0000 (09:11 +0200)
Change-Id: Ia0ce420d8958395f787f08926a14e7bfd6fc2bcd

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/deriving/ShowDeriver.java

index afd2a4f8943dfe3d5aa711a611ac3a6827f7eae1..40c3605e779dc86ac402a4fb80016e3d8298ddff 100644 (file)
@@ -81,33 +81,55 @@ class ShowDeriver implements InstanceDeriver {
             for(int i=0;i<l;++i) {
                 par[i] = "v" + i;
             }
-            Expression lhs = new EApply(
-                    new EVar("<+"),
-                    new EVar("sb"),
-                    new EApply(new EVar(constructor.name.name), Expressions.vars(par))
-                    );
-            Expression value;
-            value = new EApply(new EVar("<<"), new EVar("sb"),
-                    new ELiteral(new StringConstant(constructor.name.name)));
-            for(int i=0;i<l;++i) {
-                value = new EApply(new EVar("<<"),
-                        value,
-                        new ELiteral(new StringConstant(" "))
-                        );
-                value = new EApply(new EVar("<+"),
-                        value,
-                        new EApply(new EVar("Par"), new ELiteral(CONST_10), new EVar("v" + i))
+            
+            // <+
+            {
+                Expression lhs = new EApply(
+                        new EVar("<+"),
+                        new EVar("sb"),
+                        new EApply(new EVar(constructor.name.name), Expressions.vars(par))
                         );
+                Expression value;
+                value = new EApply(new EVar("<<"), new EVar("sb"),
+                        new ELiteral(new StringConstant(constructor.name.name)));
+                for(int i=0;i<l;++i) {
+                    value = new EApply(new EVar("<<"),
+                            value,
+                            new ELiteral(new StringConstant(" "))
+                            );
+                    value = new EApply(new EVar("<+"),
+                            value,
+                            new EApply(new EVar("Par"), new ELiteral(CONST_10), new EVar("v" + i))
+                            );
+                }
+    
+                try {
+                    DValueAst valueAst = new DValueAst(lhs, value);
+                    valueAst.setLocationDeep(der.location);
+                    valueDefs.add(valueAst);
+                    /*valueDefs.addAnnotation("<+", new DAnnotationAst(new EVar("@private"), 
+                            Collections.<Expression>emptyList()));*/
+                } catch (NotPatternException e) {
+                    errorLog.log(e.getExpression().location, "Not a pattern.");
+                }
             }
-
-            try {
-                DValueAst valueAst = new DValueAst(lhs, value);
-                valueAst.setLocationDeep(der.location);
-                valueDefs.add(valueAst);
-                /*valueDefs.addAnnotation("<+", new DAnnotationAst(new EVar("@private"), 
-                        Collections.<Expression>emptyList()));*/
-            } catch (NotPatternException e) {
-                errorLog.log(e.getExpression().location, "Not a pattern.");
+            
+            // precedence
+            {
+                Expression lhs = new EApply(
+                        new EVar("precedence"),
+                        new EApply(new EVar(constructor.name.name), Expressions.vars(par))
+                        );
+                Expression value;
+                value = new ELiteral(new IntegerConstant(l == 0 ? 0 : 20));
+    
+                try {
+                    DValueAst valueAst = new DValueAst(lhs, value);
+                    valueAst.setLocationDeep(der.location);
+                    valueDefs.add(valueAst);
+                } catch (NotPatternException e) {
+                    errorLog.log(e.getExpression().location, "Not a pattern.");
+                }
             }
         }
         instancesAst.add(new ProcessedDInstanceAst(instanceAst, valueDefs));