svghmi/parse_labels.ysl2
changeset 3592 b2bdb8b433e0
parent 3579 c5070b6973ba
child 3593 122b1094b8e6
equal deleted inserted replaced
3579:c5070b6973ba 3592:b2bdb8b433e0
    18 const "newline" |
    18 const "newline" |
    19 const "twonewlines", "concat($newline,$newline)";
    19 const "twonewlines", "concat($newline,$newline)";
    20 
    20 
    21 template "*", mode="parselabel"
    21 template "*", mode="parselabel"
    22 {
    22 {
    23     const "part","@inkscape:label";
    23     const "label","@inkscape:label";
    24     const "desc", "svg:desc";
    24     const "desc", "svg:desc";
    25 
    25 
    26     // add svg:desc field if continuation "\" marker is found at the end of label
    26     // add svg:desc field if continuation "\" marker is found at the end of label
    27     const "len","string-length($part)";
    27     const "len","string-length($label)";
    28     const "has_continuation", "substring($part,$len,1)='\\'";
    28     const "has_continuation", "substring($label,$len,1)='\\'";
    29     const "label" choose{
    29     const "full_decl" choose{
    30         when "$has_continuation" {
    30         when "$has_continuation" {
    31            const "_continuation", "substring-before($desc, $twonewlines)";
    31            const "_continuation", "substring-before($desc, $twonewlines)";
    32            const "continuation" choose {
    32            const "continuation" choose {
    33                when "$_continuation" value "$_continuation";
    33                when "$_continuation" value "$_continuation";
    34                otherwise value "$desc";
    34                otherwise value "$desc";
    35            }
    35            }
    36            value "concat(substring($part,1,$len - 1),translate($continuation,$newline,''))";
    36            value "concat(substring($label,1,$len - 1),translate($continuation,$newline,''))";
    37         }
    37         }
    38         otherwise value "$part";
    38         otherwise value "$label";
    39     }
    39     }
    40 
    40 
    41     const "id","@id";
    41     const "id","@id";
    42 
    42 
    43     const "description", "substring-after($label,'HMI:')";
    43     const "declaration", "substring-after($full_decl,'HMI:')";
    44 
    44 
    45     const "_args", "substring-before($description,'@')";
    45     const "_args", "substring-before($declaration,'@')";
    46     const "args" choose {
    46     const "args" choose {
    47         when "$_args" value "$_args";
    47         when "$_args" value "$_args";
    48         otherwise value "$description";
    48         otherwise value "$declaration";
    49     }
    49     }
    50 
    50 
    51     const "_typefreq", "substring-before($args,':')";
    51     const "_typefreq", "substring-before($args,':')";
    52     const "typefreq" choose {
    52     const "typefreq" choose {
    53         when "$_typefreq" value "$_typefreq";
    53         when "$_typefreq" value "$_typefreq";
    64     if "$type" widget {
    64     if "$type" widget {
    65         attrib "id" > «$id»
    65         attrib "id" > «$id»
    66         attrib "type" > «$type»
    66         attrib "type" > «$type»
    67         if "$freq" {
    67         if "$freq" {
    68             if "not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]?'))" {
    68             if "not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]?'))" {
    69                 error > Widget id:«$id» label:«$label» has wrong syntax of frequency forcing «$freq»
    69                 error > Widget id:«$id» label:«full_decl» has wrong syntax of frequency forcing «$freq»
    70             }
    70             }
    71             attrib "freq" > «$freq»
    71             attrib "freq" > «$freq»
    72         }
    72         }
    73         foreach "str:split(substring-after($args, ':'), ':')" {
    73         foreach "str:split(substring-after($args, ':'), ':')" {
    74             arg {
    74             arg {
    75                 attrib "value" > «.»
    75                 attrib "value" > «.»
    76             }
    76             }
    77         }
    77         }
    78         const "paths", "substring-after($description,'@')";
    78         const "paths", "substring-after($declaration,'@')";
    79         foreach "str:split($paths, '@')" {
    79         foreach "str:split($paths, '@')" {
    80             if "string-length(.) > 0" path {
    80             if "string-length(.) > 0" path {
    81                 // 1 : global match
    81                 // 1 : global match
    82                 // 2 : /path
    82                 // 2 : /path
    83                 // 3 : [accepts]
    83                 // 3 : [accepts]
    94                     when "$pathminmaxcount = 2" {
    94                     when "$pathminmaxcount = 2" {
    95                         attrib "min" > «$pathminmax[1]»
    95                         attrib "min" > «$pathminmax[1]»
    96                         attrib "max" > «$pathminmax[2]»
    96                         attrib "max" > «$pathminmax[2]»
    97                     }
    97                     }
    98                     when "$pathminmaxcount = 1 or $pathminmaxcount > 2" {
    98                     when "$pathminmaxcount = 1 or $pathminmaxcount > 2" {
    99                         error > Widget id:«$id» label:«$label» has wrong syntax of path section «$pathminmax»
    99                         error > Widget id:«$id» label:«full_decl» has wrong syntax of path section «$pathminmax»
   100                     }
   100                     }
   101                 }
   101                 }
   102                 if "$indexed_hmitree" choose {
   102                 if "$indexed_hmitree" choose {
   103                     when "regexp:test($path,'^\.[a-zA-Z0-9_]+$')" {
   103                     when "regexp:test($path,'^\.[a-zA-Z0-9_]+$')" {
   104                         attrib "type" > PAGE_LOCAL
   104                         attrib "type" > PAGE_LOCAL
   108                     }
   108                     }
   109                     otherwise {
   109                     otherwise {
   110                         const "item", "$indexed_hmitree/*[@hmipath = $path]";
   110                         const "item", "$indexed_hmitree/*[@hmipath = $path]";
   111                         const "pathtype", "local-name($item)";
   111                         const "pathtype", "local-name($item)";
   112                         if "$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')" {
   112                         if "$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')" {
   113                             error > Widget id:«$id» label:«$label» path section «$pathminmax» use min and max on non mumeric value
   113                             error > Widget id:«$id» label:«full_decl» path section «$pathminmax» use min and max on non mumeric value
   114                         }
   114                         }
   115                         if "count($item) = 1" {
   115                         if "count($item) = 1" {
   116                             attrib "index" > «$item/@index»
   116                             attrib "index" > «$item/@index»
   117                             attrib "type" > «$pathtype»
   117                             attrib "type" > «$pathtype»
   118                         }
   118                         }