aboutsummaryrefslogtreecommitdiffstats
path: root/sysparser
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2016-10-31 15:15:13 -0600
committerDmitry Vyukov <dvyukov@google.com>2016-11-11 14:33:37 -0800
commit588a542b2a23ba477031bf20b4c46b0f40a04b7d (patch)
tree9e517866f45cdb903505e72c0fcbf821c0b00dcd /sysparser
parent5ed6283b64f91c8aa036122b18974aabed4c5249 (diff)
sys: add string flags
Allow to define string flags in txt descriptions. E.g.: filesystem = "ext2", "ext3", "ext4" and then use it in string type: ptr[in, string[filesystem]]
Diffstat (limited to 'sysparser')
-rw-r--r--sysparser/lexer.go23
-rw-r--r--sysparser/parser.go3
2 files changed, 20 insertions, 6 deletions
diff --git a/sysparser/lexer.go b/sysparser/lexer.go
index 18143c901..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() {
@@ -192,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 {
@@ -224,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) &&