aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ast/parser.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-08-18 18:38:07 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-08-18 18:47:39 +0200
commit4802b0fb7440d76d78efc586b87ff6eea46b6b00 (patch)
tree7a1e39eb906a18e0be375f39ec45b0679cee39c4 /pkg/ast/parser.go
parent19b893936bebc6189c7627d56d1dc454fbd42714 (diff)
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.
Diffstat (limited to 'pkg/ast/parser.go')
-rw-r--r--pkg/ast/parser.go31
1 files changed, 31 insertions, 0 deletions
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