mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-19 06:33:06 -03:00
Rearranged code
This commit is contained in:
@ -4,8 +4,8 @@ package slinguist
|
||||
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||
// Extracted from github/linguist commit: {{ getCommit }}
|
||||
|
||||
// languagesByAlias keeps alias for different languages and use the name of the languages as a alias too. All the
|
||||
// keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores.
|
||||
// languagesByAlias keeps alias for different languages and use the name of the languages as an alias too.
|
||||
// All the keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores.
|
||||
var languagesByAlias = map[string]string{
|
||||
{{range $alias, $language := . -}}
|
||||
"{{ $alias }}": {{ printf "%q" $language -}},
|
||||
|
@ -5,25 +5,12 @@ package slinguist
|
||||
// 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)
|
||||
} else {
|
||||
lang = OtherLanguage
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type languageMatcher func ([]byte) (string, bool)
|
||||
|
||||
var matchers = map[string]languageMatcher{
|
||||
var contentMatchers = map[string]languageMatcher{
|
||||
{{ range $index, $disambiguator := . -}}
|
||||
{{ printf "%q" $disambiguator.Extension }}: func(i []byte) (string, bool) {
|
||||
{{ range $i, $language := $disambiguator.Languages -}}
|
||||
|
@ -5,7 +5,13 @@ package slinguist
|
||||
// Extracted from github/linguist commit: {{ getCommit }}
|
||||
|
||||
var languagesByExtension = map[string][]string{
|
||||
{{range $extension, $languages := . -}}
|
||||
{{range $extension, $languages := .LanguagesByExtension -}}
|
||||
"{{ $extension }}": { {{- $languages | formatStringSlice -}} },
|
||||
{{end -}}
|
||||
}
|
||||
|
||||
var extensionsByLanguage = map[string][]string{
|
||||
{{range $language, $extensions := .ExtensionsByLanguage -}}
|
||||
"{{ $language }}": { {{- $extensions | formatStringSlice -}} },
|
||||
{{end -}}
|
||||
}
|
||||
|
@ -3,14 +3,13 @@ package generator
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"text/template"
|
||||
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Aliases reads from buf and builds aliases_map.go file from aliasesTmplPath.
|
||||
// Aliases reads from buf and builds source file from aliasesTmplPath.
|
||||
func Aliases(data []byte, aliasesTmplPath, aliasesTmplName, commit string) ([]byte, error) {
|
||||
languages := make(map[string]*languageInfo)
|
||||
if err := yaml.Unmarshal(data, &languages); err != nil {
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Documentation reads from buf and builds documentation_matchers.go file from documentationTmplPath.
|
||||
// Documentation reads from buf and builds source file from documentationTmplPath.
|
||||
func Documentation(data []byte, documentationTmplPath, documentationTmplName, commit string) ([]byte, error) {
|
||||
var regexpList []string
|
||||
if err := yaml.Unmarshal(data, ®expList); err != nil {
|
||||
|
@ -9,18 +9,25 @@ import (
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Extensions reads from buf and builds extensions_map.go file from extensionsTmplPath.
|
||||
type extensionsInfo struct {
|
||||
LanguagesByExtension map[string][]string
|
||||
ExtensionsByLanguage map[string][]string
|
||||
}
|
||||
|
||||
// Extensions reads from buf and builds source file from extensionsTmplPath.
|
||||
func Extensions(data []byte, extensionsTmplPath, extensionsTmplName, commit string) ([]byte, error) {
|
||||
languages := make(map[string]*languageInfo)
|
||||
if err := yaml.Unmarshal(data, &languages); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extInfo := &extensionsInfo{}
|
||||
orderedKeyList := getAlphabeticalOrderedKeys(languages)
|
||||
languagesByExtension := buildExtensionLanguageMap(languages, orderedKeyList)
|
||||
extInfo.LanguagesByExtension = buildExtensionLanguageMap(languages, orderedKeyList)
|
||||
extInfo.ExtensionsByLanguage = buildLanguageExtensionsMap(languages)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
if err := executeExtensionsTemplate(buf, languagesByExtension, extensionsTmplPath, extensionsTmplName, commit); err != nil {
|
||||
if err := executeExtensionsTemplate(buf, extInfo, extensionsTmplPath, extensionsTmplName, commit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -39,14 +46,25 @@ func buildExtensionLanguageMap(languages map[string]*languageInfo, orderedKeyLis
|
||||
return extensionLangsMap
|
||||
}
|
||||
|
||||
func executeExtensionsTemplate(out io.Writer, languagesByExtension map[string][]string, extensionsTmplPath, extensionsTmpl, commit string) error {
|
||||
func buildLanguageExtensionsMap(languages map[string]*languageInfo) map[string][]string {
|
||||
langExtensionMap := make(map[string][]string, len(languages))
|
||||
for lang, info := range languages {
|
||||
if len(info.Extensions) > 0 {
|
||||
langExtensionMap[lang] = info.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
return langExtensionMap
|
||||
}
|
||||
|
||||
func executeExtensionsTemplate(out io.Writer, extInfo *extensionsInfo, extensionsTmplPath, extensionsTmpl, commit string) error {
|
||||
fmap := template.FuncMap{
|
||||
"getCommit": func() string { return commit },
|
||||
"formatStringSlice": func(slice []string) string { return `"` + strings.Join(slice, `","`) + `"` },
|
||||
}
|
||||
|
||||
t := template.Must(template.New(extensionsTmpl).Funcs(fmap).ParseFiles(extensionsTmplPath))
|
||||
if err := t.Execute(out, languagesByExtension); err != nil {
|
||||
if err := t.Execute(out, extInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Filenames reads from buf and builds filenames_map.go file from filenamesTmplPath.
|
||||
// Filenames reads from buf and builds source file from filenamesTmplPath.
|
||||
func Filenames(data []byte, filenamesTmplPath, filenamesTmplName, commit string) ([]byte, error) {
|
||||
languages := make(map[string]*languageInfo)
|
||||
if err := yaml.Unmarshal(data, &languages); err != nil {
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// Func is the function's type that generate the files from templates.
|
||||
// Func is the function's type that generate source file from a data to be parsed and a template.
|
||||
type Func func(dataToParse []byte, templatePath string, template string, commit string) ([]byte, error)
|
||||
|
||||
// FromFile read data to parse from a file named fileToParse and write the generated source code to a file named outPath. The generated
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
const (
|
||||
lingustURL = "https://github.com/github/linguist.git"
|
||||
commitTree = "60f864a138650dd17fafc94814be9ee2d3aaef8c"
|
||||
commitTest = "fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7"
|
||||
commitTest = "0123456789abcdef0123456789abcdef01234567"
|
||||
|
||||
// Extensions test
|
||||
extensionsTestFile = "test_files/extensions.test.yml"
|
||||
@ -77,6 +77,10 @@ type GeneratorTestSuite struct {
|
||||
tmpLinguist string
|
||||
}
|
||||
|
||||
func TestGeneratorTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(GeneratorTestSuite))
|
||||
}
|
||||
|
||||
func (g *GeneratorTestSuite) SetupSuite() {
|
||||
tmpLinguist, err := ioutil.TempDir("", "linguist-")
|
||||
assert.NoError(g.T(), err)
|
||||
@ -116,7 +120,7 @@ func (g *GeneratorTestSuite) TestFromFile() {
|
||||
wantOut string
|
||||
}{
|
||||
{
|
||||
name: "TestFromFile_Language",
|
||||
name: "TestFromFile_Extensions",
|
||||
fileToParse: extensionsTestFile,
|
||||
tmplPath: extensionsTestTmplPath,
|
||||
tmplName: extensionsTestTmplName,
|
||||
@ -201,7 +205,7 @@ func (g *GeneratorTestSuite) TestFromFile() {
|
||||
assert.NoError(g.T(), err)
|
||||
out, err := ioutil.ReadFile(outPath.Name())
|
||||
assert.NoError(g.T(), err)
|
||||
assert.EqualValues(g.T(), gold, out, fmt.Sprintf("FromFile() = %v, want %v", string(out), string(test.wantOut)))
|
||||
assert.EqualValues(g.T(), gold, out, fmt.Sprintf("%v: %v, expected: %v", test.name, string(out), string(test.wantOut)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,10 +240,6 @@ func (g *GeneratorTestSuite) TestFrequencies() {
|
||||
assert.NoError(g.T(), err)
|
||||
out, err := ioutil.ReadFile(outPath.Name())
|
||||
assert.NoError(g.T(), err)
|
||||
assert.EqualValues(g.T(), gold, out, fmt.Sprintf("Frequencies() = %v, want %v", string(out), string(test.wantOut)))
|
||||
assert.EqualValues(g.T(), gold, out, fmt.Sprintf("%v: %v, expected: %v", test.name, string(out), string(test.wantOut)))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratorTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(GeneratorTestSuite))
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// Heuristics reads from buf and builds content.go file from contentTmplPath.
|
||||
// Heuristics reads from buf and builds source file from contentTmplPath.
|
||||
func Heuristics(heuristics []byte, contentTmplPath, contentTmplName, commit string) ([]byte, error) {
|
||||
disambiguators, err := getDisambiguators(heuristics)
|
||||
if err != nil {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Interpreters reads from buf and builds interpreters_map.go file from interpretersTmplPath.
|
||||
// Interpreters reads from buf and builds source file from interpretersTmplPath.
|
||||
func Interpreters(data []byte, interpretersTmplPath, interpretersTmplName, commit string) ([]byte, error) {
|
||||
languages := make(map[string]*languageInfo)
|
||||
if err := yaml.Unmarshal(data, &languages); err != nil {
|
||||
|
@ -2,10 +2,10 @@ 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: fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7
|
||||
// Extracted from github/linguist commit: 0123456789abcdef0123456789abcdef01234567
|
||||
|
||||
// languagesByAlias keeps alias for different languages and use the name of the languages as a alias too. All the
|
||||
// keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores.
|
||||
// languagesByAlias keeps alias for different languages and use the name of the languages as an alias too.
|
||||
// All the keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores.
|
||||
var languagesByAlias = map[string]string{
|
||||
"asp": "ASP",
|
||||
"aspx": "ASP",
|
||||
|
@ -2,28 +2,15 @@ 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: fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7
|
||||
// Extracted from github/linguist commit: 0123456789abcdef0123456789abcdef01234567
|
||||
|
||||
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)
|
||||
} else {
|
||||
lang = OtherLanguage
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type languageMatcher func([]byte) (string, bool)
|
||||
|
||||
var matchers = map[string]languageMatcher{
|
||||
var contentMatchers = map[string]languageMatcher{
|
||||
".asc": func(i []byte) (string, bool) {
|
||||
if asc_PublicKey_Matcher_0.Match(i) {
|
||||
return "Public Key", true
|
||||
|
@ -2,7 +2,7 @@ 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: fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7
|
||||
// Extracted from github/linguist commit: 0123456789abcdef0123456789abcdef01234567
|
||||
|
||||
import "gopkg.in/toqueteos/substring.v1"
|
||||
|
||||
|
@ -2,7 +2,7 @@ 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: fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7
|
||||
// Extracted from github/linguist commit: 0123456789abcdef0123456789abcdef01234567
|
||||
|
||||
var languagesByExtension = map[string][]string{
|
||||
".abap": {"ABAP"},
|
||||
@ -10,3 +10,9 @@ var languagesByExtension = map[string][]string{
|
||||
".bsl": {"1C Enterprise"},
|
||||
".os": {"1C Enterprise"},
|
||||
}
|
||||
|
||||
var extensionsByLanguage = map[string][]string{
|
||||
"1C Enterprise": {".bsl", ".os"},
|
||||
"ABAP": {".abap"},
|
||||
"ABNF": {".abnf"},
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ 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: fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7
|
||||
// Extracted from github/linguist commit: 0123456789abcdef0123456789abcdef01234567
|
||||
|
||||
var languagesByFilename = map[string]string{
|
||||
"APKBUILD": "Alpine Abuild",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@ 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: fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7
|
||||
// Extracted from github/linguist commit: 0123456789abcdef0123456789abcdef01234567
|
||||
|
||||
var languagesByInterpreter = map[string][]string{
|
||||
"bash": {"Shell"},
|
||||
|
@ -2,7 +2,7 @@ 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: fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7
|
||||
// Extracted from github/linguist commit: 0123456789abcdef0123456789abcdef01234567
|
||||
|
||||
var languagesType = map[string]Type{
|
||||
"Scaml": Markup,
|
||||
|
@ -2,7 +2,7 @@ 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: fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7
|
||||
// Extracted from github/linguist commit: 0123456789abcdef0123456789abcdef01234567
|
||||
|
||||
import "gopkg.in/toqueteos/substring.v1"
|
||||
|
||||
|
@ -15,7 +15,7 @@ var typeToTypeConst = map[string]string{
|
||||
"prose": "Prose",
|
||||
}
|
||||
|
||||
// Types reads from buf and builds type.go file from typeTmplPath.
|
||||
// Types reads from buf and builds source file from typeTmplPath.
|
||||
func Types(data []byte, typeTmplPath, typeTmplName, commit string) ([]byte, error) {
|
||||
languages := make(map[string]*languageInfo)
|
||||
if err := yaml.Unmarshal(data, &languages); err != nil {
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Vendor reads from buf and builds vendor_matchers.go file from vendorTmplPath.
|
||||
// Vendor reads from buf and builds source file from vendorTmplPath.
|
||||
func Vendor(data []byte, vendorTmplPath, vendorTmplName, commit string) ([]byte, error) {
|
||||
var regexpList []string
|
||||
if err := yaml.Unmarshal(data, ®expList); err != nil {
|
||||
|
@ -11,8 +11,8 @@ const (
|
||||
// languages info file
|
||||
languagesYAML = ".linguist/lib/linguist/languages.yml"
|
||||
|
||||
// extensions_map.go generation
|
||||
extensionsFile = "extensions_map.go"
|
||||
// extension.go generation
|
||||
extensionsFile = "extension.go"
|
||||
extensionsTmplPath = "internal/code-generator/assets/extensions.go.tmpl"
|
||||
extensionsTmpl = "extensions.go.tmpl"
|
||||
|
||||
@ -22,35 +22,35 @@ const (
|
||||
contentTmplPath = "internal/code-generator/assets/content.go.tmpl"
|
||||
contentTmpl = "content.go.tmpl"
|
||||
|
||||
// vendor_matchers.go generation
|
||||
// vendor.go generation
|
||||
vendorYAML = ".linguist/lib/linguist/vendor.yml"
|
||||
vendorFile = "vendor_matchers.go"
|
||||
vendorFile = "vendor.go"
|
||||
vendorTmplPath = "internal/code-generator/assets/vendor.go.tmpl"
|
||||
vendorTmpl = "vendor.go.tmpl"
|
||||
|
||||
// documentation_matchers.go generation
|
||||
// documentation.go generation
|
||||
documentationYAML = ".linguist/lib/linguist/documentation.yml"
|
||||
documentationFile = "documentation_matchers.go"
|
||||
documentationFile = "documentation.go"
|
||||
documentationTmplPath = "internal/code-generator/assets/documentation.go.tmpl"
|
||||
documentationTmpl = "documentation.go.tmpl"
|
||||
|
||||
// type.go generation
|
||||
typeFile = "types_map.go"
|
||||
typeFile = "type.go"
|
||||
typeTmplPath = "internal/code-generator/assets/types.go.tmpl"
|
||||
typeTmpl = "types.go.tmpl"
|
||||
|
||||
// interpreters_map.go generation
|
||||
interpretersFile = "interpreters_map.go"
|
||||
// interpreter.go generation
|
||||
interpretersFile = "interpreter.go"
|
||||
interpretersTmplPath = "internal/code-generator/assets/interpreters.go.tmpl"
|
||||
interpretersTmpl = "interpreters.go.tmpl"
|
||||
|
||||
// filenames_map.go generation
|
||||
filenamesFile = "filenames_map.go"
|
||||
// filename.go generation
|
||||
filenamesFile = "filename.go"
|
||||
filenamesTmplPath = "internal/code-generator/assets/filenames.go.tmpl"
|
||||
filenamesTmpl = "filenames.go.tmpl"
|
||||
|
||||
// aliases_map.go generation
|
||||
aliasesFile = "aliases_map.go"
|
||||
// alias.go generation
|
||||
aliasesFile = "alias.go"
|
||||
aliasesTmplPath = "internal/code-generator/assets/aliases.go.tmpl"
|
||||
aliasesTmpl = "aliases.go.tmpl"
|
||||
|
||||
|
Reference in New Issue
Block a user