7 let i = String.index s '\'' in
8 let () = assert (s.[i+1] = '\'') in
9 (String.sub s 0 (i+1)) ^
12 ((String.length s) - (i+2))
19 let string_of_sqltoken t =
21 Ident s -> Printf.sprintf "Ident(%S)" s
22 | Str s -> Printf.sprintf "Str(%S)" s
23 | Num s -> Printf.sprintf "Num(%S)" s
36 let kwht = Hashtbl.create 29
41 Hashtbl.add kwht (String.uppercase text) kw
51 let kw_or_ident text =
52 try Hashtbl.find kwht (String.uppercase text)
53 with Not_found -> Ident text
59 let ident_head = ['A'-'Z' 'a'-'z' '_']
61 let ident_body = ident_head | dig | ['.' '#' '$']
62 let eol = [ '\n' '\r' ]
63 let no_eol = [^ '\n' '\r' ]
64 let spc = [ ' ' '\t' ]
65 let eol_eof = eol | eof
70 | (ident_head ident_body*) as i { kw_or_ident i }
71 | '"' { Ident (dblquoted lexbuf) }
72 | '\'' { Str (singlequoted lexbuf) }
76 ( ( dig+ (('.' dig*)?) )
82 | spc* eol+ spc* '/' spc* eol+ { Sep }
83 | ( spc | eol )+ { sqltoken lexbuf }
88 | "--" no_eol* eol_eof { sqltoken lexbuf }
91 ([^ '"']* as i) '"' { i }
92 | _ { failwith "double-quoted string not terminated" }
94 and singlequoted = parse
96 ( ( "''" [^ '\'']* )* )
97 ) as i) '\'' { undq i }
98 | _ { failwith "single-quoted string not terminated" }