Fix expension of macros in pointers with default values. default tip
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Wed, 28 Apr 2021 23:40:51 +0200
changeset 78 0b05c2bce9e4
parent 77 5b23278ed81f
Fix expension of macros in pointers with default values.

For example :

in xsl decl widget_class(%name, *clsname="%nameWidget", match="widget[@type='%name']", mode="widget_class") alias template {
| class `text **clsname` extends Widget{
content;
| }
};

widget_class('Input');

gives now :

<xsl:template match="widget[@type='Input']" mode="widget_class">
<xsl:text>class </xsl:text>
<xsl:text>InputWidget</xsl:text>
<xsl:text> extends Widget{
</xsl:text>
<xsl:text>}
</xsl:text>
</xsl:template>

Without the fix, <xsl:text>InputWidget</xsl:text> would be <xsl:text>%nameWidget</xsl:text>
yml2/backend.py
--- a/yml2/backend.py	Thu Apr 08 21:11:30 2021 +0200
+++ b/yml2/backend.py	Wed Apr 28 23:40:51 2021 +0200
@@ -247,9 +247,10 @@
         resultParms = self.values.copy()
         macros = self.macros.copy()
         toDelete = [ key for key in resultParms.keys() ]
+        toPointers = {}
         for key in toDelete:
             if key[0] == "*":
-                del resultParms[key]
+                toPointers[key] = resultParms.pop(key)
         for key, value in callValues.items():
             if key[0] == "%":
                 macros[key] = value
@@ -259,11 +260,7 @@
         for cp in callParms:
             if i < len(self.parms):
                 if self.parms[i][0] == "*":
-                    cp = u(cp)
-                    if "'" in cp:
-                        pointers[self.parms[i][1:]] = '"' + cp + '"'
-                    else:
-                        pointers[self.parms[i][1:]] = "'" + cp + "'"
+                    toPointers[self.parms[i]] = cp
                 elif self.parms[i][0] == "%":
                     macros[self.parms[i]] = u(cp)
                 else:
@@ -272,6 +269,10 @@
                 extraContent += u(cp)
                 hasContent = True
             i += 1
+        for k,v in toPointers.items():
+            v = applyMacros(macros, u(v))
+            q = '"' if "'" in v else "'"
+            pointers[k[1:]] = q + v + q
         result = ""
         for p, v in resultParms.items():
             if p[0] == "'" or p[0] == '"':