mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-14 15:32:24 +00:00
c6d74bca66
fixed autogenerated comment changed constant types names GetLanguageByShebang doesn't print errors languageInfo struct change to have only necessary fields GetLanguageByShebang has a comment now
51 lines
1.5 KiB
Cheetah
51 lines
1.5 KiB
Cheetah
package slinguist
|
|
|
|
// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/simple-linguist.v1/internal/code-generator
|
|
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
|
// Extracted from github/linguist commit: {{ getCommit }}
|
|
|
|
import (
|
|
"path/filepath"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
func GetLanguageByContent(filename string, content []byte) (lang string, safe bool) {
|
|
ext := strings.ToLower(filepath.Ext(filename))
|
|
if fnMatcher, ok := matchers[ext]; ok {
|
|
lang, safe = fnMatcher(content)
|
|
return
|
|
}
|
|
|
|
return GetLanguageByExtension(filename)
|
|
}
|
|
|
|
type languageMatcher func ([]byte) (string, bool)
|
|
|
|
var matchers = map[string]languageMatcher{
|
|
{{ range $index, $disambiguator := . -}}
|
|
{{ printf "%q" $disambiguator.Extension }}: func(i []byte) (string, bool) {
|
|
{{ 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(i)
|
|
{{- if lt $j (len $language.LogicRelations) }} {{index $language.LogicRelations $j}} {{- end -}} {{ end }} {
|
|
return {{ printf "%q" $language.Language }}, true
|
|
}
|
|
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end}}
|
|
|
|
return {{ returnLanguage $disambiguator.Languages }}, {{ safeLanguage $disambiguator.Languages }}
|
|
},
|
|
{{ end -}}
|
|
}
|
|
|
|
var (
|
|
{{ range $index, $heuristic := getAllHeuristics . -}}
|
|
{{ $heuristic.Name }} = regexp.MustCompile(`{{ $heuristic.Regexp }}`)
|
|
{{ end -}}
|
|
) |