]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] go/token, go/scanner: add the "~" operator
authorRob Findley <rfindley@google.com>
Fri, 4 Jun 2021 02:07:36 +0000 (22:07 -0400)
committerRobert Findley <rfindley@google.com>
Thu, 17 Jun 2021 02:05:54 +0000 (02:05 +0000)
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>
src/go/scanner/scanner.go
src/go/scanner/scanner_test.go
src/go/token/token.go

index 29cbf39721f6d2746142c5728fe1dfd6c1ea387f..f8bcf4d8642b65e23357ecd09bbed493542687c8 100644 (file)
@@ -969,6 +969,8 @@ scanAgain:
                        }
                case '|':
                        tok = s.switch3(token.OR, token.OR_ASSIGN, '|', token.LOR)
+               case '~':
+                       tok = token.TILDE
                default:
                        // next reports unexpected BOMs - don't repeat
                        if ch != bom {
index ac8d2577169bc94b41114fe256fa85dafd4db39e..dd3c7cf83858537401dfdcd938be25d425d67673 100644 (file)
@@ -40,7 +40,7 @@ type elt struct {
        class int
 }
 
-var tokens = [...]elt{
+var tokens = []elt{
        // Special tokens
        {token.COMMENT, "/* a comment */", special},
        {token.COMMENT, "// a comment \n", special},
@@ -149,6 +149,7 @@ var tokens = [...]elt{
        {token.RBRACE, "}", operator},
        {token.SEMICOLON, ";", operator},
        {token.COLON, ":", operator},
+       {token.TILDE, "~", operator},
 
        // Keywords
        {token.BREAK, "break", keyword},
index 96a1079ec37c4668969721700df0a682087c00f9..d22e575661a2df95726266b65c512fbdda7c5838 100644 (file)
@@ -125,6 +125,11 @@ const (
        TYPE
        VAR
        keyword_end
+
+       additional_beg
+       // additional tokens, handled in an ad-hoc manner
+       TILDE
+       additional_end
 )
 
 var tokens = [...]string{
@@ -225,6 +230,8 @@ var tokens = [...]string{
        SWITCH: "switch",
        TYPE:   "type",
        VAR:    "var",
+
+       TILDE: "~",
 }
 
 // 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
 // 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;
 // it returns false otherwise.