This is an approximate port of CL 307370 to go/token and go/scanner.
Change-Id: I5b789408f825f7e39f569322cb67802117b9d734
Reviewed-on: https://go-review.googlesource.com/c/go/+/324992
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
}
case '|':
tok = s.switch3(token.OR, token.OR_ASSIGN, '|', token.LOR)
+ case '~':
+ tok = token.TILDE
default:
// next reports unexpected BOMs - don't repeat
if ch != bom {
class int
}
-var tokens = [...]elt{
+var tokens = []elt{
// Special tokens
{token.COMMENT, "/* a comment */", special},
{token.COMMENT, "// a comment \n", special},
{token.RBRACE, "}", operator},
{token.SEMICOLON, ";", operator},
{token.COLON, ":", operator},
+ {token.TILDE, "~", operator},
// Keywords
{token.BREAK, "break", keyword},
TYPE
VAR
keyword_end
+
+ additional_beg
+ // additional tokens, handled in an ad-hoc manner
+ TILDE
+ additional_end
)
var tokens = [...]string{
SWITCH: "switch",
TYPE: "type",
VAR: "var",
+
+ TILDE: "~",
}
// String returns the string corresponding to the token tok.
// IsOperator returns true for tokens corresponding to operators and
// delimiters; it returns false otherwise.
//
-func (tok Token) IsOperator() bool { return operator_beg < tok && tok < operator_end }
+func (tok Token) IsOperator() bool {
+ return (operator_beg < tok && tok < operator_end) || tok == TILDE
+}
// IsKeyword returns true for tokens corresponding to keywords;
// it returns false otherwise.