mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Parse "x.y".
This commit is contained in:
1 parent
9d3c8b30f1
commit
c86ff2fcc3
2 files changed
+31
-15
No files matched your search
+2
-2
@@ -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
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user