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 }
105 | "?" (digit+ as str) { PARAM (Stmt.Raw.Numbered (int_of_string str)) }
106 | [':' '@'] (ident as str) { PARAM (Stmt.Raw.Named str) }
109 | "CONFLICT" { CONFLICT }
112 | "IGNORE" { IGNORE }
113 | "REPLACE" { REPLACE }
116 | "ROLLBACK" { ROLLBACK }
119 (("LEFT"|"RIGHT"|"FULL") wsp+)?
120 (("INNER"|"OUTER"|"CROSS") wsp+)?
123 | mnot ("LIKE" | "GLOB" | "REGEXP" | "MATCH") { LIKE_OP }
127 | "MAX" | "MIN" | "CONCAT" { FUNCTION }
128 | "ISNULL" | "NOTNULL" { TEST_NULL }
129 | "BETWEEB" { BETWEEN }
131 | "ESCAPE" { ESCAPE }
133 | ident as str { IDENT (str) }
134 | digit+ as str { INTEGER (int_of_string str) }
136 | _ { error lexbuf "ruleMain" }
138 (*ruleInQuotes = parse
139 | '"' { TEXT (!curStr) }
140 | eof { error lexbuf "no terminating quote"; }
141 | '\n' { advance_line lexbuf; error lexbuf "EOL before terminating quote"; }
142 | [^'"' '\n']+ { store (Lexing.lexeme lexbuf); ruleInQuotes lexbuf; }
143 | _ { error lexbuf "ruleInQuotes"; }
146 | '\n' { advance_line lexbuf; !curStr }
148 | [^'\n']+ { store (Lexing.lexeme lexbuf); ruleComment lexbuf; }
149 | _ { error lexbuf "ruleComment"; }
153 let parse_rule lexbuf = ruleMain lexbuf