예제 #1
0
func fetchInnerStatements(lines []string, factory *StatementFactory, lineNum int) ([]Statement, parser.SyntaxError) {
	scanner := parser.NewScanPeekerStr(parser.FromLines(lines), lineNum)
	statements := make([]Statement, 0)
	next := func() (Statement, parser.SyntaxError) {
		return factory.Read(scanner)
	}

	return subFetchInnerStatements(next, statements)
}
예제 #2
0
func generateInnerFunc(typeDef expressionParsing.TypeDefinition, tabCount int, innerStatements []string) string {
	tabs := ""
	for i := 0; i <= tabCount; i++ {
		tabs += "\t"
	}
	tabs2 := string(tabs[:len(tabs)-1])

	if _, ok := typeDef.(expressionParsing.FuncTypeDefinition); !ok {
		lenInner := len(innerStatements) - 1
		innerCode := parser.FromLines(innerStatements[:lenInner])
		return fmt.Sprintf("%s\n%sreturn %s", innerCode, tabs2, innerStatements[lenInner])
	}

	return fmt.Sprintf("return %s {\n%s%s\n%s}", generateTypeDef(false, typeDef), tabs, generateInnerFunc(getReturnType(typeDef), tabCount+1, innerStatements), tabs2)
}
예제 #3
0
func (ds LetStatement) Parse(block string, lineNum int, nextBlockScanner *parser.ScanPeeker, factory *StatementFactory) (Statement, parser.SyntaxError) {
	lines := parser.Lines(block)

	ok, varName, restOfLine := splitEquals(lines[0])

	if ok {
		if ds.packageLevel {
			factory = adjustFactory(varName, factory)
		}
		combinedLine := parser.FromLines(append([]string{restOfLine}, lines[1:]...))
		peeker := parser.NewScanPeekerStr(combinedLine, lineNum)
		st, err := factory.Read(peeker)
		if err != nil {
			return nil, err
		}
		return newLetStatement(varName, combinedLine, lineNum, st), nil
	}

	if ds.packageLevel {
		return nil, parser.NewSyntaxError(fmt.Sprintf("Unknown statement: %s", lines[0]), lineNum, 0)
	} else {
		return nil, nil
	}
}