mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-23 00:20:09 -03:00
added interpreters_map.go generation
fixed Interpreters comment
This commit is contained in:
parent
6ddbb79af0
commit
2644a7c8da
11
internal/code-generator/assets/interpreters.go.tmpl
Normal file
11
internal/code-generator/assets/interpreters.go.tmpl
Normal file
@ -0,0 +1,11 @@
|
||||
package slinguist
|
||||
|
||||
// CODE GENERATED AUTOMATICALLY WITH github.com/src-d/simple-linguist/cli/slinguist-generate
|
||||
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||
// Extracted from github/linguist commit: {{ getCommit }}
|
||||
|
||||
var languagesByInterpreter = map[string][]string{
|
||||
{{range $interpreter, $languages := . -}}
|
||||
"{{ $interpreter }}": { {{- $languages | formatStringSlice -}} },
|
||||
{{end -}}
|
||||
}
|
@ -41,6 +41,12 @@ const (
|
||||
typesGold = "test_files/type.gold"
|
||||
typesTestTmplPath = "test_files/type.test.go.tmpl"
|
||||
typesTestTmplName = "type.test.go.tmpl"
|
||||
|
||||
// Interpreters test
|
||||
interpretersTestFile = "test_files/interpreters.test.yml"
|
||||
interpretersGold = "test_files/interpreters.gold"
|
||||
interpretersTestTmplPath = "test_files/interpreters.test.go.tmpl"
|
||||
interpretersTestTmplName = "interpreters.test.go.tmpl"
|
||||
)
|
||||
|
||||
func TestFromFile(t *testing.T) {
|
||||
@ -59,6 +65,9 @@ func TestFromFile(t *testing.T) {
|
||||
goldTypes, err := ioutil.ReadFile(typesGold)
|
||||
assert.NoError(t, err)
|
||||
|
||||
goldInterpreters, err := ioutil.ReadFile(interpretersGold)
|
||||
assert.NoError(t, err)
|
||||
|
||||
outPathLang, err := ioutil.TempFile("/tmp", "generator-test-")
|
||||
assert.NoError(t, err)
|
||||
defer os.Remove(outPathLang.Name())
|
||||
@ -79,6 +88,10 @@ func TestFromFile(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
defer os.Remove(outPathTypes.Name())
|
||||
|
||||
outPathInterpreters, err := ioutil.TempFile("/tmp", "generator-test-")
|
||||
assert.NoError(t, err)
|
||||
defer os.Remove(outPathInterpreters.Name())
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
fileToParse string
|
||||
@ -139,6 +152,16 @@ func TestFromFile(t *testing.T) {
|
||||
generate: Types,
|
||||
wantOut: goldTypes,
|
||||
},
|
||||
{
|
||||
name: "TestFromFile_Interpreters",
|
||||
fileToParse: interpretersTestFile,
|
||||
outPath: outPathInterpreters.Name(),
|
||||
tmplPath: interpretersTestTmplPath,
|
||||
tmplName: interpretersTestTmplName,
|
||||
commit: commitTest,
|
||||
generate: Interpreters,
|
||||
wantOut: goldInterpreters,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
54
internal/code-generator/generator/interpreters.go
Normal file
54
internal/code-generator/generator/interpreters.go
Normal file
@ -0,0 +1,54 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Interpreters reads from buf and builds interpreters_map.go 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orderedKeys := getAlphabeticalOrderedKeys(languages)
|
||||
languagesByInterpreter := buildInterpreterLanguagesMap(languages, orderedKeys)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
if err := executeInterpretersTemplate(buf, languagesByInterpreter, interpretersTmplPath, interpretersTmplName, commit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func buildInterpreterLanguagesMap(languages map[string]*languageInfo, orderedKeys []string) map[string][]string {
|
||||
interpreterLangsMap := make(map[string][]string)
|
||||
for _, lang := range orderedKeys {
|
||||
langInfo := languages[lang]
|
||||
for _, interpreter := range langInfo.Interpreters {
|
||||
interpreterLangsMap[interpreter] = append(interpreterLangsMap[interpreter], lang)
|
||||
}
|
||||
}
|
||||
|
||||
return interpreterLangsMap
|
||||
}
|
||||
|
||||
func executeInterpretersTemplate(out io.Writer, languagesByInterpreter map[string][]string, interpretersTmplPath, interpretersTmpl, 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(interpretersTmpl).Funcs(fmap).ParseFiles(interpretersTmplPath))
|
||||
if err := t.Execute(out, languagesByInterpreter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package slinguist
|
||||
|
||||
// CODE GENERATED AUTOMATICALLY WITH github.com/src-d/simple-linguist/cli/slinguist-generate
|
||||
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||
// Extracted from github/linguist commit: fe8b44ab8a225b1ffa75b983b916ea22fee5b6f7
|
||||
|
||||
var languagesByInterpreter = map[string][]string{
|
||||
"bash": {"Shell"},
|
||||
"nush": {"Nu"},
|
||||
"python": {"Python"},
|
||||
"python2": {"Python"},
|
||||
"python3": {"Python"},
|
||||
"rc": {"Shell"},
|
||||
"sh": {"Shell"},
|
||||
"zsh": {"Shell"},
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package slinguist
|
||||
|
||||
// CODE GENERATED AUTOMATICALLY WITH github.com/src-d/simple-linguist/cli/slinguist-generate
|
||||
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||
// Extracted from github/linguist commit: {{ getCommit }}
|
||||
|
||||
var languagesByInterpreter = map[string][]string{
|
||||
{{range $interpreter, $languages := . -}}
|
||||
"{{ $interpreter }}": { {{- $languages | formatStringSlice -}} },
|
||||
{{end -}}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
---
|
||||
Nu:
|
||||
interpreters:
|
||||
- nush
|
||||
Shell:
|
||||
interpreters:
|
||||
- bash
|
||||
- rc
|
||||
- sh
|
||||
- zsh
|
||||
Python:
|
||||
interpreters:
|
||||
- python
|
||||
- python2
|
||||
- python3
|
@ -66,6 +66,7 @@ func main() {
|
||||
&generatorArgs{vendorYAML, vendorFile, vendorTmplPath, vendorTmpl, commit, generator.Vendor},
|
||||
&generatorArgs{documentationYAML, documentationFile, documentationTmplPath, documentationTmpl, commit, generator.Documentation},
|
||||
&generatorArgs{languagesYAML, typeFile, typeTmplPath, typeTmpl, commit, generator.Types},
|
||||
&generatorArgs{languagesYAML, interpretersFile, interpretersTmplPath, interpretersTmpl, commit, generator.Interpreters},
|
||||
}
|
||||
|
||||
for _, args := range argsList {
|
||||
|
98
interpreters_map.go
Normal file
98
interpreters_map.go
Normal file
@ -0,0 +1,98 @@
|
||||
package slinguist
|
||||
|
||||
// CODE GENERATED AUTOMATICALLY WITH github.com/src-d/simple-linguist/cli/slinguist-generate
|
||||
// THIS FILE SHOULD NOT BE EDITED BY HAND
|
||||
// Extracted from github/linguist commit: dae33dc2b20cddc85d1300435c3be7118a7115a9
|
||||
|
||||
var languagesByInterpreter = map[string][]string{
|
||||
"Rscript": {"R"},
|
||||
"apl": {"APL"},
|
||||
"aplx": {"APL"},
|
||||
"awk": {"Awk"},
|
||||
"bash": {"Shell"},
|
||||
"bigloo": {"Scheme"},
|
||||
"boolector": {"SMT"},
|
||||
"ccl": {"Common Lisp"},
|
||||
"chicken": {"Scheme"},
|
||||
"clisp": {"Common Lisp"},
|
||||
"coffee": {"CoffeeScript"},
|
||||
"crystal": {"Crystal"},
|
||||
"csi": {"Scheme"},
|
||||
"cvc4": {"SMT"},
|
||||
"dart": {"Dart"},
|
||||
"dtrace": {"DTrace"},
|
||||
"dyalog": {"APL"},
|
||||
"ecl": {"Common Lisp"},
|
||||
"elixir": {"Elixir"},
|
||||
"escript": {"Erlang"},
|
||||
"fish": {"fish"},
|
||||
"gawk": {"Awk"},
|
||||
"gn": {"GN"},
|
||||
"gnuplot": {"Gnuplot"},
|
||||
"gosh": {"Scheme"},
|
||||
"groovy": {"Groovy"},
|
||||
"guile": {"Scheme"},
|
||||
"instantfpc": {"Pascal"},
|
||||
"io": {"Io"},
|
||||
"ioke": {"Ioke"},
|
||||
"jconsole": {"J"},
|
||||
"jruby": {"Ruby"},
|
||||
"julia": {"Julia"},
|
||||
"lisp": {"Common Lisp"},
|
||||
"lsl": {"LSL"},
|
||||
"lua": {"Lua", "Terra"},
|
||||
"macruby": {"Ruby"},
|
||||
"make": {"Makefile"},
|
||||
"mathsat5": {"SMT"},
|
||||
"mawk": {"Awk"},
|
||||
"mmi": {"Mercury"},
|
||||
"moon": {"MoonScript"},
|
||||
"nawk": {"Awk"},
|
||||
"newlisp": {"NewLisp"},
|
||||
"node": {"JavaScript"},
|
||||
"nush": {"Nu"},
|
||||
"ocaml": {"OCaml", "Reason"},
|
||||
"ocamlrun": {"OCaml"},
|
||||
"ocamlscript": {"OCaml"},
|
||||
"openrc-run": {"OpenRC runscript"},
|
||||
"opensmt": {"SMT"},
|
||||
"osascript": {"AppleScript"},
|
||||
"parrot": {"Parrot Assembly", "Parrot Internal Representation"},
|
||||
"perl": {"Perl"},
|
||||
"perl6": {"Perl6"},
|
||||
"php": {"PHP"},
|
||||
"picolisp": {"PicoLisp"},
|
||||
"pike": {"Pike"},
|
||||
"pil": {"PicoLisp"},
|
||||
"python": {"Python"},
|
||||
"python2": {"Python"},
|
||||
"python3": {"Python"},
|
||||
"qmake": {"QMake"},
|
||||
"r6rs": {"Scheme"},
|
||||
"racket": {"Racket"},
|
||||
"rake": {"Ruby"},
|
||||
"rbx": {"Ruby"},
|
||||
"rc": {"Shell"},
|
||||
"regina": {"REXX"},
|
||||
"rexx": {"REXX"},
|
||||
"ruby": {"Ruby"},
|
||||
"rune": {"E"},
|
||||
"runhaskell": {"Haskell"},
|
||||
"sbcl": {"Common Lisp"},
|
||||
"scala": {"Scala"},
|
||||
"sclang": {"SuperCollider"},
|
||||
"scsynth": {"SuperCollider"},
|
||||
"sh": {"Shell"},
|
||||
"smt-rat": {"SMT"},
|
||||
"smtinterpol": {"SMT"},
|
||||
"stp": {"SMT"},
|
||||
"swipl": {"Prolog"},
|
||||
"tcc": {"C"},
|
||||
"tclsh": {"Tcl"},
|
||||
"verit": {"SMT"},
|
||||
"wish": {"Tcl"},
|
||||
"yap": {"Prolog"},
|
||||
"yices2": {"SMT"},
|
||||
"z3": {"SMT"},
|
||||
"zsh": {"Shell"},
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user