tartrazine/internal/code-generator/assets/content.go.tmpl

34 lines
1008 B
Cheetah
Raw Normal View History

package data
2017-04-05 14:01:31 +00:00
import "gopkg.in/toqueteos/substring.v1"
2017-04-05 14:01:31 +00:00
2017-05-31 10:07:46 +00:00
type languageMatcher func ([]byte) []string
2017-04-05 14:01:31 +00:00
var ContentMatchers = map[string]languageMatcher{
2017-04-05 14:01:31 +00:00
{{ range $index, $disambiguator := . -}}
2017-05-31 10:07:46 +00:00
{{ printf "%q" $disambiguator.Extension }}: func(i []byte) []string {
2017-04-05 14:01:31 +00:00
{{ 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))
2017-04-05 14:01:31 +00:00
{{- if lt $j (len $language.LogicRelations) }} {{index $language.LogicRelations $j}} {{- end -}} {{ end }} {
2017-05-31 10:07:46 +00:00
return []string{ {{- printf "%q" $language.Language -}} }
2017-04-05 14:01:31 +00:00
}
2017-04-05 14:01:31 +00:00
{{- end -}}
{{- end -}}
{{- end}}
2017-05-31 10:07:46 +00:00
return {{ returnLanguages $disambiguator.Languages | returnStringSlice }}
2017-04-05 14:01:31 +00:00
},
{{ end -}}
}
var (
{{ range $index, $heuristic := getAllHeuristics . -}}
{{ $heuristic.Name }} = substring.Regexp(`{{ $heuristic.Regexp }}`)
2017-04-05 14:01:31 +00:00
{{ end -}}
)