edouard@3221: // parse_labels.ysl2 Edouard@2790: Edouard@2843: Edouard@2882: // Parses: Edouard@3408: // "HMI:WidgetType|freq:param1:param2@path1,path1min,path1max@path2" Edouard@2882: // Edouard@2882: // Into: Edouard@2893: // widget type="WidgetType" id="blah456" { Edouard@2882: // arg value="param1"; Edouard@2882: // arg value="param2"; edouard@3097: // path value=".path1" index=".path1" min="path1min" max="path1max" type="PAGE_LOCAL"; Edouard@3060: // path value="/path1" index="348" type="HMI_INT"; Edouard@3060: // path value="path4" index="path4" type="HMI_LOCAL"; Edouard@2882: // } Edouard@2882: // edouard@3236: const "pathregex",!"'^([^\[,]+)(\[[^\]]+\])?([\d,]*)$'"!; edouard@3236: Edouard@3469: template "*", mode="parselabel" edouard@3236: { edouard@2886: const "label","@inkscape:label"; edouard@3097: const "id","@id"; edouard@3259: Edouard@2877: const "description", "substring-after($label,'HMI:')"; Edouard@2877: Edouard@2877: const "_args", "substring-before($description,'@')"; Edouard@2877: const "args" choose { Edouard@2877: when "$_args" value "$_args"; Edouard@2877: otherwise value "$description"; Edouard@2877: } Edouard@2877: Edouard@3408: const "_typefreq", "substring-before($args,':')"; Edouard@3408: const "typefreq" choose { Edouard@3408: when "$_typefreq" value "$_typefreq"; Edouard@2877: otherwise value "$args"; Edouard@2877: } Edouard@2877: edouard@3412: const "freq", "substring-after($typefreq,'|')"; Edouard@3408: Edouard@3408: const "_type", "substring-before($typefreq,'|')"; Edouard@3408: const "type" choose { Edouard@3408: when "$_type" value "$_type"; Edouard@3408: otherwise value "$typefreq"; Edouard@3408: } edouard@2886: if "$type" widget { edouard@3097: attrib "id" > «$id» Edouard@2877: attrib "type" > «$type» Edouard@3455: if "$freq" { Edouard@3469: if "not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]?'))" { Edouard@3455: error > Widget id:«$id» label:«$label» has wrong syntax of frequency forcing «$freq» Edouard@3455: } Edouard@3455: attrib "freq" > «$freq» Edouard@3455: } Edouard@2877: foreach "str:split(substring-after($args, ':'), ':')" { Edouard@2877: arg { Edouard@2877: attrib "value" > «.» Edouard@2877: } Edouard@2877: } Edouard@2877: const "paths", "substring-after($description,'@')"; Edouard@2877: foreach "str:split($paths, '@')" { Edouard@2877: if "string-length(.) > 0" path { edouard@3236: // 1 : global match edouard@3236: // 2 : /path edouard@3236: // 3 : [accepts] edouard@3236: // 4 : min,max edouard@3236: const "path_match", "regexp:match(.,$pathregex)"; edouard@3236: const "pathminmax", "str:split($path_match[4],',')"; edouard@3236: const "path", "$path_match[2]"; edouard@3236: const "path_accepts", "$path_match[3]"; edouard@3097: const "pathminmaxcount", "count($pathminmax)"; edouard@3097: attrib "value" > «$path» edouard@3236: if "string-length($path_accepts)" edouard@3236: attrib "accepts" > «$path_accepts» edouard@3017: choose { edouard@3236: when "$pathminmaxcount = 2" { edouard@3236: attrib "min" > «$pathminmax[1]» edouard@3236: attrib "max" > «$pathminmax[2]» edouard@3097: } edouard@3236: when "$pathminmaxcount = 1 or $pathminmaxcount > 2" { edouard@3097: error > Widget id:«$id» label:«$label» has wrong syntax of path section «$pathminmax» edouard@3097: } edouard@3097: } edouard@3229: if "$indexed_hmitree" choose { edouard@3127: when "regexp:test($path,'^\.[a-zA-Z0-9_]+$')" { edouard@3097: attrib "type" > PAGE_LOCAL edouard@3097: } edouard@3127: when "regexp:test($path,'^[a-zA-Z0-9_]+$')" { edouard@3097: attrib "type" > HMI_LOCAL edouard@3017: } edouard@3017: otherwise { edouard@3097: const "item", "$indexed_hmitree/*[@hmipath = $path]"; edouard@3097: const "pathtype", "local-name($item)"; edouard@3097: if "$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')" { edouard@3097: error > Widget id:«$id» label:«$label» path section «$pathminmax» use min and max on non mumeric value edouard@3097: } edouard@3097: if "count($item) = 1" { edouard@3097: attrib "index" > «$item/@index» edouard@3097: attrib "type" > «$pathtype» edouard@3017: } edouard@3017: } Edouard@2911: } Edouard@2877: } Edouard@2877: } edouard@3259: if "svg:desc" desc value "svg:desc/text()"; Edouard@2877: } Edouard@2877: } Edouard@2877: edouard@3229: edouard@3229: // Templates to generate label back from parsed tree edouard@3229: template "arg", mode="genlabel" > :«@value» edouard@3229: edouard@3229: template "path", mode="genlabel" { edouard@3229: > @«@value» edouard@3230: if "string-length(@min)>0 or string-length(@max)>0" > ,«@min»,«@max» edouard@3229: } edouard@3229: edouard@3229: template "widget", mode="genlabel" { edouard@3229: > HMI:«@type» edouard@3229: apply "arg", mode="genlabel"; edouard@3229: apply "path", mode="genlabel"; edouard@3229: } edouard@3229: