Commit 776a9010 authored by Robert Griesemer's avatar Robert Griesemer

go/scanner, go/token: recognize => (ALIAS) token

For #16339.

Change-Id: I0f83e46f13b5c8801aacf48fc8b690049edbbbff
Reviewed-on: https://go-review.googlesource.com/30210Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent c1e267cc
...@@ -731,7 +731,7 @@ scanAgain: ...@@ -731,7 +731,7 @@ scanAgain:
case '>': case '>':
tok = s.switch4(token.GTR, token.GEQ, '>', token.SHR, token.SHR_ASSIGN) tok = s.switch4(token.GTR, token.GEQ, '>', token.SHR, token.SHR_ASSIGN)
case '=': case '=':
tok = s.switch2(token.ASSIGN, token.EQL) tok = s.switch3(token.ASSIGN, token.EQL, '>', token.ALIAS)
case '!': case '!':
tok = s.switch2(token.NOT, token.NEQ) tok = s.switch2(token.NOT, token.NEQ)
case '&': case '&':
......
...@@ -121,6 +121,7 @@ var tokens = [...]elt{ ...@@ -121,6 +121,7 @@ var tokens = [...]elt{
{token.LAND, "&&", operator}, {token.LAND, "&&", operator},
{token.LOR, "||", operator}, {token.LOR, "||", operator},
{token.ARROW, "<-", operator}, {token.ARROW, "<-", operator},
{token.ALIAS, "=>", operator},
{token.INC, "++", operator}, {token.INC, "++", operator},
{token.DEC, "--", operator}, {token.DEC, "--", operator},
......
...@@ -121,6 +121,10 @@ const ( ...@@ -121,6 +121,10 @@ const (
TYPE TYPE
VAR VAR
keyword_end keyword_end
// Alias support - must add at end to pass Go 1 compatibility test
ALIAS // =>
) )
var tokens = [...]string{ var tokens = [...]string{
...@@ -221,6 +225,8 @@ var tokens = [...]string{ ...@@ -221,6 +225,8 @@ var tokens = [...]string{
SWITCH: "switch", SWITCH: "switch",
TYPE: "type", TYPE: "type",
VAR: "var", VAR: "var",
ALIAS: "=>",
} }
// String returns the string corresponding to the token tok. // 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 ...@@ -300,7 +306,7 @@ 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 == ALIAS }
// IsKeyword returns true for tokens corresponding to keywords; // IsKeyword returns true for tokens corresponding to keywords;
// it returns false otherwise. // it returns false otherwise.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment