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

52 lines
1003 B
Cheetah
Raw Normal View History

package data
2017-04-05 14:01:31 +00:00
import (
"regexp"
2017-04-05 14:01:31 +00:00
"gopkg.in/src-d/enry.v1/data/rule"
)
var ContentHeuristics = map[string]*Heuristics{
{{ range $ext, $rules := . -}}
{{ printf "%q" $ext }}: &Heuristics{
{{ range $rule := $rules -}}
{{template "Rule" $rule}}
{{ end -}}
},
2017-04-05 14:01:31 +00:00
{{ 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}}