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