github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/compile/internal/syntax/tokens.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package syntax 6 7 type token uint 8 9 //go:generate stringer -type token -linecomment 10 11 const ( 12 _ token = iota 13 _EOF // EOF 14 15 // names and literals 16 _Name // name 17 _Literal // literal 18 19 // operators and operations 20 // _Operator is excluding '*' (_Star) 21 _Operator // op 22 _AssignOp // op= 23 _IncOp // opop 24 _Assign // = 25 _Define // := 26 _Arrow // <- 27 _Star // * 28 29 // delimiters 30 _Lparen // ( 31 _Lbrack // [ 32 _Lbrace // { 33 _Rparen // ) 34 _Rbrack // ] 35 _Rbrace // } 36 _Comma // , 37 _Semi // ; 38 _Colon // : 39 _Dot // . 40 _DotDotDot // ... 41 42 // keywords 43 _Break // break 44 _Case // case 45 _Chan // chan 46 _Const // const 47 _Continue // continue 48 _Default // default 49 _Defer // defer 50 _Else // else 51 _Fallthrough // fallthrough 52 _For // for 53 _Func // func 54 _Go // go 55 _Goto // goto 56 _If // if 57 _Import // import 58 _Interface // interface 59 _Map // map 60 _Package // package 61 _Range // range 62 _Return // return 63 _Select // select 64 _Struct // struct 65 _Switch // switch 66 _Type // type 67 _Var // var 68 69 // empty line comment to exclude it from .String 70 tokenCount // 71 ) 72 73 const ( 74 // for BranchStmt 75 Break = _Break 76 Continue = _Continue 77 Fallthrough = _Fallthrough 78 Goto = _Goto 79 80 // for CallStmt 81 Go = _Go 82 Defer = _Defer 83 ) 84 85 // Make sure we have at most 64 tokens so we can use them in a set. 86 const _ uint64 = 1 << (tokenCount - 1) 87 88 // contains reports whether tok is in tokset. 89 func contains(tokset uint64, tok token) bool { 90 return tokset&(1<<tok) != 0 91 } 92 93 type LitKind uint8 94 95 // TODO(gri) With the 'i' (imaginary) suffix now permitted on integer 96 // and floating-point numbers, having a single ImagLit does 97 // not represent the literal kind well anymore. Remove it? 98 const ( 99 IntLit LitKind = iota 100 FloatLit 101 ImagLit 102 RuneLit 103 StringLit 104 ) 105 106 type Operator uint 107 108 //go:generate stringer -type Operator -linecomment 109 110 const ( 111 _ Operator = iota 112 113 // Def is the : in := 114 Def // : 115 Not // ! 116 Recv // <- 117 118 // precOrOr 119 OrOr // || 120 121 // precAndAnd 122 AndAnd // && 123 124 // precCmp 125 Eql // == 126 Neq // != 127 Lss // < 128 Leq // <= 129 Gtr // > 130 Geq // >= 131 132 // precAdd 133 Add // + 134 Sub // - 135 Or // | 136 Xor // ^ 137 138 // precMul 139 Mul // * 140 Div // / 141 Rem // % 142 And // & 143 AndNot // &^ 144 Shl // << 145 Shr // >> 146 ) 147 148 // Operator precedences 149 const ( 150 _ = iota 151 precOrOr 152 precAndAnd 153 precCmp 154 precAdd 155 precMul 156 )