yml2/standardlib.ysl2
author Hartmut Goebel <h.goebel@crazy-compilers.com>
Tue, 17 Mar 2020 10:26:38 +0100
changeset 43 fb35b9db9ca1
permissions -rw-r--r--
Move data files into the Python package.

The packe directory is now always searched for include files, after
all other directoreis given in $YML_PATH.
43
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     1
// YML2 standardlib version 2.5.8
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     2
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     3
function "yml:hex2dec" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     4
    param "hex";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     5
    param "_result", 0;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     6
    
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     7
    const "hd", "substring($hex, 1, 1)";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     8
    const "a", """translate($hd, 'ABCDEFabcdef123456789',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     9
        '123456123456000000000')""";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    10
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    11
    const "d" choose {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    12
        when "$a>0" value "$a + 9";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    13
        otherwise value "$hd";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    14
    }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    15
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    16
    choose {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    17
        when "string-length($hex) = 1"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    18
            value "$_result * 16 + $d";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    19
        otherwise call "yml:hex2dec"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    20
            with "hex", "substring($hex, 2, 8)", 
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    21
            with "_result", "$_result * 16 + $d";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    22
    }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    23
}
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    24
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    25
function "yml:dec2hex" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    26
    param "dec";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    27
    param "bits", !16**7!;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    28
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    29
    const "v", "floor($dec div $bits)";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    30
    value "substring('0123456789abcdef', $v + 1, 1)";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    31
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    32
    if "$bits > 1" call "yml:dec2hex"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    33
        with "dec", "$dec - $bits * $v",
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    34
        with "bits", "$bits div 16";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    35
}
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    36
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    37
def "yml:dec2hex" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    38
    param "dec";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    39
    param "digits", 8;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    40
        
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    41
    result call "yml:dec2hex" with "dec", "$dec", with "bits", "math:power(16, $digits - 1)";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    42
}
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    43
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    44
def "yml:hex2dec" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    45
    param "hex";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    46
    result call "yml:hex2dec" with "hex", "$hex";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    47
}
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    48
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    49
def "yml:lcase" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    50
    param "text", "''";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    51
    result "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    52
}
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    53
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    54
def "yml:ucase" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    55
    param "text", "''";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    56
    result "translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    57
}
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    58
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    59
def "yml:mixedCase" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    60
    param "text", "''";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    61
    result "concat(yml:lcase(substring($text,1,1)),substring($text,2))";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    62
}
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    63
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    64
def "yml:capit" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    65
    param "text", "''";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    66
    result "concat(yml:ucase(substring($text,1,1)),substring($text,2))";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    67
}
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    68