Remove token ID/Key distinction, part 7 of N

This commit is contained in:
Nigel Tao committed 2018-04-15 15:15:56 +10:00
1 parent 5c48c84cae
commit 81e02e7db6
2 files changed
+81 -78

No files matched your search

+77 -73
View File
@@ -35,80 +35,12 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
}
depth++
if n != nil {
if n == nil {
return buf
}
if n.id0.IsXOp() {
switch {
default:
switch n.id0.Key() {
case t.KeyError, t.KeyStatus, t.KeySuspension:
switch n.id0.Key() {
case t.KeyError:
buf = append(buf, "error "...)
case t.KeyStatus:
buf = append(buf, "status "...)
case t.KeySuspension:
buf = append(buf, "suspension "...)
}
if n.id1 != 0 {
buf = append(buf, tm.ByID(n.id1)...)
buf = append(buf, '.')
}
fallthrough
case 0:
buf = append(buf, tm.ByID(n.id2)...)
case t.KeyTry:
buf = append(buf, "try "...)
fallthrough
case t.KeyOpenParen:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
if n.flags&FlagsSuspendible != 0 {
buf = append(buf, '?')
} else if n.flags&FlagsImpure != 0 {
buf = append(buf, '!')
}
buf = append(buf, '(')
for i, o := range n.list0 {
if i != 0 {
buf = append(buf, ", "...)
}
buf = append(buf, tm.ByID(o.Arg().Name())...)
buf = append(buf, ':')
buf = o.Arg().Value().appendStr(buf, tm, false, depth)
}
buf = append(buf, ')')
case t.KeyOpenBracket:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '[')
buf = n.rhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ']')
case t.KeyColon:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '[')
buf = n.mhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ':')
buf = n.rhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ']')
case t.KeyDot:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '.')
buf = append(buf, tm.ByID(n.id2)...)
case t.KeyDollar:
buf = append(buf, "$("...)
for i, o := range n.list0 {
if i != 0 {
buf = append(buf, ", "...)
}
buf = o.Expr().appendStr(buf, tm, false, depth)
}
buf = append(buf, ')')
}
case n.id0.IsXUnaryOp():
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
@@ -143,6 +75,78 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
buf = append(buf, ')')
}
}
} else {
switch n.id0.Key() {
case t.KeyError, t.KeyStatus, t.KeySuspension:
switch n.id0.Key() {
case t.KeyError:
buf = append(buf, "error "...)
case t.KeyStatus:
buf = append(buf, "status "...)
case t.KeySuspension:
buf = append(buf, "suspension "...)
}
if n.id1 != 0 {
buf = append(buf, tm.ByID(n.id1)...)
buf = append(buf, '.')
}
fallthrough
case 0:
buf = append(buf, tm.ByID(n.id2)...)
case t.KeyTry:
buf = append(buf, "try "...)
fallthrough
case t.KeyOpenParen:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
if n.flags&FlagsSuspendible != 0 {
buf = append(buf, '?')
} else if n.flags&FlagsImpure != 0 {
buf = append(buf, '!')
}
buf = append(buf, '(')
for i, o := range n.list0 {
if i != 0 {
buf = append(buf, ", "...)
}
buf = append(buf, tm.ByID(o.Arg().Name())...)
buf = append(buf, ':')
buf = o.Arg().Value().appendStr(buf, tm, false, depth)
}
buf = append(buf, ')')
case t.KeyOpenBracket:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '[')
buf = n.rhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ']')
case t.KeyColon:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '[')
buf = n.mhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ':')
buf = n.rhs.Expr().appendStr(buf, tm, false, depth)
buf = append(buf, ']')
case t.KeyDot:
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
buf = append(buf, '.')
buf = append(buf, tm.ByID(n.id2)...)
case t.KeyDollar:
buf = append(buf, "$("...)
for i, o := range n.list0 {
if i != 0 {
buf = append(buf, ", "...)
}
buf = o.Expr().appendStr(buf, tm, false, depth)
}
buf = append(buf, ')')
}
}
return buf
+4 -5
View File
@@ -40,8 +40,6 @@ const (
// Key is the high 16 bits of an ID. It is the map key for a Map.
type Key uint32
func (k Key) isXOp() bool { return minXOpKey <= k && k <= maxXOpKey }
const (
FlagsBits = 16
FlagsMask = 1<<FlagsBits - 1
@@ -93,9 +91,10 @@ func (x ID) IsImplicitSemicolon() bool {
(x.Key() < Key(len(isImplicitSemicolon)) && isImplicitSemicolon[x.Key()])
}
func (x ID) IsXUnaryOp() bool { return x.Key().isXOp() && x.IsUnaryOp() }
func (x ID) IsXBinaryOp() bool { return x.Key().isXOp() && x.IsBinaryOp() }
func (x ID) IsXAssociativeOp() bool { return x.Key().isXOp() && x.IsAssociativeOp() }
func (x ID) IsXOp() bool { return minXOpKey <= x.Key() && x.Key() <= maxXOpKey }
func (x ID) IsXUnaryOp() bool { return x.IsXOp() && x.IsUnaryOp() }
func (x ID) IsXBinaryOp() bool { return x.IsXOp() && x.IsBinaryOp() }
func (x ID) IsXAssociativeOp() bool { return x.IsXOp() && x.IsAssociativeOp() }
// QID is a qualified ID, such as "foo.bar". QID[0] is "foo"'s ID and QID[1] is
// "bar"'s. QID[0] may be 0 for a plain "bar".