code-gen: make content heuristics regexp engine configurable & generation syntax-aware

This commit is contained in:
Alex Bezzubov
2022-12-25 11:56:58 +01:00
parent 0b92f97b9c
commit 5e590f3554
4 changed files with 54 additions and 24 deletions

View File

@ -1,3 +1,4 @@
//go:build !oniguruma
// +build !oniguruma
package regex
@ -12,6 +13,20 @@ func MustCompile(str string) EnryRegexp {
return regexp.MustCompile(str)
}
// MustCompileMultiline mimics Ruby defaults for regexp, where ^$ matches begin/end of line.
// I.e. it converts Ruby regexp syntaxt to RE2 equivalent
func MustCompileMultiline(s string) EnryRegexp {
const multilineModeFlag = "(?m)"
return regexp.MustCompile(multilineModeFlag + s)
}
// MustCompileRuby used for expressions with syntax not supported by RE2.
func MustCompileRuby(s string) EnryRegexp {
// TODO(bzz): find a bettee way?
// This will only trigger a panic on .Match() for the clients
return nil
}
func QuoteMeta(s string) string {
return regexp.QuoteMeta(s)
}