Hi, great library you have here! We are building a file globbing library (https://github.com/goreleaser/fileglob) on top of glob which required us to write some helper functions that operate on glob/syntax/ast. Maybe some of these functions are useful to your users and could be exposed directly in the glob library.
ContainsMatchers: Returns true if the pattern contains matchers and false otherwise. This is useful to determine whether the pattern directly references a file or multiple files via matchers.
UnquoteMeta: For patterns without matchers, return the static text represented by the pattern. This is useful to determine which file is directly referenced by a pattern that may contain escaped matchers.
Currently, using these functions in our package results in the pattern being parsed multiple times: Once for every function and then finally for the actual compilation.
Also, it would be useful to allow for AST manipulation. This could be used to inject globbing options, perform queries on the AST (like the functions above) or to extend the functionality of this library. https://github.com/antonmedv/expr uses a great pattern for this, the Patcher: https://github.com/antonmedv/expr/blob/master/docs/Visitor-and-Patch.md. In glob this could be done by passing a variadic list of function operating on the AST to the Compile function:
var containsMatchers bool
# MustCompile(string, func(rootNode ...*ast.Node))
glob.MustCompile("/foo/*", ContainsMatchers(&containsMatchers))
What do you think? If you think these ideas are not a good fit for glob you can close this issue.
Hi, great library you have here! We are building a file globbing library (https://github.com/goreleaser/fileglob) on top of
glob
which required us to write some helper functions that operate onglob/syntax/ast
. Maybe some of these functions are useful to your users and could be exposed directly in theglob
library.Consider the following example (source code can be found here: https://github.com/goreleaser/fileglob/blob/main/prefix.go):
ContainsMatchers
: Returnstrue
if the pattern contains matchers andfalse
otherwise. This is useful to determine whether the pattern directly references a file or multiple files via matchers.UnquoteMeta
: For patterns without matchers, return the static text represented by the pattern. This is useful to determine which file is directly referenced by a pattern that may contain escaped matchers.Currently, using these functions in our package results in the pattern being parsed multiple times: Once for every function and then finally for the actual compilation.
Also, it would be useful to allow for AST manipulation. This could be used to inject globbing options, perform queries on the AST (like the functions above) or to extend the functionality of this library. https://github.com/antonmedv/expr uses a great pattern for this, the
Patcher
: https://github.com/antonmedv/expr/blob/master/docs/Visitor-and-Patch.md. Inglob
this could be done by passing a variadic list of function operating on the AST to theCompile
function:What do you think? If you think these ideas are not a good fit for
glob
you can close this issue.