sync/functions.ysl2
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 16 Oct 2019 16:35:08 +0200
branchENGINE-654
changeset 4118 b0995cc07d02
parent 2829 e444c3c960bb
permissions -rw-r--r--
merged in sync
krista@2271
     1
// This file is under GNU General Public License 3.0
krista@2271
     2
// see LICENSE.txt
krista@2271
     3
krista@2271
     4
// function library
krista@2271
     5
krista@2271
     6
def "func:distinctName" {
krista@2271
     7
    param "nodes", "/..";
krista@2271
     8
    choose {
krista@2271
     9
        when "not($nodes)"
krista@2271
    10
            result "/..";
vb@2829
    11
        otherwise
krista@2271
    12
            result "$nodes[1] | func:distinctName($nodes[position() > 1])[@name != $nodes[1]/@name]";
krista@2271
    13
    }
krista@2271
    14
}
vb@2829
    15
vb@2829
    16
def "func:distinctType" {
vb@2829
    17
    param "nodes", "/..";
vb@2829
    18
    choose {
vb@2829
    19
        when "not($nodes)"
vb@2829
    20
            result "/..";
vb@2829
    21
        otherwise
vb@2829
    22
            result "$nodes[1] | func:distinctType($nodes[position() > 1])[@type != $nodes[1]/@type]";
vb@2829
    23
    }
vb@2829
    24
}
vb@2829
    25
vb@2829
    26
def "func:asn1name"
vb@2829
    27
    result "translate(@name, '_', '-')";
vb@2829
    28
vb@2829
    29
def "func:asn1type" {
vb@2829
    30
    choose {
vb@2829
    31
        when "@type='bool'"
vb@2829
    32
            result "'BOOLEAN'";
vb@2829
    33
        when "@type='int'"
vb@2829
    34
            result "'INTEGER'";
vb@2829
    35
        otherwise
vb@2829
    36
            result "translate(@type, '_', '-')";
vb@2829
    37
    }
vb@2829
    38
}
vb@2829
    39
vb@2829
    40
def "func:basicType" {
vb@2829
    41
    choose {
vb@2829
    42
        when "substring(@type,1,1)=yml:lcase(substring(@type,1,1))"
vb@2829
    43
            result "true()";
vb@2829
    44
        otherwise
vb@2829
    45
            result "false()";
vb@2829
    46
    }
vb@2829
    47
}
vb@2829
    48
vb@2829
    49
def "func:ctype" {
vb@2829
    50
    choose {
vb@2829
    51
        when "func:basicType()"
vb@2829
    52
            result "@type";
vb@2829
    53
        otherwise
vb@2829
    54
            result "concat(@type,'_t')";
vb@2829
    55
    }
vb@2829
    56
}