aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ast/parser.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-05-10 18:02:54 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-05-14 19:28:01 +0200
commiteea28fee309680462752ef7709f1a94178dce44d (patch)
tree29caff3a1e370c092522a94a9a231d83a767d20b /pkg/ast/parser.go
parent1886b2a4811a4d9adbfc509505a095848cc655eb (diff)
pkg/compiler: support complex len targets
This change adds compiler support for complex path expressions in len targets. E.g. it allows to refer to a sibling field as len[parent_struct:field:another_field]. See the docs change for details. This is just a compiler change. The feature is not yet supported by the prog package.
Diffstat (limited to 'pkg/ast/parser.go')
-rw-r--r--pkg/ast/parser.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/pkg/ast/parser.go b/pkg/ast/parser.go
index b68a1a8a2..b8d22fd88 100644
--- a/pkg/ast/parser.go
+++ b/pkg/ast/parser.go
@@ -424,20 +424,22 @@ func (p *parser) parseType() *Type {
p.expect(tokInt, tokIdent, tokString)
}
p.next()
- if allowColon && p.tryConsume(tokColon) {
- col := &Type{
- Pos: p.pos,
- }
- switch p.tok {
- case tokInt:
- col.Value, col.ValueFmt = p.parseIntValue()
- case tokIdent:
- col.Ident = p.lit
- default:
- p.expect(tokInt, tokIdent)
+ if allowColon {
+ for p.tryConsume(tokColon) {
+ col := &Type{
+ Pos: p.pos,
+ }
+ switch p.tok {
+ case tokInt:
+ col.Value, col.ValueFmt = p.parseIntValue()
+ case tokIdent:
+ col.Ident = p.lit
+ default:
+ p.expect(tokInt, tokIdent)
+ }
+ arg.Colon = append(arg.Colon, col)
+ p.next()
}
- arg.Colon = append(arg.Colon, col)
- p.next()
}
arg.Args = p.parseTypeList()
return arg