Rename [i:j] to [i .. j], the same as Rust

This commit is contained in:
Nigel Tao committed 2019-10-12 21:14:18 +11:00
1 parent 7872a8893b
commit a9ea63ff06
16 files changed
+55 -50

No files matched your search

+2 -2
View File
@@ -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
View File
@@ -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:
+2 -2
View File
@@ -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",