mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-27 06:42:04 -03:00
code-gen: make content heuristics regexp engine configurable & generation syntax-aware
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
//go:build oniguruma
|
||||
// +build oniguruma
|
||||
|
||||
package regex
|
||||
@ -8,8 +9,17 @@ import (
|
||||
|
||||
type EnryRegexp = *rubex.Regexp
|
||||
|
||||
func MustCompile(str string) EnryRegexp {
|
||||
return rubex.MustCompileASCII(str)
|
||||
func MustCompile(s string) EnryRegexp {
|
||||
return rubex.MustCompileASCII(s)
|
||||
}
|
||||
|
||||
// MustCompileMultiline matches in multi-line mode by default with Oniguruma.
|
||||
func MustCompileMultiline(s string) EnryRegexp {
|
||||
return MustCompile(s)
|
||||
}
|
||||
|
||||
func MustCompileRuby(s string) EnryRegexp {
|
||||
return MustCompile(s)
|
||||
}
|
||||
|
||||
func QuoteMeta(s string) string {
|
||||
|
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user