yml2/standardlib.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 28 Apr 2021 23:40:51 +0200
changeset 78 0b05c2bce9e4
parent 43 fb35b9db9ca1
permissions -rw-r--r--
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 standardlib version 2.5.8

function "yml:hex2dec" {
    param "hex";
    param "_result", 0;
    
    const "hd", "substring($hex, 1, 1)";
    const "a", """translate($hd, 'ABCDEFabcdef123456789',
        '123456123456000000000')""";

    const "d" choose {
        when "$a>0" value "$a + 9";
        otherwise value "$hd";
    }

    choose {
        when "string-length($hex) = 1"
            value "$_result * 16 + $d";
        otherwise call "yml:hex2dec"
            with "hex", "substring($hex, 2, 8)", 
            with "_result", "$_result * 16 + $d";
    }
}

function "yml:dec2hex" {
    param "dec";
    param "bits", !16**7!;

    const "v", "floor($dec div $bits)";
    value "substring('0123456789abcdef', $v + 1, 1)";

    if "$bits > 1" call "yml:dec2hex"
        with "dec", "$dec - $bits * $v",
        with "bits", "$bits div 16";
}

def "yml:dec2hex" {
    param "dec";
    param "digits", 8;
        
    result call "yml:dec2hex" with "dec", "$dec", with "bits", "math:power(16, $digits - 1)";
}

def "yml:hex2dec" {
    param "hex";
    result call "yml:hex2dec" with "hex", "$hex";
}

def "yml:lcase" {
    param "text", "''";
    result "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')";
}

def "yml:ucase" {
    param "text", "''";
    result "translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')";
}

def "yml:mixedCase" {
    param "text", "''";
    result "concat(yml:lcase(substring($text,1,1)),substring($text,2))";
}

def "yml:capit" {
    param "text", "''";
    result "concat(yml:ucase(substring($text,1,1)),substring($text,2))";
}