summaryrefslogtreecommitdiff
path: root/src/go/token/token.go
Commit message (Collapse)AuthorAgeFilesLines
* go/token: add IsIdentifier, IsKeyword, and IsExportedDaniel Martí2019-04-151-1/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Telling whether a string is a valid Go identifier can seem like an easy task, but it's easy to forget about the edge cases. For example, some implementations out there forget that an empty string or keywords like "func" aren't valid identifiers. Add a simple implementation with proper Unicode support, and start using it in cmd/cover and cmd/doc. Other pieces of the standard library reimplement part of this logic, but don't use a "func(string) bool" signature, so we're leaving them untouched for now. Add some tests too, to ensure that we actually got these edge cases correctly. Since telling whether a string is a valid identifier requires knowing that it's not a valid keyword, add IsKeyword too. The internal map was already accessible via Lookup, but "Lookup(str) != IDENT" isn't as easy to understand as IsKeyword(str). And, as per Josh's suggestion, we could have IsKeyword (and probably Lookup too) use a perfect hash function instead of a global map. Finally, for consistency with these new functions, add IsExported. That makes go/ast.IsExported a bit redundant, so perhaps it can be deprecated in favor of go/token.IsExported in the future. Clarify that token.IsExported doesn't imply token.IsIdentifier, to avoid ambiguity. Fixes #30064. Change-Id: I0e0e49215fd7e47b603ebc2b5a44086c51ba57f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/169018 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
* Revert "go/scanner, go/token: recognize => (ALIAS) token"Robert Griesemer2016-11-051-7/+1
| | | | | | | | | | | | This reverts commit 776a90100f1f65fcf54dfd3d082d657341bdc323. Reason: Decision to back out current alias implementation. For #16339. Change-Id: Icb451a122c661ded05d9293356b466fa72b965f3 Reviewed-on: https://go-review.googlesource.com/32824 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* go/scanner, go/token: recognize => (ALIAS) tokenRobert Griesemer2016-10-041-1/+7
| | | | | | | | For #16339. Change-Id: I0f83e46f13b5c8801aacf48fc8b690049edbbbff Reviewed-on: https://go-review.googlesource.com/30210 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
* build: move package sources from src/pkg to srcRuss Cox2014-09-081-0/+308
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.