Skip to content

Commit 776a901

Browse files
committed
go/scanner, go/token: recognize => (ALIAS) token
For golang#16339. Change-Id: I0f83e46f13b5c8801aacf48fc8b690049edbbbff Reviewed-on: https://go-review.googlesource.com/30210 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
1 parent c1e267c commit 776a901

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/go/scanner/scanner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ scanAgain:
731731
case '>':
732732
tok = s.switch4(token.GTR, token.GEQ, '>', token.SHR, token.SHR_ASSIGN)
733733
case '=':
734-
tok = s.switch2(token.ASSIGN, token.EQL)
734+
tok = s.switch3(token.ASSIGN, token.EQL, '>', token.ALIAS)
735735
case '!':
736736
tok = s.switch2(token.NOT, token.NEQ)
737737
case '&':

src/go/scanner/scanner_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ var tokens = [...]elt{
121121
{token.LAND, "&&", operator},
122122
{token.LOR, "||", operator},
123123
{token.ARROW, "<-", operator},
124+
{token.ALIAS, "=>", operator},
124125
{token.INC, "++", operator},
125126
{token.DEC, "--", operator},
126127

src/go/token/token.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ const (
121121
TYPE
122122
VAR
123123
keyword_end
124+
125+
// Alias support - must add at end to pass Go 1 compatibility test
126+
127+
ALIAS // =>
124128
)
125129

126130
var tokens = [...]string{
@@ -221,6 +225,8 @@ var tokens = [...]string{
221225
SWITCH: "switch",
222226
TYPE: "type",
223227
VAR: "var",
228+
229+
ALIAS: "=>",
224230
}
225231

226232
// String returns the string corresponding to the token tok.
@@ -300,7 +306,7 @@ func (tok Token) IsLiteral() bool { return literal_beg < tok && tok < literal_en
300306
// IsOperator returns true for tokens corresponding to operators and
301307
// delimiters; it returns false otherwise.
302308
//
303-
func (tok Token) IsOperator() bool { return operator_beg < tok && tok < operator_end }
309+
func (tok Token) IsOperator() bool { return operator_beg < tok && tok < operator_end || tok == ALIAS }
304310

305311
// IsKeyword returns true for tokens corresponding to keywords;
306312
// it returns false otherwise.

0 commit comments

Comments
 (0)