mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Parse "x = i + j + k".
Also run gofmt.
This commit is contained in:
1 parent
60a4fdb9fd
commit
1770f9064e
2 files changed
+28
-7
No files matched your search
+4
-1
@@ -21,7 +21,7 @@ const (
|
|||||||
// - LHS: <nil|KExpr>
|
// - LHS: <nil|KExpr>
|
||||||
// - MHS: <nil|KExpr>
|
// - MHS: <nil|KExpr>
|
||||||
// - RHS: <nil|KExpr|KType>
|
// - RHS: <nil|KExpr|KType>
|
||||||
// - List0: <KExpr> function call arguments
|
// - List0: <KExpr> function call arguments or associative op arguments
|
||||||
// - FlagsSuspendible is "f(x)" vs "f?(x)"
|
// - FlagsSuspendible is "f(x)" vs "f?(x)"
|
||||||
//
|
//
|
||||||
// A zero ID0 means an identifier or literal in ID1, like "foo" or "42".
|
// A zero ID0 means an identifier or literal in ID1, like "foo" or "42".
|
||||||
@@ -32,6 +32,9 @@ const (
|
|||||||
// operands. The LHS may be null for the "-" and "+" operators, which are
|
// operands. The LHS may be null for the "-" and "+" operators, which are
|
||||||
// also unary operators.
|
// also unary operators.
|
||||||
//
|
//
|
||||||
|
// For associative binary operators, both LHS and RHS may be null, and
|
||||||
|
// multiple operands are in List0.
|
||||||
|
//
|
||||||
// For function calls, like "LHS(List0)", ID0 is IDOpenParen.
|
// For function calls, like "LHS(List0)", ID0 is IDOpenParen.
|
||||||
//
|
//
|
||||||
// For indexes, like "LHS[RHS]", ID0 is IDOpenBracket.
|
// For indexes, like "LHS[RHS]", ID0 is IDOpenBracket.
|
||||||
|
|||||||
+24
-6
@@ -141,8 +141,8 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
|||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
return &a.Node{
|
return &a.Node{
|
||||||
Kind: a.KUse,
|
Kind: a.KUse,
|
||||||
ID1: id1,
|
ID1: id1,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -504,11 +504,29 @@ func (p *parser) parseExpr() (*a.Node, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !x.IsAssociative() || x != p.peekID() {
|
||||||
|
return &a.Node{
|
||||||
|
Kind: a.KExpr,
|
||||||
|
ID0: x,
|
||||||
|
LHS: lhs,
|
||||||
|
RHS: rhs,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
list0 := []*a.Node{lhs, rhs}
|
||||||
|
for p.peekID() == x {
|
||||||
|
p.src = p.src[1:]
|
||||||
|
arg, err := p.parseOperand()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
list0 = append(list0, arg)
|
||||||
|
}
|
||||||
return &a.Node{
|
return &a.Node{
|
||||||
Kind: a.KExpr,
|
Kind: a.KExpr,
|
||||||
ID0: x,
|
ID0: x,
|
||||||
LHS: lhs,
|
List0: list0,
|
||||||
RHS: rhs,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
return lhs, nil
|
return lhs, nil
|
||||||
|
|||||||
Reference in new issue
Block a user