예제 #1
0
func (fs *LambdaStatement) GenerateGo(fm expressionParsing.FunctionMap) (string, expressionParsing.TypeDefinition, parser.SyntaxError) {
	innerScope := fm.NextScopeLayer()
	setupFuncMap(innerScope, fs.TypeDef.(expressionParsing.FuncTypeDefinition))
	inner, err := generateInnerGo(innerScope, fs.InnerStatements)
	if err != nil {
		return "", nil, err
	}

	var funcName string = ""
	if fs.packageLevel {
		funcName = fs.name + " "
	}

	return fmt.Sprintf("func %s%s{\n\t%s\n}", funcName, generateTypeDef(true, fs.TypeDef), generateInnerFunc(getReturnType(fs.TypeDef), 1, inner)), fs.TypeDef, nil
}
예제 #2
0
func (ds *LetStatement) GenerateGo(fm expressionParsing.FunctionMap) (string, expressionParsing.TypeDefinition, parser.SyntaxError) {
	innerCode, returnType, synErr := ds.innerStatement.GenerateGo(fm.NextScopeLayer())

	if synErr != nil {
		return "", nil, synErr
	}

	name, err := fm.AddFunction(ds.varName, returnType)
	if err != nil {
		return "", nil, parser.NewSyntaxError(err.Error(), 0, 0)
	}

	var genCode string
	if _, ok := returnType.(expressionParsing.FuncTypeDefinition); ok {
		if ls, ok := ds.innerStatement.(*LambdaStatement); ok && ls.packageLevel {
			genCode = innerCode
		} else {
			genCode = fmt.Sprintf("var %s %s\n%s = %s", name, returnType.GenerateGo(), name, innerCode)
		}
	} else {
		genCode = fmt.Sprintf("var %s func() %s\n%s = func(){\n\treturn %s\n}", name, returnType.GenerateGo(), name, innerCode)
	}
	return genCode, returnType, nil
}