Skip to content

Commit 7c5d7a4

Browse files
committed
[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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent ad59efb commit 7c5d7a4

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Diff for: src/go/scanner/scanner.go

+2
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,8 @@ scanAgain:
969969
}
970970
case '|':
971971
tok = s.switch3(token.OR, token.OR_ASSIGN, '|', token.LOR)
972+
case '~':
973+
tok = token.TILDE
972974
default:
973975
// next reports unexpected BOMs - don't repeat
974976
if ch != bom {

Diff for: src/go/scanner/scanner_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type elt struct {
4040
class int
4141
}
4242

43-
var tokens = [...]elt{
43+
var tokens = []elt{
4444
// Special tokens
4545
{token.COMMENT, "/* a comment */", special},
4646
{token.COMMENT, "// a comment \n", special},
@@ -149,6 +149,7 @@ var tokens = [...]elt{
149149
{token.RBRACE, "}", operator},
150150
{token.SEMICOLON, ";", operator},
151151
{token.COLON, ":", operator},
152+
{token.TILDE, "~", operator},
152153

153154
// Keywords
154155
{token.BREAK, "break", keyword},

Diff for: src/go/token/token.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ const (
125125
TYPE
126126
VAR
127127
keyword_end
128+
129+
additional_beg
130+
// additional tokens, handled in an ad-hoc manner
131+
TILDE
132+
additional_end
128133
)
129134

130135
var tokens = [...]string{
@@ -225,6 +230,8 @@ var tokens = [...]string{
225230
SWITCH: "switch",
226231
TYPE: "type",
227232
VAR: "var",
233+
234+
TILDE: "~",
228235
}
229236

230237
// 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
304311
// IsOperator returns true for tokens corresponding to operators and
305312
// delimiters; it returns false otherwise.
306313
//
307-
func (tok Token) IsOperator() bool { return operator_beg < tok && tok < operator_end }
314+
func (tok Token) IsOperator() bool {
315+
return (operator_beg < tok && tok < operator_end) || tok == TILDE
316+
}
308317

309318
// IsKeyword returns true for tokens corresponding to keywords;
310319
// it returns false otherwise.

0 commit comments

Comments
 (0)