diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-11-11 14:44:01 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-11 14:44:01 -0800 |
| commit | 89abacc228e60afe1df0b01d36dc7fe886ca7bcc (patch) | |
| tree | f0ca6508ab6f3b6ea78e6260c28dd09f37c9d48c /sysparser | |
| parent | 85f78e771dced807e5e09b8012ec38333e442bb7 (diff) | |
| parent | 3a65453870b12f5c42739c27d99df8fc58358f88 (diff) | |
Merge pull request #86 from google/sys_ptrs
A bunch of changes to sys/prog package
Diffstat (limited to 'sysparser')
| -rw-r--r-- | sysparser/lexer.go | 26 | ||||
| -rw-r--r-- | sysparser/parser.go | 3 |
2 files changed, 23 insertions, 6 deletions
diff --git a/sysparser/lexer.go b/sysparser/lexer.go index 06210a584..a3b8f58ed 100644 --- a/sysparser/lexer.go +++ b/sysparser/lexer.go @@ -18,6 +18,7 @@ type Description struct { Structs map[string]Struct Unnamed map[string][]string Flags map[string][]string + StrFlags map[string][]string Resources map[string]Resource } @@ -51,6 +52,7 @@ func Parse(in io.Reader) *Description { structs := make(map[string]Struct) unnamed := make(map[string][]string) flags := make(map[string][]string) + strflags := make(map[string][]string) resources := make(map[string]Resource) var str *Struct for p.Scan() { @@ -93,6 +95,9 @@ func Parse(in io.Reader) *Description { } fields := make(map[string]bool) for _, f := range str.Flds { + if f[0] == "parent" { + failf("struct/union %v contains reserved field 'parent'", str.Name) + } if fields[f[0]] { failf("duplicate field %v in struct/union %v", f[0], str.Name) } @@ -189,12 +194,24 @@ func Parse(in io.Reader) *Description { case '=': // flag p.Parse('=') - vals := []string{p.Ident()} - for !p.EOF() { + str := p.Char() == '"' + var vals []string + for { + v := p.Ident() + if str { + v = v[1 : len(v)-1] + } + vals = append(vals, v) + if p.EOF() { + break + } p.Parse(',') - vals = append(vals, p.Ident()) } - flags[name] = vals + if str { + strflags[name] = vals + } else { + flags[name] = vals + } case '{', '[': p.Parse(ch) if _, ok := structs[name]; ok { @@ -221,6 +238,7 @@ func Parse(in io.Reader) *Description { Structs: structs, Unnamed: unnamed, Flags: flags, + StrFlags: strflags, Resources: resources, } } diff --git a/sysparser/parser.go b/sysparser/parser.go index 590847b0e..d5021eee6 100644 --- a/sysparser/parser.go +++ b/sysparser/parser.go @@ -70,11 +70,10 @@ func (p *parser) Ident() string { start, end := p.i, 0 if p.Char() == '"' { p.Parse('"') - start++ for p.Char() != '"' { p.i++ } - end = p.i + end = p.i + 1 p.Parse('"') } else { for p.i < len(p.s) && |
