svghmi/parse_labels.ysl2
branchsvghmi
changeset 3236 e4e27c4efb96
parent 3230 95f07764991f
child 3259 76da573569a6
equal deleted inserted replaced
3235:b2b6bf45aa2d 3236:e4e27c4efb96
    11 //      path value=".path1" index=".path1" min="path1min" max="path1max" type="PAGE_LOCAL";
    11 //      path value=".path1" index=".path1" min="path1min" max="path1max" type="PAGE_LOCAL";
    12 //      path value="/path1" index="348" type="HMI_INT";
    12 //      path value="/path1" index="348" type="HMI_INT";
    13 //      path value="path4" index="path4" type="HMI_LOCAL";
    13 //      path value="path4" index="path4" type="HMI_LOCAL";
    14 //  }
    14 //  }
    15 //
    15 //
    16 template "*", mode="parselabel" {
    16 const "pathregex",!"'^([^\[,]+)(\[[^\]]+\])?([\d,]*)$'"!;
       
    17 
       
    18 template "*", mode="parselabel" 
       
    19 {
    17     const "label","@inkscape:label";
    20     const "label","@inkscape:label";
    18     const "id","@id";
    21     const "id","@id";
    19     const "description", "substring-after($label,'HMI:')";
    22     const "description", "substring-after($label,'HMI:')";
    20 
    23 
    21     const "_args", "substring-before($description,'@')";
    24     const "_args", "substring-before($description,'@')";
    39             }
    42             }
    40         }
    43         }
    41         const "paths", "substring-after($description,'@')";
    44         const "paths", "substring-after($description,'@')";
    42         foreach "str:split($paths, '@')" {
    45         foreach "str:split($paths, '@')" {
    43             if "string-length(.) > 0" path {
    46             if "string-length(.) > 0" path {
    44                 const "pathminmax", "str:split(.,',')";
    47                 // 1 : global match
    45                 const "path", "$pathminmax[1]";
    48                 // 2 : /path
       
    49                 // 3 : [accepts]
       
    50                 // 4 : min,max
       
    51                 const "path_match", "regexp:match(.,$pathregex)";
       
    52                 const "pathminmax", "str:split($path_match[4],',')";
       
    53                 const "path", "$path_match[2]";
       
    54                 const "path_accepts", "$path_match[3]";
    46                 const "pathminmaxcount", "count($pathminmax)";
    55                 const "pathminmaxcount", "count($pathminmax)";
    47                 attrib "value" > «$path»
    56                 attrib "value" > «$path»
       
    57                 if "string-length($path_accepts)"
       
    58                     attrib "accepts" > «$path_accepts»
    48                 choose {
    59                 choose {
    49                     when "$pathminmaxcount = 3" {
    60                     when "$pathminmaxcount = 2" {
    50                         attrib "min" > «$pathminmax[2]»
    61                         attrib "min" > «$pathminmax[1]»
    51                         attrib "max" > «$pathminmax[3]»
    62                         attrib "max" > «$pathminmax[2]»
    52                     }
    63                     }
    53                     when "$pathminmaxcount = 2" {
    64                     when "$pathminmaxcount = 1 or $pathminmaxcount > 2" {
    54                         error > Widget id:«$id» label:«$label» has wrong syntax of path section «$pathminmax»
    65                         error > Widget id:«$id» label:«$label» has wrong syntax of path section «$pathminmax»
    55                     }
    66                     }
    56                 }
    67                 }
    57                 if "$indexed_hmitree" choose {
    68                 if "$indexed_hmitree" choose {
    58                     when "regexp:test($path,'^\.[a-zA-Z0-9_]+$')" {
    69                     when "regexp:test($path,'^\.[a-zA-Z0-9_]+$')" {