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) }
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 } }