@@ -575,6 +575,21 @@ func cmdSetIfAbsent(opts *Options, env CmdEnvironment) (*build.File, error) {
575575 return env .File , nil
576576}
577577
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+
578593func getAttrValueExpr (attr string , args []string , env CmdEnvironment ) build.Expr {
579594 switch {
580595 case attr == "kind" :
@@ -585,9 +600,8 @@ func getAttrValueExpr(attr string, args []string, env CmdEnvironment) build.Expr
585600 list = append (list , & build.LiteralExpr {Token : i })
586601 }
587602 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 )
591605 case IsList (attr ):
592606 var list []build.Expr
593607 for _ , arg := range args {
0 commit comments