mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-13 23:12:24 +00:00
7eafe024af
Signed-off-by: Denys Smirnov <denys@sourced.tech>
34 lines
1008 B
Cheetah
34 lines
1008 B
Cheetah
package data
|
|
|
|
import "gopkg.in/toqueteos/substring.v1"
|
|
|
|
type languageMatcher func ([]byte) []string
|
|
|
|
var ContentMatchers = map[string]languageMatcher{
|
|
{{ range $index, $disambiguator := . -}}
|
|
{{ printf "%q" $disambiguator.Extension }}: func(i []byte) []string {
|
|
{{ range $i, $language := $disambiguator.Languages -}}
|
|
|
|
{{- if not (avoidLanguage $language) }}
|
|
{{- if gt (len $language.Heuristics) 0 }}
|
|
{{- if gt $i 0 }} else {{ end -}}
|
|
if {{- range $j, $heuristic := $language.Heuristics }} {{ $heuristic.Name }}.Match(string(i))
|
|
{{- if lt $j (len $language.LogicRelations) }} {{index $language.LogicRelations $j}} {{- end -}} {{ end }} {
|
|
return []string{ {{- printf "%q" $language.Language -}} }
|
|
}
|
|
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end}}
|
|
|
|
return {{ returnLanguages $disambiguator.Languages | returnStringSlice }}
|
|
},
|
|
{{ end -}}
|
|
}
|
|
|
|
var (
|
|
{{ range $index, $heuristic := getAllHeuristics . -}}
|
|
{{ $heuristic.Name }} = substring.Regexp(`{{ $heuristic.Regexp }}`)
|
|
{{ end -}}
|
|
)
|