2019-03-18 18:15:26 +03:00
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"regexp"
|
2019-03-27 11:27:59 +03:00
|
|
|
"strconv"
|
2019-03-18 18:15:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var tengoModFileRE = regexp.MustCompile(`^srcmod_(\w+).tengo$`)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
modules := make(map[string]string)
|
|
|
|
|
|
|
|
// enumerate all Tengo module files
|
|
|
|
files, err := ioutil.ReadDir(".")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, file := range files {
|
|
|
|
m := tengoModFileRE.FindStringSubmatch(file.Name())
|
|
|
|
if m != nil {
|
|
|
|
modName := m[1]
|
|
|
|
|
|
|
|
src, err := ioutil.ReadFile(file.Name())
|
|
|
|
if err != nil {
|
2019-12-20 22:40:38 +03:00
|
|
|
log.Fatalf("file '%s' read error: %s",
|
|
|
|
file.Name(), err.Error())
|
2019-03-18 18:15:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
modules[modName] = string(src)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var out bytes.Buffer
|
|
|
|
out.WriteString(`// Code generated using gensrcmods.go; DO NOT EDIT.
|
|
|
|
|
|
|
|
package stdlib
|
|
|
|
|
|
|
|
// SourceModules are source type standard library modules.
|
2019-03-20 11:28:40 +03:00
|
|
|
var SourceModules = map[string]string{` + "\n")
|
2019-03-18 18:15:26 +03:00
|
|
|
for modName, modSrc := range modules {
|
2019-12-20 22:40:38 +03:00
|
|
|
out.WriteString("\t\"" + modName + "\": " +
|
|
|
|
strconv.Quote(modSrc) + ",\n")
|
2019-03-18 18:15:26 +03:00
|
|
|
}
|
|
|
|
out.WriteString("}\n")
|
|
|
|
|
|
|
|
const target = "source_modules.go"
|
|
|
|
if err := ioutil.WriteFile(target, out.Bytes(), 0644); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|