This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
scanner.l
341 lines (284 loc) · 9.01 KB
/
scanner.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
%{
// Copyright (c) 2014 The ql Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
%}
%option case-insensitive
%x S1 S2
%yyc c
%yym l.Mark()
%yyn c = l.Next()
%yyt l.sc
%{
package ql
import (
"fmt"
"strconv"
)
// Implements yyLexer.
func (l *lexer) Lex(lval *yySymType) (r int) {
const (
INITIAL = iota
S1
S2
)
if n := l.inj; n != 0 {
l.inj = 0
return n
}
defer func() {
pos := l.file.Position(l.First.Pos())
l.line = pos.Line
l.col = pos.Column
lval.line, lval.col = l.line, l.col
}()
c := l.Enter()
%}
int_lit {decimal_lit}|{octal_lit}|{hex_lit}
decimal_lit [1-9][0-9]*
octal_lit 0[0-7]*
hex_lit 0[xX][0-9a-fA-F]+
float_lit {D}"."{D}?{E}?|{D}{E}|"."{D}{E}?
D [0-9]+
E [eE][-+]?[0-9]+
imaginary_ilit {D}i
imaginary_lit {float_lit}i
a [aA]
b [bB]
c [cC]
d [dD]
e [eE]
f [fF]
g [gG]
h [hH]
i [iI]
j [jJ]
k [kK]
l [lL]
m [mM]
n [nN]
o [oO]
p [pP]
q [qQ]
r [rR]
s [sS]
t [tT]
u [uU]
v [vV]
w [wW]
x [xX]
y [yY]
z [zZ]
add {a}{d}{d}
alter {a}{l}{t}{e}{r}
and {a}{n}{d}
as {a}{s}
asc {a}{s}{c}
begin {b}{e}{g}{i}{n}
between {b}{e}{t}{w}{e}{e}{n}
by {b}{y}
column {c}{o}{l}{u}{m}{n}
commit {c}{o}{m}{m}{i}{t}
create {c}{r}{e}{a}{t}{e}
default {d}{e}{f}{a}{u}{l}{t}
delete {d}{e}{l}{e}{t}{e}
desc {d}{e}{s}{c}
distinct {d}{i}{s}{t}{i}{n}{c}{t}
drop {d}{r}{o}{p}
exists {e}{x}{i}{s}{t}{s}
explain {e}{x}{p}{l}{a}{i}{n}
from {f}{r}{o}{m}
full {f}{u}{l}{l}
group {g}{r}{o}{u}{p}
if {i}{f}
in {i}{n}
index {i}{n}{d}{e}{x}
insert {i}{n}{s}{e}{r}{t}
into {i}{n}{t}{o}
is {i}{s}
join {j}{o}{i}{n}
left {l}{e}{f}{t}
like {l}{i}{k}{e}
limit {l}{i}{m}{i}{t}
not {n}{o}{t}
offset {o}{f}{f}{s}{e}{t}
on {o}{n}
or {o}{r}
order {o}{r}{d}{e}{r}
outer {o}{u}{t}{e}{r}
right {r}{i}{g}{h}{t}
rollback {r}{o}{l}{l}{b}{a}{c}{k}
select {s}{e}{l}{e}{c}{t}
set {s}{e}{t}
table {t}{a}{b}{l}{e}
transaction {t}{r}{a}{n}{s}{a}{c}{t}{i}{o}{n}
truncate {t}{r}{u}{n}{c}{a}{t}{e}
unique {u}{n}{i}{q}{u}{e}
update {u}{p}{d}{a}{t}{e}
values {v}{a}{l}{u}{e}{s}
where {w}{h}{e}{r}{e}
null {n}{u}{l}{l}
false {f}{a}{l}{s}{e}
true {t}{r}{u}{e}
bigint {b}{i}{g}{i}{n}{t}
bigrat {b}{i}{g}{r}{a}{t}
blob {b}{l}{o}{b}
bool {b}{o}{o}{l}
byte {b}{y}{t}{e}
complex {c}{o}{m}{p}{l}{e}{x}
duration {d}{u}{r}{a}{t}{i}{o}{n}
float {f}{l}{o}{a}{t}
int {i}{n}{t}
rune {r}{u}{n}{e}
string {s}{t}{r}{i}{n}{g}
time {t}{i}{m}{e}
uint {u}{i}{n}{t}
idchar0 [a-zA-Z_\x81]
idchars {idchar0}|[0-9\x82]
ident {idchar0}{idchars}*
%%
c = l.Rule0()
<*>\x80 return 0
[ \t\n\r]+
--.*
\/\/.*
\/\*([^*]|\*+[^*/])*\*+\/
{imaginary_ilit} return l.int(lval, true)
{imaginary_lit} return l.float(lval, true)
{int_lit} return l.int(lval, false)
{float_lit} return l.float(lval, false)
\" l.sc = S1
` l.sc = S2
'(\\.|[^'])*' if ret := l.str(lval, ""); ret != stringLit {
return ret
}
lval.item = idealRune(lval.item.(string)[0])
return intLit
<S1>(\\.|[^\"])*\" return l.str(lval, "\"")
<S2>([^`]|\n)*` return l.str(lval, "`")
"!=" return neq
"&&" return andand
"&^" return andnot
"<<" return lsh
"<=" return le
"==" return eq
">=" return ge
">>" return rsh
"||" return oror
{add} return add
{alter} return alter
{and} return and
{asc} return asc
{as} return as
{begin} return begin
{between} return between
{by} return by
{column} return column
{commit} return commit
{create} return create
{default} return defaultKwd
{delete} return deleteKwd
{desc} return desc
{distinct} return distinct
{drop} return drop
{exists} return exists
{explain} return explain
{from} return from
{full} return full
{group} return group
{if} return ifKwd
{index} return index
{insert} return insert
{into} return into
{in} return in
{is} return is
{join} return join
{left} return left
{like} return like
{limit} return limit
{not} return not
{offset} return offset
{on} return on
{order} return order
{or} return or
{outer} return outer
{right} return right
{rollback} return rollback
{select} l.agg = append(l.agg, false)
return selectKwd
{set} return set
{table} return tableKwd
{transaction} return transaction
{truncate} return truncate
{update} return update
{unique} return unique
{values} return values
{where} return where
{null} lval.item = nil
return null
{false} lval.item = false
return falseKwd
{true} lval.item = true
return trueKwd
{bigint} lval.item = qBigInt
return bigIntType
{bigrat} lval.item = qBigRat
return bigRatType
{blob} lval.item = qBlob
return blobType
{bool} lval.item = qBool
return boolType
{byte} lval.item = qUint8
return byteType
{complex}128 lval.item = qComplex128
return complex128Type
{complex}64 lval.item = qComplex64
return complex64Type
{duration} lval.item = qDuration
return durationType
{float} lval.item = qFloat64
return floatType
{float}32 lval.item = qFloat32
return float32Type
{float}64 lval.item = qFloat64
return float64Type
{int} lval.item = qInt64
return intType
{int}16 lval.item = qInt16
return int16Type
{int}32 lval.item = qInt32
return int32Type
{int}64 lval.item = qInt64
return int64Type
{int}8 lval.item = qInt8
return int8Type
{rune} lval.item = qInt32
return runeType
{string} lval.item = qString
return stringType
{time} lval.item = qTime
return timeType
{uint} lval.item = qUint64
return uintType
{uint}16 lval.item = qUint16
return uint16Type
{uint}32 lval.item = qUint32
return uint32Type
{uint}64 lval.item = qUint64
return uint64Type
{uint}8 lval.item = qUint8
return uint8Type
{ident} lval.item = string(l.TokenBytes(nil))
return identifier
($|\?)({D}|{ident}) s := string(l.TokenBytes(nil)[1:])
lval.item, _ = strconv.Atoi(s)
if s != "" && s[0] < '1' || s[0] > '9' {
l.err("parameter number must be non zero")
}
return qlParam
%%
if c, ok := l.Abort(); ok {
return c
}
goto yyAction
}