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
34 | Ignore_token -> Printf.sprintf "Ignore_token"
37 let kwht = Hashtbl.create 29
42 Hashtbl.add kwht (String.uppercase text) kw
49 ; ("commit", Ignore_token)
53 let kw_or_ident text =
54 try Hashtbl.find kwht (String.uppercase text)
55 with Not_found -> Ident text
61 let ident_head = ['A'-'Z' 'a'-'z' '_']
63 let ident_body = ident_head | dig | ['.' '#' '$']
64 let eol = [ '\n' '\r' ]
65 let no_eol = [^ '\n' '\r' ]
66 let spc = [ ' ' '\t' ]
67 let eol_eof = eol | eof
72 | (ident_head ident_body*) as i { kw_or_ident i }
73 | '"' { Ident (dblquoted lexbuf) }
74 | '\'' { Str (singlequoted lexbuf) }
78 ( ( dig+ (('.' dig*)?) )
84 | spc* eol+ spc* '/' spc* eol+ { Sep }
85 | ( spc | eol )+ { sqltoken lexbuf }
90 | "--" no_eol* eol_eof { sqltoken lexbuf }
93 ([^ '"']* as i) '"' { i }
94 | _ { failwith "double-quoted string not terminated" }
96 and singlequoted = parse
98 ( ( "''" [^ '\'']* )* )
99 ) as i) '\'' { undq i }
100 | _ { failwith "single-quoted string not terminated" }