|
1 // parse_labels.ysl2 |
|
2 |
|
3 |
|
4 // Parses: |
|
5 // "HMI:WidgetType:param1:param2@path1,path1min,path1max@path2" |
|
6 // |
|
7 // Into: |
|
8 // widget type="WidgetType" id="blah456" { |
|
9 // arg value="param1"; |
|
10 // arg value="param2"; |
|
11 // path value=".path1" index=".path1" min="path1min" max="path1max" type="PAGE_LOCAL"; |
|
12 // path value="/path1" index="348" type="HMI_INT"; |
|
13 // path value="path4" index="path4" type="HMI_LOCAL"; |
|
14 // } |
|
15 // |
|
16 template "*", mode="parselabel" { |
|
17 const "label","@inkscape:label"; |
|
18 const "id","@id"; |
|
19 const "description", "substring-after($label,'HMI:')"; |
|
20 |
|
21 const "_args", "substring-before($description,'@')"; |
|
22 const "args" choose { |
|
23 when "$_args" value "$_args"; |
|
24 otherwise value "$description"; |
|
25 } |
|
26 |
|
27 const "_type", "substring-before($args,':')"; |
|
28 const "type" choose { |
|
29 when "$_type" value "$_type"; |
|
30 otherwise value "$args"; |
|
31 } |
|
32 |
|
33 if "$type" widget { |
|
34 attrib "id" > «$id» |
|
35 attrib "type" > «$type» |
|
36 foreach "str:split(substring-after($args, ':'), ':')" { |
|
37 arg { |
|
38 attrib "value" > «.» |
|
39 } |
|
40 } |
|
41 const "paths", "substring-after($description,'@')"; |
|
42 foreach "str:split($paths, '@')" { |
|
43 if "string-length(.) > 0" path { |
|
44 const "pathminmax", "str:split(.,',')"; |
|
45 const "path", "$pathminmax[1]"; |
|
46 const "pathminmaxcount", "count($pathminmax)"; |
|
47 attrib "value" > «$path» |
|
48 choose { |
|
49 when "$pathminmaxcount = 3" { |
|
50 attrib "min" > «$pathminmax[2]» |
|
51 attrib "max" > «$pathminmax[3]» |
|
52 } |
|
53 when "$pathminmaxcount = 2" { |
|
54 error > Widget id:«$id» label:«$label» has wrong syntax of path section «$pathminmax» |
|
55 } |
|
56 } |
|
57 choose { |
|
58 when "regexp:test($path,'^\.[a-zA-Z0-9_]+$')" { |
|
59 attrib "type" > PAGE_LOCAL |
|
60 } |
|
61 when "regexp:test($path,'^[a-zA-Z0-9_]+$')" { |
|
62 attrib "type" > HMI_LOCAL |
|
63 } |
|
64 otherwise { |
|
65 const "item", "$indexed_hmitree/*[@hmipath = $path]"; |
|
66 const "pathtype", "local-name($item)"; |
|
67 if "$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')" { |
|
68 error > Widget id:«$id» label:«$label» path section «$pathminmax» use min and max on non mumeric value |
|
69 } |
|
70 if "count($item) = 1" { |
|
71 attrib "index" > «$item/@index» |
|
72 attrib "type" > «$pathtype» |
|
73 } |
|
74 } |
|
75 } |
|
76 } |
|
77 } |
|
78 } |
|
79 } |
|
80 |