mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-09-20 15:31:21 +00:00
- update go.mod \w v2 - update all import paths Signed-off-by: Alexander Bezzubov <bzz@apache.org>
52 lines
1005 B
Cheetah
52 lines
1005 B
Cheetah
package data
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"github.com/src-d/enry/v2/data/rule"
|
|
)
|
|
|
|
var ContentHeuristics = map[string]*Heuristics{
|
|
{{ range $ext, $rules := . -}}
|
|
{{ printf "%q" $ext }}: &Heuristics{
|
|
{{ range $rule := $rules -}}
|
|
{{template "Rule" $rule}}
|
|
{{ end -}}
|
|
},
|
|
{{ end -}}
|
|
}
|
|
|
|
{{ define "Rule" -}}
|
|
{{ if eq .Op "And" -}}
|
|
rule.And(
|
|
{{ template "Languages" .Langs -}}
|
|
{{ range $rule := .Rules -}}
|
|
{{template "Rule" $rule}}
|
|
{{ end -}}
|
|
),
|
|
{{- else if eq .Op "Or" -}}
|
|
rule.Or(
|
|
{{ template "Languages" .Langs -}}
|
|
regexp.MustCompile(`{{ .Pattern }}`),
|
|
),
|
|
{{- else if eq .Op "Not" -}}
|
|
rule.Not(
|
|
{{ template "Languages" .Langs -}}
|
|
regexp.MustCompile(`{{ .Pattern }}`),
|
|
),
|
|
{{- else if eq .Op "Always" -}}
|
|
rule.Always(
|
|
{{ template "Languages" .Langs -}}
|
|
),
|
|
{{ end -}}
|
|
{{ end -}}
|
|
|
|
|
|
{{define "Languages" -}}
|
|
{{with . -}}
|
|
rule.MatchingLanguages( {{range .}} {{printf "\"%s\"" .}}, {{end}} ),
|
|
{{ else -}}
|
|
rule.MatchingLanguages(""),
|
|
{{end -}}
|
|
{{end}}
|