From 4802b0fb7440d76d78efc586b87ff6eea46b6b00 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 18 Aug 2017 18:38:07 +0200 Subject: sys/syz-sysgen: switch to new parser For now we just generate the old structs from the new AST. But this allows to delete the old parser entirely. --- pkg/ast/parser.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'pkg/ast/parser.go') diff --git a/pkg/ast/parser.go b/pkg/ast/parser.go index 10f389424..fc05378b2 100644 --- a/pkg/ast/parser.go +++ b/pkg/ast/parser.go @@ -6,6 +6,8 @@ package ast import ( "errors" "fmt" + "io/ioutil" + "path/filepath" "strconv" "strings" ) @@ -41,6 +43,35 @@ func Parse(data []byte, filename string, errorHandler func(pos Pos, msg string)) return } +func ParseGlob(glob string, errorHandler func(pos Pos, msg string)) (top []interface{}, ok bool) { + if errorHandler == nil { + errorHandler = loggingHandler + } + files, err := filepath.Glob(glob) + if err != nil { + errorHandler(Pos{}, fmt.Sprintf("failed to find input files: %v", err)) + return nil, false + } + if len(files) == 0 { + errorHandler(Pos{}, fmt.Sprintf("no files matched by glob %q", glob)) + return nil, false + } + ok = true + for _, f := range files { + data, err := ioutil.ReadFile(f) + if err != nil { + errorHandler(Pos{}, fmt.Sprintf("failed to read input file: %v", err)) + return nil, false + } + top1, ok1 := Parse(data, filepath.Base(f), errorHandler) + if !ok1 { + ok = false + } + top = append(top, top1...) + } + return +} + type parser struct { s *scanner -- cgit mrf-deployment