Exemplo n.º 1
0
func (codegen *_CodeGen) BeginScript(compiler *gslang.Compiler, script *ast.Script) bool {

	codegen.compiler = compiler

	scriptPath := filepath.ToSlash(filepath.Clean(script.Name()))

	for _, skip := range codegen.skips {

		if skip.MatchString(scriptPath) {
			return false
		}
	}

	if strings.HasPrefix(script.Package, "gslang") {
		return false
	}

	codegen.header.Reset()
	codegen.source.Reset()
	codegen.predecl.Reset()

	codegen.script = script

	codegen.imports = make(map[string]string)

	for k, v := range imports {
		codegen.imports[k] = v
	}

	return true
}
Exemplo n.º 2
0
func (codegen *_CodeGen) BeginScript(compiler *gslang.Compiler, script *ast.Script) bool {

	scriptPath := filepath.ToSlash(filepath.Clean(script.Name()))

	for _, skip := range codegen.skips {

		if skip.MatchString(scriptPath) {

			return false
		}
	}

	if strings.HasPrefix(script.Package, "gslang.") {
		return false
	}

	codegen.header.Reset()
	codegen.content.Reset()

	codegen.script = script

	codegen.packageName = script.Package
	codegen.scriptPath = strings.Replace(codegen.packageName, ".", "/", -1)

	langs := gslang.FindAnnotations(script.Module, "gslang.Package")

	for _, lang := range langs {

		langName, ok := lang.Args.NamedArg("Lang")

		if ok && compiler.Eval().EvalString(langName) == "golang" {

			packageName, ok := lang.Args.NamedArg("Name")

			if ok && compiler.Eval().EvalString(packageName) == script.Package {

				redirect, ok := lang.Args.NamedArg("Redirect")

				if ok {
					codegen.packageName = compiler.Eval().EvalString(redirect)
					codegen.scriptPath = codegen.packageName
				}
			}

		}
	}

	path := strings.Replace(codegen.packageName, ".", "/", -1)
	codegen.header.WriteString(fmt.Sprintf("package %s\n\n", filepath.Base(path)))

	codegen.imports = make(map[string]string)

	for k, v := range imports {
		codegen.imports[k] = v
	}

	return true
}