Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/compile/internal/syntax/tokens.go

Documentation: cmd/compile/internal/syntax

     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 tokens.go
    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 tokens.go
   109  
   110  const (
   111  	_ Operator = iota
   112  
   113  	// Def is the : in :=
   114  	Def   // :
   115  	Not   // !
   116  	Recv  // <-
   117  	Tilde // ~
   118  
   119  	// precOrOr
   120  	OrOr // ||
   121  
   122  	// precAndAnd
   123  	AndAnd // &&
   124  
   125  	// precCmp
   126  	Eql // ==
   127  	Neq // !=
   128  	Lss // <
   129  	Leq // <=
   130  	Gtr // >
   131  	Geq // >=
   132  
   133  	// precAdd
   134  	Add // +
   135  	Sub // -
   136  	Or  // |
   137  	Xor // ^
   138  
   139  	// precMul
   140  	Mul    // *
   141  	Div    // /
   142  	Rem    // %
   143  	And    // &
   144  	AndNot // &^
   145  	Shl    // <<
   146  	Shr    // >>
   147  )
   148  
   149  // Operator precedences
   150  const (
   151  	_ = iota
   152  	precOrOr
   153  	precAndAnd
   154  	precCmp
   155  	precAdd
   156  	precMul
   157  )
   158  

View as plain text