SVGHMI: Extend widget labels parsing to allow expressing widget's accepted types in labels svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Mon, 03 May 2021 00:06:03 +0200
branchsvghmi
changeset 3236 e4e27c4efb96
parent 3235 b2b6bf45aa2d
child 3237 d000a91d1e95
SVGHMI: Extend widget labels parsing to allow expressing widget's accepted types in labels
svghmi/parse_labels.ysl2
--- a/svghmi/parse_labels.ysl2	Mon May 03 00:04:08 2021 +0200
+++ b/svghmi/parse_labels.ysl2	Mon May 03 00:06:03 2021 +0200
@@ -13,7 +13,10 @@
 //      path value="path4" index="path4" type="HMI_LOCAL";
 //  }
 //
-template "*", mode="parselabel" {
+const "pathregex",!"'^([^\[,]+)(\[[^\]]+\])?([\d,]*)$'"!;
+
+template "*", mode="parselabel" 
+{
     const "label","@inkscape:label";
     const "id","@id";
     const "description", "substring-after($label,'HMI:')";
@@ -41,16 +44,24 @@
         const "paths", "substring-after($description,'@')";
         foreach "str:split($paths, '@')" {
             if "string-length(.) > 0" path {
-                const "pathminmax", "str:split(.,',')";
-                const "path", "$pathminmax[1]";
+                // 1 : global match
+                // 2 : /path
+                // 3 : [accepts]
+                // 4 : min,max
+                const "path_match", "regexp:match(.,$pathregex)";
+                const "pathminmax", "str:split($path_match[4],',')";
+                const "path", "$path_match[2]";
+                const "path_accepts", "$path_match[3]";
                 const "pathminmaxcount", "count($pathminmax)";
                 attrib "value" > «$path»
+                if "string-length($path_accepts)"
+                    attrib "accepts" > «$path_accepts»
                 choose {
-                    when "$pathminmaxcount = 3" {
-                        attrib "min" > «$pathminmax[2]»
-                        attrib "max" > «$pathminmax[3]»
+                    when "$pathminmaxcount = 2" {
+                        attrib "min" > «$pathminmax[1]»
+                        attrib "max" > «$pathminmax[2]»
                     }
-                    when "$pathminmaxcount = 2" {
+                    when "$pathminmaxcount = 1 or $pathminmaxcount > 2" {
                         error > Widget id:«$id» label:«$label» has wrong syntax of path section «$pathminmax»
                     }
                 }