github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/builder/dockerfile/parser/dumper/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/docker/docker/builder/dockerfile/parser" 8 ) 9 10 func main() { 11 var f *os.File 12 var err error 13 14 if len(os.Args) < 2 { 15 fmt.Println("please supply filename(s)") 16 os.Exit(1) 17 } 18 19 for _, fn := range os.Args[1:] { 20 f, err = os.Open(fn) 21 if err != nil { 22 panic(err) 23 } 24 defer f.Close() 25 26 d := parser.Directive{LookingForDirectives: true} 27 parser.SetEscapeToken(parser.DefaultEscapeToken, &d) 28 29 ast, err := parser.Parse(f, &d) 30 if err != nil { 31 panic(err) 32 } else { 33 fmt.Println(ast.Dump()) 34 } 35 } 36 }