roulette/vendor/github.com/alecthomas/chroma/v2/lexers/mysql.go

34 lines
968 B
Go
Raw Normal View History

2023-09-14 22:37:22 +00:00
package lexers
import (
"regexp"
)
var (
mysqlAnalyserNameBetweenBacktickRe = regexp.MustCompile("`[a-zA-Z_]\\w*`")
mysqlAnalyserNameBetweenBracketRe = regexp.MustCompile(`\[[a-zA-Z_]\w*\]`)
)
func init() { // nolint: gochecknoinits
Get("mysql").
SetAnalyser(func(text string) float32 {
nameBetweenBacktickCount := len(mysqlAnalyserNameBetweenBacktickRe.FindAllString(text, -1))
nameBetweenBracketCount := len(mysqlAnalyserNameBetweenBracketRe.FindAllString(text, -1))
var result float32
// Same logic as above in the TSQL analysis.
dialectNameCount := nameBetweenBacktickCount + nameBetweenBracketCount
if dialectNameCount >= 1 && nameBetweenBacktickCount >= (2*nameBetweenBracketCount) {
// Found at least twice as many `name` as [name].
result += 0.5
} else if nameBetweenBacktickCount > nameBetweenBracketCount {
result += 0.2
} else if nameBetweenBacktickCount > 0 {
result += 0.1
}
return result
})
}