11{
22 open Parser
3+ exception Lexing_error of string
34 let meta_cmds = Hashtbl. create 20
45 let () =
56 List. iter (fun (strcmd , mcmd ) -> Hashtbl. add meta_cmds strcmd mcmd)
1415 [
1516 " INSERT" , INSERT ;
1617 " SELECT" , SELECT ;
18+ " INTO" , INTO ;
19+ " VALUES" , VALUES ;
20+ " FROM" , FROM ;
1721 ]
1822}
1923
@@ -23,7 +27,8 @@ let frac = '.'digit*
2327let float = digit* frac?
2428let white = [' ' '\t' ]+
2529let meta_command = ['.' ]['a' - 'z' 'A' - 'Z' '_' ]+
26- let statement = ['a' - 'z' 'A' - 'Z' '_' ]+
30+ let statement = ['A' - 'Z' '_' ]['A' - 'Z' '_' ]+
31+ let id = ['A' - 'Z' 'a' - 'z' '_' ]['a' - 'z' '_' '0' - '9' ]*
2732let newline = '\r' | '\n' | " \r\n "
2833
2934
@@ -42,25 +47,31 @@ rule read =
4247 | " FALSE" { FALSE }
4348 | " ==" { STRUCT_COMP }
4449 | " <>" { NEQ }
45- | " <" { LT }
46- | " >" { GT }
4750 | " <=" { LEQ }
4851 | " >=" { GEQ }
49- | " ;;" { ENTER }
52+ | " <" { LT }
53+ | " >" { GT }
54+ | " ," { COMMA }
5055 | white { read lexbuf}
5156 | int { INT (int_of_string(Lexing. lexeme lexbuf))}
5257 | float { FLOAT (float_of_string(Lexing. lexeme lexbuf))}
5358 | meta_command as md
5459 {try Hashtbl. find meta_cmds md
55- with Not_found -> IDENTIFIER md}
60+ with Not_found -> UNK_COM md}
5661 | statement as s
57- {try Hashtbl. find stmts (String. uppercase_ascii s)
58- with Not_found -> IDENTIFIER s}
62+ {try Hashtbl. find stmts s
63+ with Not_found -> UNK_COM s}
64+ | id as s { IDENTIFIER s }
5965 | newline { Lexing. new_line lexbuf; read lexbuf }
66+ | " '" { read_string (Buffer. create 16 ) lexbuf}
6067 | eof { EOF }
61- (* | _ { raise (Failure ("Char not allowed in text: " ^Lexing.lexeme lexbuf^)} *)
68+ | _ { raise ( Lexing_error ( " bad char, error " ))}
6269and comment =
6370 parse
6471 | newline { Lexing. new_line lexbuf; read lexbuf}
6572 | eof { EOF }
6673 | _ { comment lexbuf }
74+ and read_string buff = parse
75+ | " '" { STRING (Buffer. contents buff)}
76+ | _ as c { Buffer. add_char buff c; read_string buff lexbuf }
77+ | eof { raise (Lexing_error (" String not finished, error" ))}
0 commit comments