Remove token ID/Key distinction, part 9 of N

This commit is contained in:
Nigel Tao committed 2018-04-15 15:41:48 +10:00
1 parent 1717d5befd
commit 10b6eaebb6
3 files changed
+112 -84

No files matched your search

+6 -8
View File
@@ -110,7 +110,7 @@ func Render(w io.Writer, tm *t.Map, src []t.Token, comments []string) (err error
if prevID != 0 && !prevIsTightRight && !tok.ID.IsTightLeft() {
// The "(" token's tight-left-ness is context dependent. For
// "f(x)", the "(" is tight-left. For "a * (b + c)", it is not.
if tok.ID.Key() != t.KeyOpenParen || !isCloseIdentStrLiteral(prevID) {
if tok.ID.Key() != t.KeyOpenParen || !isCloseIdentStrLiteral(tm, prevID) {
buf = append(buf, ' ')
}
}
@@ -135,7 +135,7 @@ func Render(w io.Writer, tm *t.Map, src []t.Token, comments []string) (err error
if prevID != 0 && tok.ID.IsUnaryOp() && tok.ID.IsBinaryOp() {
// Token-based (not ast.Node-based) heuristic for whether the
// operator looks unary instead of binary.
prevIsTightRight = !isCloseIdentLiteral(prevID)
prevIsTightRight = !isCloseIdentLiteral(tm, prevID)
}
prevID = tok.ID
@@ -205,12 +205,10 @@ func appendTabs(buf []byte, n int) []byte {
return buf
}
func isCloseIdentLiteral(x t.ID) bool {
const flags = t.FlagsIdent | t.FlagsLiteral
return x.IsClose() || x.Flags()&flags != 0
func isCloseIdentLiteral(tm *t.Map, x t.ID) bool {
return x.IsClose() || x.IsIdent(tm) || x.IsLiteral(tm)
}
func isCloseIdentStrLiteral(x t.ID) bool {
const flags = t.FlagsIdent | t.FlagsStrLiteral
return x.IsClose() || x.Flags()&flags != 0
func isCloseIdentStrLiteral(tm *t.Map, x t.ID) bool {
return x.IsClose() || x.IsIdent(tm) || x.IsStrLiteral(tm)
}