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