mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 16:32:11 +01:00
Introduce "array[N] T" and "slice T" type syntax
This commit is contained in:
1 parent
2b91e7861c
commit
d33db6dae0
15 files changed
+83
-68
No files matched your search
+3
-3
@@ -622,7 +622,7 @@ func NewJump(keyword t.ID, label t.ID) *Jump {
|
||||
const MaxTypeExprDepth = 63
|
||||
|
||||
// TypeExpr is a type expression, such as "u32", "u32[..8]", "pkg.foo", "ptr
|
||||
// T", "[8] T" or "[] T":
|
||||
// T", "array[8] T" or "slice T":
|
||||
// - ID0: <0|IDPtr|IDArray|IDSlice|IDOpenParen>
|
||||
// - ID1: <0|pkg>
|
||||
// - ID2: <0|type name>
|
||||
@@ -632,9 +632,9 @@ const MaxTypeExprDepth = 63
|
||||
//
|
||||
// An IDPtr ID0 means "ptr RHS". RHS is the inner type.
|
||||
//
|
||||
// An IDArray ID0 means "[LHS] RHS". RHS is the inner type.
|
||||
// An IDArray ID0 means "array[LHS] RHS". RHS is the inner type.
|
||||
//
|
||||
// An IDSlice ID0 means "[] RHS". RHS is the inner type.
|
||||
// An IDSlice ID0 means "slice RHS". RHS is the inner type.
|
||||
//
|
||||
// An IDOpenParen ID0 means "LHS.ID2", a function or method type. LHS is the
|
||||
// receiver type, which may be nil. If non-nil, it will be a pointee type: "T"
|
||||
|
||||
+2
-2
@@ -212,12 +212,12 @@ func (n *TypeExpr) appendStr(buf []byte, tm *t.Map, depth uint32) []byte {
|
||||
buf = append(buf, "ptr "...)
|
||||
return n.Inner().appendStr(buf, tm, depth)
|
||||
case t.KeyArray:
|
||||
buf = append(buf, '[')
|
||||
buf = append(buf, "array["...)
|
||||
buf = n.ArrayLength().appendStr(buf, tm, false, 0)
|
||||
buf = append(buf, "] "...)
|
||||
return n.Inner().appendStr(buf, tm, depth)
|
||||
case t.KeySlice:
|
||||
buf = append(buf, "[] "...)
|
||||
buf = append(buf, "slice "...)
|
||||
return n.Inner().appendStr(buf, tm, depth)
|
||||
case t.KeyOpenParen:
|
||||
buf = append(buf, "func "...)
|
||||
|
||||
@@ -67,8 +67,8 @@ func TestString(tt *testing.T) {
|
||||
"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]",
|
||||
"x as array[4] T",
|
||||
"x as array[8 + (2 * N)] ptr array[4] ptr pkg.T[i..j]",
|
||||
}
|
||||
|
||||
tm := &t.Map{}
|
||||
|
||||
Reference in new issue
Block a user