func runFile(name string) *parser.Block { os.Chdir(filepath.Dir(name)) file, err := util.NewFile(filepath.Base(name) + "." + util.FileExtension) if err != nil { reportError(err.Error(), false) } lex := lexer.NewLexerFromFile(file) err = lex.Lex() if err != nil { reportError(err.Error(), false) } nodes, err := parser.Nodes(lex.Tokens) if err != nil { reportError(err.Error(), false) } block := parser.NewBlock(nodes, nil, file) setDefaults(block.Scope) err = block.Exec() if err != nil { reportError(err.Error(), false) } return block }
func useFile(context *parser.FunctionCallContext) error { values, err := parser.ValidateArguments(context, "use-file", parser.VALUE_STRING) if err != nil { return err } file, err := util.NewFile(values[0].S) if err != nil { return err } lex := lexer.NewLexerFromFile(file) err = lex.Lex() if err != nil { return err } nodes, err := parser.Nodes(lex.Tokens) if err != nil { return err } fileBlock := parser.NewBlock(nodes, context.Block, file) err = fileBlock.Exec() if err != nil { return err } for key, value := range fileBlock.Scope.Symbols { if value.Exported { context.Block.Scope.SetSymbol(key, value) } } fileBlock.Stack.PopAllToOtherStack(context.Block.Stack) return nil }