forked from robertkrimen/otto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (42 loc) · 910 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/Forever-Young/otto"
"github.com/Forever-Young/otto/parser"
// "github.com/Forever-Young/otto/underscore"
)
// var flag_underscore *bool = flag.Bool("underscore", true, "Load underscore into the runtime environment")
func readSource(filename string) ([]byte, error) {
if filename == "" || filename == "-" {
return ioutil.ReadAll(os.Stdin)
}
return ioutil.ReadFile(filename)
}
func main() {
flag.Parse()
// if !*flag_underscore {
// underscore.Disable()
// }
err := func() error {
src, err := readSource(flag.Arg(0))
if err != nil {
return err
}
// vm := otto.New()
// _, err = vm.Run(src)
_, err = parser.ParseFile(nil, flag.Arg(0), src, 0)
return err
}()
if err != nil {
switch err := err.(type) {
case *otto.Error:
fmt.Print(err.String())
default:
fmt.Println(err)
}
os.Exit(64)
}
}