1 // parse_labels.ysl2 |
1 // parse_labels.ysl2 |
2 |
2 |
3 |
3 |
4 // Parses: |
4 // Parses: |
5 // "HMI:WidgetType|freq:param1:param2@path1,path1min,path1max@path2#" |
5 // "HMI:WidgetType|freq:param1:param2@a=path1,path1min,path1max@b=path2#a+b>3" |
6 // |
6 // |
7 // Into: |
7 // Into: |
8 // widget type="WidgetType" id="blah456" { |
8 // widget type="WidgetType" id="blah456" { |
9 // arg value="param1"; |
9 // arg value="param1"; |
10 // arg value="param2"; |
10 // arg value="param2"; |
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 const "pathregex",!"'^([^\[,]+)(\[[^\]]+\])?([-.\d,]*)$'"!; |
16 const "pathregex",!"'^(\w+=)?([^,=]+)([-.\d,]*)$'"!; |
17 |
17 |
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" |
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:«full_decl» 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 // find "#" + JS expr at the end |
78 const "tail", "substring-after($declaration,'@')"; |
79 const "tail", "substring-after($declaration,'@')"; |
79 const "taillen","string-length($tail)"; |
80 const "taillen","string-length($tail)"; |
80 const "has_enable", "substring($tail,$taillen,1)='#'"; |
81 const "has_enable", "contains($tail, '#')"; |
81 const "paths" choose{ |
82 const "paths" choose{ |
82 when "$has_enable" { |
83 when "$has_enable" { |
83 value "substring($tail,1,$taillen - 1)"; |
84 value "substring-before($tail,'#')"; |
84 } |
85 } |
85 otherwise value "$tail"; |
86 otherwise value "$tail"; |
86 } |
87 } |
87 if "$has_enable" { |
88 if "$has_enable" { |
88 attrib "has_enable" > yes |
89 const "enable_expr", "substring-after($tail,'#')"; |
|
90 attrib "enable_expr" value "$enable_expr"; |
89 } |
91 } |
|
92 |
|
93 // for stricter syntax checking, this should make error |
|
94 // if $paths contains "@@" or ends with "@" (empty paths) |
|
95 |
90 foreach "str:split($paths, '@')" { |
96 foreach "str:split($paths, '@')" { |
91 if "string-length(.) > 0" path { |
97 if "string-length(.) > 0" path { |
92 // 1 : global match |
98 // 1 : global match |
|
99 // 2 : assign= |
93 // 2 : /path |
100 // 2 : /path |
94 // 3 : [accepts] |
101 // 3 : min,max |
95 // 4 : min,max |
|
96 const "path_match", "regexp:match(.,$pathregex)"; |
102 const "path_match", "regexp:match(.,$pathregex)"; |
|
103 const "pathassign", "substring-before($path_match[2],'=')"; |
97 const "pathminmax", "str:split($path_match[4],',')"; |
104 const "pathminmax", "str:split($path_match[4],',')"; |
98 const "path", "$path_match[2]"; |
105 const "path", "$path_match[3]"; |
99 const "path_accepts", "$path_match[3]"; |
|
100 const "pathminmaxcount", "count($pathminmax)"; |
106 const "pathminmaxcount", "count($pathminmax)"; |
101 attrib "value" > «$path» |
107 if "not($path)" |
102 if "string-length($path_accepts)" |
108 error > Widget id:«$id» label:«$full_decl» has wrong syntax |
103 attrib "accepts" > «$path_accepts» |
109 |
|
110 attrib "value" value "$path"; |
|
111 if "$pathassign" |
|
112 attrib "assign" value "$pathassign"; |
104 choose { |
113 choose { |
105 when "$pathminmaxcount = 2" { |
114 when "$pathminmaxcount = 2" { |
106 attrib "min" > «$pathminmax[1]» |
115 attrib "min" > «$pathminmax[1]» |
107 attrib "max" > «$pathminmax[2]» |
116 attrib "max" > «$pathminmax[2]» |
108 } |
117 } |
109 when "$pathminmaxcount = 1 or $pathminmaxcount > 2" { |
118 when "$pathminmaxcount = 1 or $pathminmaxcount > 2" { |
110 error > Widget id:«$id» label:«full_decl» has wrong syntax of path section «$pathminmax» |
119 error > Widget id:«$id» label:«$full_decl» has wrong syntax of path section «$pathminmax» |
111 } |
120 } |
112 } |
121 } |
113 if "$indexed_hmitree" choose { |
122 if "$indexed_hmitree" choose { |
114 when "regexp:test($path,'^\.[a-zA-Z0-9_]+$')" { |
123 when "regexp:test($path,'^\.[a-zA-Z0-9_]+$')" { |
115 attrib "type" > PAGE_LOCAL |
124 attrib "type" > PAGE_LOCAL |
119 } |
128 } |
120 otherwise { |
129 otherwise { |
121 const "item", "$indexed_hmitree/*[@hmipath = $path]"; |
130 const "item", "$indexed_hmitree/*[@hmipath = $path]"; |
122 const "pathtype", "local-name($item)"; |
131 const "pathtype", "local-name($item)"; |
123 if "$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')" { |
132 if "$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')" { |
124 error > Widget id:«$id» label:«full_decl» path section «$pathminmax» use min and max on non mumeric value |
133 error > Widget id:«$id» label:«$full_decl» path section «$pathminmax» use min and max on non mumeric value |
125 } |
134 } |
126 if "count($item) = 1" { |
135 if "count($item) = 1" { |
127 attrib "index" > «$item/@index» |
136 attrib "index" > «$item/@index» |
128 attrib "type" > «$pathtype» |
137 attrib "type" > «$pathtype» |
129 } |
138 } |