@@ -575,6 +575,21 @@ func cmdSetIfAbsent(opts *Options, env CmdEnvironment) (*build.File, error) {
575
575
return env .File , nil
576
576
}
577
577
578
+ // isFunctionCall parses the args to see if they are arguments to a single
579
+ // function call. This is naïve and does not attempt to parse the inner tokens.
580
+ // example:
581
+ // the user input: "glob(["*.c", "*.h"])"
582
+ // is tokenized to: "glob([\"*.c\",", "\"*.h\"])",
583
+ func isFunctionCall (function string , args [] string ) bool {
584
+ return strings .HasPrefix (args [0 ], function + "(" ) &&
585
+ strings .HasSuffix (args [len (args ) - 1 ], ")" )
586
+ }
587
+
588
+ func functionCallExpr (args []string ) build.Expr {
589
+ joined := strings .Join (args , "" )
590
+ return & build.Ident {Name : joined }
591
+ }
592
+
578
593
func getAttrValueExpr (attr string , args []string , env CmdEnvironment ) build.Expr {
579
594
switch {
580
595
case attr == "kind" :
@@ -585,9 +600,8 @@ func getAttrValueExpr(attr string, args []string, env CmdEnvironment) build.Expr
585
600
list = append (list , & build.LiteralExpr {Token : i })
586
601
}
587
602
return & build.ListExpr {List : list }
588
- case IsList (attr ) && len (args ) == 1 && strings .HasPrefix (args [0 ], "glob(" ):
589
- // Single-value glob
590
- return & build.Ident {Name : args [0 ]}
603
+ case IsList (attr ) && isFunctionCall ("glob" , args ):
604
+ return functionCallExpr (args )
591
605
case IsList (attr ):
592
606
var list []build.Expr
593
607
for _ , arg := range args {
0 commit comments