mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Rename [i:j] to [i .. j], the same as Rust
This commit is contained in:
1 parent
7872a8893b
commit
a9ea63ff06
16 files changed
+55
-50
No files matched your search
+2
-2
@@ -293,7 +293,7 @@ func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
|
||||
const MaxExprDepth = 255
|
||||
|
||||
// Expr is an expression, such as "i", "+j" or "k + l[m(n, o)].p":
|
||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDColon|IDDot>
|
||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDDotDot|IDDot>
|
||||
// - ID1: <0|pkg> (for statuses)
|
||||
// - ID2: <0|literal|ident>
|
||||
// - LHS: <nil|Expr>
|
||||
@@ -318,7 +318,7 @@ const MaxExprDepth = 255
|
||||
//
|
||||
// For indexes, like "LHS[RHS]", ID0 is IDOpenBracket.
|
||||
//
|
||||
// For slices, like "LHS[MHS:RHS]", ID0 is IDColon.
|
||||
// For slices, like "LHS[MHS .. RHS]", ID0 is IDDotDot.
|
||||
//
|
||||
// For selectors, like "LHS.ID2", ID0 is IDDot.
|
||||
//
|
||||
|
||||
+10
-4
@@ -105,12 +105,18 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
|
||||
buf = n.rhs.AsExpr().appendStr(buf, tm, false, depth)
|
||||
buf = append(buf, ']')
|
||||
|
||||
case t.IDColon:
|
||||
case t.IDDotDot:
|
||||
buf = n.lhs.AsExpr().appendStr(buf, tm, true, depth)
|
||||
buf = append(buf, '[')
|
||||
buf = n.mhs.AsExpr().appendStr(buf, tm, false, depth)
|
||||
buf = append(buf, ':')
|
||||
buf = n.rhs.AsExpr().appendStr(buf, tm, false, depth)
|
||||
if n.mhs != nil {
|
||||
buf = n.mhs.AsExpr().appendStr(buf, tm, false, depth)
|
||||
buf = append(buf, ' ')
|
||||
}
|
||||
buf = append(buf, ".."...)
|
||||
if n.rhs != nil {
|
||||
buf = append(buf, ' ')
|
||||
buf = n.rhs.AsExpr().appendStr(buf, tm, false, depth)
|
||||
}
|
||||
buf = append(buf, ']')
|
||||
|
||||
case t.IDDot:
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestString(tt *testing.T) {
|
||||
|
||||
"x[i]",
|
||||
"x[i][j]",
|
||||
"x[i:j]",
|
||||
"x[i .. j]",
|
||||
"x[i](arg:j)",
|
||||
"x(arg:i)[j]",
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestString(tt *testing.T) {
|
||||
"x * ((a / b) - (i / j))",
|
||||
|
||||
"x + y + z",
|
||||
"x + (i * j.k[l] * (-m << 4) * (n & o(o0:p, o1:q[:r.s + 5]))) + z",
|
||||
"x + (i * j.k[l] * (-m << 4) * (n & o(o0:p, o1:q[.. r.s + 5]))) + z",
|
||||
|
||||
"x as base.bool",
|
||||
"x as base.u32",
|
||||
|
||||
@@ -870,7 +870,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (bounds, error) {
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
case t.IDColon:
|
||||
case t.IDDotDot:
|
||||
lhs := n.LHS().AsExpr()
|
||||
if _, err := q.bcheckExpr(lhs, depth); err != nil {
|
||||
return bounds{}, err
|
||||
|
||||
+2
-2
@@ -434,9 +434,9 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
n.SetMType(lTyp.Inner())
|
||||
return nil
|
||||
|
||||
case t.IDColon:
|
||||
case t.IDDotDot:
|
||||
// n is a slice.
|
||||
// TODO: require that the i and j in a[i:j] are *unsigned* (or
|
||||
// TODO: require that the i and j in a[i .. j] are *unsigned* (or
|
||||
// non-negative constants)?
|
||||
if mhs := n.MHS().AsExpr(); mhs != nil {
|
||||
if err := q.tcheckExpr(mhs, depth); err != nil {
|
||||
|
||||
+7
-7
@@ -441,10 +441,10 @@ func (p *parser) parseTypeExpr() (*a.TypeExpr, error) {
|
||||
return a.NewTypeExpr(0, pkg, name, lhs.AsNode(), mhs, nil), nil
|
||||
}
|
||||
|
||||
// parseBracket parses "[i:j]", "[i:]", "[:j]" and "[:]". A "..=" replaces the
|
||||
// ":" if sep is t.IDDotDotEq instead of t.IDColon. If sep is t.IDColon, it
|
||||
// also parses "[x]". The returned op is sep for a range or refinement and
|
||||
// t.IDOpenBracket for an index.
|
||||
// parseBracket parses "[i .. j]", "[i ..]", "[.. j]" and "[..]". A "..="
|
||||
// replaces the ".." if sep is t.IDDotDotEq instead of t.IDDotDot. If sep is
|
||||
// t.IDDotDot, it also parses "[x]". The returned op is sep for a range or
|
||||
// refinement and t.IDOpenBracket for an index.
|
||||
func (p *parser) parseBracket(sep t.ID) (op t.ID, ei *a.Expr, ej *a.Expr, err error) {
|
||||
if x := p.peek1(); x != t.IDOpenBracket {
|
||||
got := p.tm.ByID(x)
|
||||
@@ -463,13 +463,13 @@ func (p *parser) parseBracket(sep t.ID) (op t.ID, ei *a.Expr, ej *a.Expr, err er
|
||||
case x == sep:
|
||||
p.src = p.src[1:]
|
||||
|
||||
case x == t.IDCloseBracket && sep == t.IDColon:
|
||||
case x == t.IDCloseBracket && sep == t.IDDotDot:
|
||||
p.src = p.src[1:]
|
||||
return t.IDOpenBracket, nil, ei, nil
|
||||
|
||||
default:
|
||||
extra := ``
|
||||
if sep == t.IDColon {
|
||||
if sep == t.IDDotDot {
|
||||
extra = ` or "]"`
|
||||
}
|
||||
got := p.tm.ByID(x)
|
||||
@@ -1177,7 +1177,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
lhs = a.NewExpr(flags, t.IDOpenParen, 0, 0, lhs.AsNode(), nil, nil, args)
|
||||
|
||||
case t.IDOpenBracket:
|
||||
id0, mhs, rhs, err := p.parseBracket(t.IDColon)
|
||||
id0, mhs, rhs, err := p.parseBracket(t.IDDotDot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1172,7 +1172,6 @@ var isTightLeft = [...]bool{
|
||||
IDCloseBracket: true,
|
||||
|
||||
IDDot: true,
|
||||
IDDotDot: true,
|
||||
IDComma: true,
|
||||
IDExclam: true,
|
||||
IDQuestion: true,
|
||||
@@ -1184,7 +1183,6 @@ var isTightRight = [...]bool{
|
||||
IDOpenBracket: true,
|
||||
|
||||
IDDot: true,
|
||||
IDDotDot: true,
|
||||
IDExclam: true,
|
||||
IDQuestion: true,
|
||||
IDColon: true,
|
||||
|
||||
Reference in new issue
Block a user