mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 17:01:35 +01:00
Remove token ID/Key distinction, part 7 of N
This commit is contained in:
1 parent
5c48c84cae
commit
81e02e7db6
2 files changed
+45
-42
No files matched your search
+41
-37
@@ -35,9 +35,48 @@ 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:
|
||||
case n.id0.IsXUnaryOp():
|
||||
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
|
||||
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
|
||||
|
||||
case n.id0.IsXBinaryOp():
|
||||
if parenthesize {
|
||||
buf = append(buf, '(')
|
||||
}
|
||||
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
|
||||
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
|
||||
if n.id0.Key() == t.KeyXBinaryAs {
|
||||
buf = append(buf, n.rhs.TypeExpr().Str(tm)...)
|
||||
} else {
|
||||
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
|
||||
}
|
||||
if parenthesize {
|
||||
buf = append(buf, ')')
|
||||
}
|
||||
|
||||
case n.id0.IsXAssociativeOp():
|
||||
if parenthesize {
|
||||
buf = append(buf, '(')
|
||||
}
|
||||
op := opStrings[0xFF&n.id0.Key()]
|
||||
for i, o := range n.list0 {
|
||||
if i != 0 {
|
||||
buf = append(buf, op...)
|
||||
}
|
||||
buf = o.Expr().appendStr(buf, tm, true, depth)
|
||||
}
|
||||
if parenthesize {
|
||||
buf = append(buf, ')')
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
switch n.id0.Key() {
|
||||
case t.KeyError, t.KeyStatus, t.KeySuspension:
|
||||
switch n.id0.Key() {
|
||||
@@ -108,41 +147,6 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
|
||||
}
|
||||
buf = append(buf, ')')
|
||||
}
|
||||
|
||||
case n.id0.IsXUnaryOp():
|
||||
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
|
||||
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
|
||||
|
||||
case n.id0.IsXBinaryOp():
|
||||
if parenthesize {
|
||||
buf = append(buf, '(')
|
||||
}
|
||||
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
|
||||
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
|
||||
if n.id0.Key() == t.KeyXBinaryAs {
|
||||
buf = append(buf, n.rhs.TypeExpr().Str(tm)...)
|
||||
} else {
|
||||
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
|
||||
}
|
||||
if parenthesize {
|
||||
buf = append(buf, ')')
|
||||
}
|
||||
|
||||
case n.id0.IsXAssociativeOp():
|
||||
if parenthesize {
|
||||
buf = append(buf, '(')
|
||||
}
|
||||
op := opStrings[0xFF&n.id0.Key()]
|
||||
for i, o := range n.list0 {
|
||||
if i != 0 {
|
||||
buf = append(buf, op...)
|
||||
}
|
||||
buf = o.Expr().appendStr(buf, tm, true, depth)
|
||||
}
|
||||
if parenthesize {
|
||||
buf = append(buf, ')')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buf
|
||||
|
||||
+4
-5
@@ -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".
|
||||
|
||||
Reference in new issue
Block a user