Parse "x.y".

This commit is contained in:
Nigel Tao committed 2017-05-04 14:22:29 +10:00
1 parent 9d3c8b30f1
commit c86ff2fcc3
2 files changed
+31 -15

No files matched your search

+2 -2
View File
@@ -16,7 +16,7 @@ const (
KInvalid = Kind(iota)
// KExpr is an expression, such as "i", "+j" or "k + l[m].n".
// - ID0: <0|operator|IDOpenBracket|IDDot>
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDDot>
// - ID1: <0|identifier name|literal>
// - LHS: <nil|KExpr>
// - RHS: <nil|KExpr|KType>
@@ -33,7 +33,7 @@ const (
//
// For indexes, like "lhs[rhs]", ID0 is IDOpenBracket.
//
// For selectors, like "lhs.rhs", ID0 is IDDot.
// For selectors, like "lhs.id1", ID0 is IDDot.
KExpr
// KAssign is "Left = Right".
+29 -13
View File
@@ -310,7 +310,7 @@ func (p *parser) parseOperand() (*a.Node, error) {
case x.IsUnaryOp():
p.src = p.src[1:]
rhs, err := p.parseExpr()
rhs, err := p.parseOperand()
if err != nil {
return nil, err
}
@@ -325,18 +325,34 @@ func (p *parser) parseOperand() (*a.Node, error) {
if err != nil {
return nil, err
}
switch p.peekID() {
case t.IDOpenParen:
// TODO: parse "f(i)".
case t.IDOpenBracket:
// TODO: parse "a[i]".
case t.IDDot:
// TODO: parse "x.y".
}
return &a.Node{
lhs := &a.Node{
Kind: a.KExpr,
ID1: id,
}, nil
}
for {
switch p.peekID() {
default:
return lhs, nil
case t.IDOpenParen:
// TODO: parse "f(i)".
case t.IDOpenBracket:
// TODO: parse "a[i]".
case t.IDDot:
p.src = p.src[1:]
id, err := p.parseIdent()
if err != nil {
return nil, err
}
lhs = &a.Node{
Kind: a.KExpr,
ID0: t.IDDot,
ID1: id,
LHS: lhs,
}
}
}
}