mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 00:38:14 +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>
|
||||
// - MHS: <nil|KExpr>
|
||||
// - 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)"
|
||||
//
|
||||
// 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
|
||||
// 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 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:]
|
||||
return &a.Node{
|
||||
Kind: a.KUse,
|
||||
ID1: id1,
|
||||
Kind: a.KUse,
|
||||
ID1: id1,
|
||||
}, nil
|
||||
|
||||
}
|
||||
@@ -504,11 +504,29 @@ func (p *parser) parseExpr() (*a.Node, error) {
|
||||
if err != nil {
|
||||
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{
|
||||
Kind: a.KExpr,
|
||||
ID0: x,
|
||||
LHS: lhs,
|
||||
RHS: rhs,
|
||||
Kind: a.KExpr,
|
||||
ID0: x,
|
||||
List0: list0,
|
||||
}, nil
|
||||
}
|
||||
return lhs, nil
|
||||
|
||||
Reference in new issue
Block a user