mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +00:00
[dev.typeparams] go/token, go/scanner: add the "~" operator
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>
This commit is contained in:
parent
ad59efb027
commit
7c5d7a4caf
|
@ -969,6 +969,8 @@ scanAgain:
|
||||||
}
|
}
|
||||||
case '|':
|
case '|':
|
||||||
tok = s.switch3(token.OR, token.OR_ASSIGN, '|', token.LOR)
|
tok = s.switch3(token.OR, token.OR_ASSIGN, '|', token.LOR)
|
||||||
|
case '~':
|
||||||
|
tok = token.TILDE
|
||||||
default:
|
default:
|
||||||
// next reports unexpected BOMs - don't repeat
|
// next reports unexpected BOMs - don't repeat
|
||||||
if ch != bom {
|
if ch != bom {
|
||||||
|
|
|
@ -40,7 +40,7 @@ type elt struct {
|
||||||
class int
|
class int
|
||||||
}
|
}
|
||||||
|
|
||||||
var tokens = [...]elt{
|
var tokens = []elt{
|
||||||
// Special tokens
|
// Special tokens
|
||||||
{token.COMMENT, "/* a comment */", special},
|
{token.COMMENT, "/* a comment */", special},
|
||||||
{token.COMMENT, "// a comment \n", special},
|
{token.COMMENT, "// a comment \n", special},
|
||||||
|
@ -149,6 +149,7 @@ var tokens = [...]elt{
|
||||||
{token.RBRACE, "}", operator},
|
{token.RBRACE, "}", operator},
|
||||||
{token.SEMICOLON, ";", operator},
|
{token.SEMICOLON, ";", operator},
|
||||||
{token.COLON, ":", operator},
|
{token.COLON, ":", operator},
|
||||||
|
{token.TILDE, "~", operator},
|
||||||
|
|
||||||
// Keywords
|
// Keywords
|
||||||
{token.BREAK, "break", keyword},
|
{token.BREAK, "break", keyword},
|
||||||
|
|
|
@ -125,6 +125,11 @@ const (
|
||||||
TYPE
|
TYPE
|
||||||
VAR
|
VAR
|
||||||
keyword_end
|
keyword_end
|
||||||
|
|
||||||
|
additional_beg
|
||||||
|
// additional tokens, handled in an ad-hoc manner
|
||||||
|
TILDE
|
||||||
|
additional_end
|
||||||
)
|
)
|
||||||
|
|
||||||
var tokens = [...]string{
|
var tokens = [...]string{
|
||||||
|
@ -225,6 +230,8 @@ var tokens = [...]string{
|
||||||
SWITCH: "switch",
|
SWITCH: "switch",
|
||||||
TYPE: "type",
|
TYPE: "type",
|
||||||
VAR: "var",
|
VAR: "var",
|
||||||
|
|
||||||
|
TILDE: "~",
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns the string corresponding to the token tok.
|
// String returns the string corresponding to the token tok.
|
||||||
|
@ -304,7 +311,9 @@ func (tok Token) IsLiteral() bool { return literal_beg < tok && tok < literal_en
|
||||||
// IsOperator returns true for tokens corresponding to operators and
|
// IsOperator returns true for tokens corresponding to operators and
|
||||||
// delimiters; it returns false otherwise.
|
// 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;
|
// IsKeyword returns true for tokens corresponding to keywords;
|
||||||
// it returns false otherwise.
|
// it returns false otherwise.
|
||||||
|
|
Loading…
Reference in a new issue