mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Remove token ID/Key distinction, part 7 of N
This commit is contained in:
1 parent
5c48c84cae
commit
81e02e7db6
2 files changed
+81
-78
No files matched your search
+77
-73
@@ -35,80 +35,12 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
|
|||||||
}
|
}
|
||||||
depth++
|
depth++
|
||||||
|
|
||||||
if n != nil {
|
if n == nil {
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
if n.id0.IsXOp() {
|
||||||
switch {
|
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():
|
case n.id0.IsXUnaryOp():
|
||||||
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
|
buf = append(buf, opStrings[0xFF&n.id0.Key()]...)
|
||||||
buf = n.rhs.Expr().appendStr(buf, tm, true, depth)
|
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, ')')
|
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
|
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.
|
// Key is the high 16 bits of an ID. It is the map key for a Map.
|
||||||
type Key uint32
|
type Key uint32
|
||||||
|
|
||||||
func (k Key) isXOp() bool { return minXOpKey <= k && k <= maxXOpKey }
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FlagsBits = 16
|
FlagsBits = 16
|
||||||
FlagsMask = 1<<FlagsBits - 1
|
FlagsMask = 1<<FlagsBits - 1
|
||||||
@@ -93,9 +91,10 @@ func (x ID) IsImplicitSemicolon() bool {
|
|||||||
(x.Key() < Key(len(isImplicitSemicolon)) && isImplicitSemicolon[x.Key()])
|
(x.Key() < Key(len(isImplicitSemicolon)) && isImplicitSemicolon[x.Key()])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x ID) IsXUnaryOp() bool { return x.Key().isXOp() && x.IsUnaryOp() }
|
func (x ID) IsXOp() bool { return minXOpKey <= x.Key() && x.Key() <= maxXOpKey }
|
||||||
func (x ID) IsXBinaryOp() bool { return x.Key().isXOp() && x.IsBinaryOp() }
|
func (x ID) IsXUnaryOp() bool { return x.IsXOp() && x.IsUnaryOp() }
|
||||||
func (x ID) IsXAssociativeOp() bool { return x.Key().isXOp() && x.IsAssociativeOp() }
|
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
|
// 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".
|
// "bar"'s. QID[0] may be 0 for a plain "bar".
|
||||||
|
|||||||
Reference in new issue
Block a user