mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Parse "f(x)(y)".
This commit is contained in:
1 parent
ede8786f4b
commit
d92049b8fa
2 files changed
+56
-1
No files matched your search
@@ -0,0 +1,55 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
package ast_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/puffs/lang/parse"
|
||||
"github.com/google/puffs/lang/token"
|
||||
)
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
const filename = "test.puffs"
|
||||
testCases := []string{
|
||||
"1",
|
||||
"x",
|
||||
|
||||
"x + 42",
|
||||
"x and (y < z)",
|
||||
"x & (y as u8)",
|
||||
"x * ((a / b) - (i / j))",
|
||||
|
||||
"x as bool",
|
||||
"x as u32",
|
||||
"x as T",
|
||||
"x as T",
|
||||
"x as T[i:]",
|
||||
"x as T[:j]",
|
||||
"x as T[i:j]",
|
||||
"x as pkg.T",
|
||||
"x as ptr T",
|
||||
"x as [4] T",
|
||||
"x as [8 + (2 * N)] ptr [4] ptr pkg.T[i:j]",
|
||||
}
|
||||
|
||||
idMap := &token.IDMap{}
|
||||
for _, tc := range testCases {
|
||||
tokens, _, err := token.Tokenize(idMap, filename, []byte(tc))
|
||||
if err != nil {
|
||||
t.Errorf("Tokenize(%q): %v", tc, err)
|
||||
continue
|
||||
}
|
||||
expr, err := parse.ParseExpr(idMap, filename, tokens)
|
||||
if err != nil {
|
||||
t.Errorf("ParseExpr(%q): %v", tc, err)
|
||||
continue
|
||||
}
|
||||
got := expr.String(idMap)
|
||||
if got != tc {
|
||||
t.Errorf("got %q, want %q", got, tc)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -585,7 +585,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.NewExpr(flags, t.IDOpenParen, 0, lhs.Node(), nil, nil, args), nil
|
||||
lhs = a.NewExpr(flags, t.IDOpenParen, 0, lhs.Node(), nil, nil, args)
|
||||
|
||||
case t.IDOpenBracket:
|
||||
id0, mhs, rhs, err := p.parseRangeOrIndex(true)
|
||||
|
||||
Reference in new issue
Block a user