9 let store str = curStr := str
11 let error buf callerID =
12 Error.report "Lexer error : %s" callerID;
14 raise Parsing.Parse_error
16 let advance_line_pos pos =
17 let module L = Lexing in
18 {L.pos_fname=pos.L.pos_fname;
19 pos_lnum = pos.L.pos_lnum + 1;
21 pos_cnum = pos.L.pos_cnum}
23 let advance_line lexbuf =
24 lexbuf.Lexing.lex_curr_p <- advance_line_pos lexbuf.Lexing.lex_curr_p
28 let alpha = ['a'-'z' 'A'-'Z']
29 let ident = (alpha) (alpha | digit | '_' )+
31 let mnot = ("NOT" wsp+)?
33 rule ruleStatement props = parse
34 | ['\n' ' ' '\t']+ { ruleStatement props lexbuf }
36 | "--" wsp* "[sql2cpp]" wsp+ (ident+ as n) wsp* "=" wsp* ([^'\n']* as v) '\n'
38 ruleStatement (Props.set props n v) lexbuf
40 | "--" { store ""; ignore (ruleComment lexbuf); ruleStatement props lexbuf }
41 | alpha [^ ';']+ as stmt ';' { Some (stmt,props) }
45 | wsp { ruleMain lexbuf }
46 (* update line number *)
47 | '\n' { advance_line lexbuf; ruleMain lexbuf}
54 | "--" { store ""; ignore (ruleComment lexbuf); ruleMain lexbuf }
55 (* | '"' { store ""; ruleInQuotes lexbuf } *)
58 | "CREATE" wsp+ "TABLE" { CREATE_TABLE }
60 | "REPLACE" { REPLACE }
62 | "DELETE" wsp+ "FROM" { DELETE_FROM }
72 | "UNION" (wsp+ "ALL")? | "EXCEPT" | "INTERSECT" { COMPOUND_OP }
83 (* column-constraint *)
84 | "NOT" wsp+ "NULL" { NOT_NULL }
86 | "PRIMARY" wsp+ "KEY" { PRIMARY_KEY }
87 | "AUTOINCREMENT" { AUTOINCREMENT }
88 | "DEFAULT" { DEFAULT }
91 | "INTEGER" { T_INTEGER }
95 | "DISTINCT" { DISTINCT }
98 | "ORDER" wsp+ "BY" { ORDER_BY }
102 | "OFFSET" { OFFSET }
104 | "?" { PARAM Stmt.Raw.Next }
107 | "CONFLICT" { CONFLICT }
110 | "IGNORE" { IGNORE }
111 | "REPLACE" { REPLACE }
114 | "ROLLBACK" { ROLLBACK }
117 (("LEFT"|"RIGHT"|"FULL") wsp+)?
118 (("INNER"|"OUTER"|"CROSS") wsp+)?
121 | mnot ("LIKE" | "GLOB" | "REGEXP" | "MATCH") { LIKE_OP }
123 | "MAX" | "MIN" { FUNCTION }
124 | "ISNULL" | "NOTNULL" { TEST_NULL }
125 | "BETWEEB" { BETWEEN }
127 | "ESCAPE" { ESCAPE }
129 | ident as str { IDENT (str) }
130 | digit+ as str { INTEGER (int_of_string str) }
132 | _ { error lexbuf "ruleMain" }
134 (*ruleInQuotes = parse
135 | '"' { TEXT (!curStr) }
136 | eof { error lexbuf "no terminating quote"; }
137 | '\n' { advance_line lexbuf; error lexbuf "EOL before terminating quote"; }
138 | [^'"' '\n']+ { store (Lexing.lexeme lexbuf); ruleInQuotes lexbuf; }
139 | _ { error lexbuf "ruleInQuotes"; }
142 | '\n' { advance_line lexbuf; !curStr }
144 | [^'\n']+ { store (Lexing.lexeme lexbuf); ruleComment lexbuf; }
145 | _ { error lexbuf "ruleComment"; }
149 let parse_rule lexbuf = ruleMain lexbuf