apple / pkl-go

Pkl bindings for the Go programming language
https://pkl-lang.org/go/current/index.html
Apache License 2.0
259 stars 24 forks source link

Turn pkl Regex type into go regexp.Regexp type #44

Open VincentSchmid opened 5 months ago

VincentSchmid commented 5 months ago

It would be nice to have the Regex type convert to the regexp.Regexp type. Currently, I use a string and have to turn the string into regex within go before using it.

bioball commented 5 months ago

Pkl's regexes follow Java syntax. They don't map 1:1 to Go regex, which is why they don't get turned into Go's regexp.Regexp.

The pkl#Regex struct exists for compatibility sake, but it's not really meant to represent config data.

I'd actually suggest that you represent regexes as strings in Pkl if you mean to pass it into Go. You can add a @SourceCode annotation to get language injection in pkl-intellij:

@SourceCode { language = "RegExp" }
myRegex: String