]> Cypherpunks repositories - gostls13.git/commitdiff
go/scanner, go/token: recognize => (ALIAS) token
authorRobert Griesemer <gri@golang.org>
Mon, 3 Oct 2016 20:24:56 +0000 (13:24 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 4 Oct 2016 22:44:42 +0000 (22:44 +0000)
For #16339.

Change-Id: I0f83e46f13b5c8801aacf48fc8b690049edbbbff
Reviewed-on: https://go-review.googlesource.com/30210
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/go/scanner/scanner.go
src/go/scanner/scanner_test.go
src/go/token/token.go

index ce660c71d5c954218a88221ceb41235f266874b2..bf63e814aa7a0af3783e5b61f6368f244237bcbd 100644 (file)
@@ -731,7 +731,7 @@ scanAgain:
                case '>':
                        tok = s.switch4(token.GTR, token.GEQ, '>', token.SHR, token.SHR_ASSIGN)
                case '=':
-                       tok = s.switch2(token.ASSIGN, token.EQL)
+                       tok = s.switch3(token.ASSIGN, token.EQL, '>', token.ALIAS)
                case '!':
                        tok = s.switch2(token.NOT, token.NEQ)
                case '&':
index 0d21905166c286eba4d913e6ba7181fac3827598..d1f2158898fee5dbaac5208ba077fe433c501709 100644 (file)
@@ -121,6 +121,7 @@ var tokens = [...]elt{
        {token.LAND, "&&", operator},
        {token.LOR, "||", operator},
        {token.ARROW, "<-", operator},
+       {token.ALIAS, "=>", operator},
        {token.INC, "++", operator},
        {token.DEC, "--", operator},
 
index 865f63f4a146ca03da07074106c59f466a9b9c07..7ad4290fb9d99b3c9c8c7787a189327543f25a7c 100644 (file)
@@ -121,6 +121,10 @@ const (
        TYPE
        VAR
        keyword_end
+
+       // Alias support - must add at end to pass Go 1 compatibility test
+
+       ALIAS // =>
 )
 
 var tokens = [...]string{
@@ -221,6 +225,8 @@ var tokens = [...]string{
        SWITCH: "switch",
        TYPE:   "type",
        VAR:    "var",
+
+       ALIAS: "=>",
 }
 
 // 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
 // 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 == ALIAS }
 
 // IsKeyword returns true for tokens corresponding to keywords;
 // it returns false otherwise.