edouard@3221: // parse_labels.ysl2 Edouard@2790: Edouard@2843: Edouard@2882: // Parses: Edouard@3594: // "HMI:WidgetType|freq:param1:param2@a=path1,path1min,path1max@b=path2#a+b>3" 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@3594: const "pathregex",!"'^(\w+=)?([^,=]+)([-.\d,]*)$'"!; edouard@3236: Edouard@3579: const "newline" | Edouard@3579: const "twonewlines", "concat($newline,$newline)"; Edouard@3579: Edouard@3473: template "*", mode="parselabel" edouard@3236: { Edouard@3592: const "label","@inkscape:label"; Edouard@3579: const "desc", "svg:desc"; Edouard@3579: Edouard@3579: // add svg:desc field if continuation "\" marker is found at the end of label Edouard@3592: const "len","string-length($label)"; Edouard@3592: const "has_continuation", "substring($label,$len,1)='\\'"; Edouard@3592: const "full_decl" choose{ Edouard@3579: when "$has_continuation" { Edouard@3579: const "_continuation", "substring-before($desc, $twonewlines)"; Edouard@3579: const "continuation" choose { Edouard@3579: when "$_continuation" value "$_continuation"; Edouard@3579: otherwise value "$desc"; Edouard@3579: } Edouard@3592: value "concat(substring($label,1,$len - 1),translate($continuation,$newline,''))"; Edouard@3579: } Edouard@3592: otherwise value "$label"; Edouard@3579: } Edouard@3579: edouard@3097: const "id","@id"; edouard@3259: Edouard@3592: const "declaration", "substring-after($full_decl,'HMI:')"; Edouard@2877: Edouard@3592: const "_args", "substring-before($declaration,'@')"; Edouard@2877: const "args" choose { Edouard@2877: when "$_args" value "$_args"; Edouard@3592: otherwise value "$declaration"; 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@3473: if "not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]?'))" { Edouard@3594: error > Widget id:«$id» label:«$full_decl» has wrong syntax of frequency forcing «$freq» Edouard@3455: } Edouard@3455: attrib "freq" > «$freq» Edouard@3455: } Edouard@3595: Edouard@3594: // find "#" + JS expr at the end Edouard@3593: const "tail", "substring-after($declaration,'@')"; Edouard@3593: const "taillen","string-length($tail)"; Edouard@3594: const "has_enable", "contains($tail, '#')"; Edouard@3593: const "paths" choose{ Edouard@3593: when "$has_enable" { Edouard@3594: value "substring-before($tail,'#')"; Edouard@3593: } Edouard@3593: otherwise value "$tail"; Edouard@3593: } Edouard@3593: if "$has_enable" { Edouard@3594: const "enable_expr", "substring-after($tail,'#')"; Edouard@3594: attrib "enable_expr" value "$enable_expr"; Edouard@3593: } Edouard@3594: Edouard@3595: foreach "str:split(substring-after($args, ':'), ':')" { Edouard@3595: arg { Edouard@3595: attrib "value" > «.» Edouard@3595: } Edouard@3595: } Edouard@3595: Edouard@3594: // for stricter syntax checking, this should make error Edouard@3594: // if $paths contains "@@" or ends with "@" (empty paths) Edouard@3594: Edouard@2877: foreach "str:split($paths, '@')" { Edouard@2877: if "string-length(.) > 0" path { edouard@3236: // 1 : global match Edouard@3594: // 2 : assign= edouard@3236: // 2 : /path Edouard@3594: // 3 : min,max edouard@3236: const "path_match", "regexp:match(.,$pathregex)"; Edouard@3594: const "pathassign", "substring-before($path_match[2],'=')"; edouard@3236: const "pathminmax", "str:split($path_match[4],',')"; Edouard@3594: const "path", "$path_match[3]"; edouard@3097: const "pathminmaxcount", "count($pathminmax)"; Edouard@3594: if "not($path)" Edouard@3594: error > Widget id:«$id» label:«$full_decl» has wrong syntax Edouard@3594: Edouard@3594: attrib "value" value "$path"; Edouard@3594: if "$pathassign" Edouard@3594: attrib "assign" value "$pathassign"; 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@3594: error > Widget id:«$id» label:«$full_decl» 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@3594: error > Widget id:«$id» label:«$full_decl» 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@3579: choose{ Edouard@3579: when "$has_continuation" { Edouard@3579: const "_continuation", "substring-after($desc, $twonewlines)"; Edouard@3579: if "$_continuation" Edouard@3579: desc value "$_continuation"; Edouard@3579: } Edouard@3579: otherwise Edouard@3579: if "$desc" desc value "$desc/text()"; Edouard@3579: } 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: