From d1531f13672ff3b55134271a6ffc72e11a4ba450 Mon Sep 17 00:00:00 2001 From: ygrek Date: Sun, 3 May 2009 10:26:32 +0300 Subject: [PATCH] sql2cpp split into main --- sql2cpp.ml => main.ml | 30 +++++------------ sql2cpp.ml | 91 +++++++++++++++------------------------------------ 2 files changed, 34 insertions(+), 87 deletions(-) copy sql2cpp.ml => main.ml (57%) rewrite sql2cpp.ml (69%) diff --git a/sql2cpp.ml b/main.ml similarity index 57% copy from sql2cpp.ml copy to main.ml index 9117c42..58f283b 100644 --- a/sql2cpp.ml +++ b/main.ml @@ -36,30 +36,16 @@ let show_one ((s,p),props) = let catch f x = try Some (f x) with _ -> None -let with_file filename f = - match catch Std.input_file filename with - | None -> Error.log "cannot open file : %s" filename - | Some s -> f s - let tee f x = f x; x -let work filename = - with_file filename (fun s -> s - >> statements >> L.map parse_one >> L.filter_valid +let parse_sql s = + s >> statements >> L.map parse_one + >> L.filter_valid (* >> tee (L.iter show_one) *) - >> Gen.process) + >> Gen.process -let show_help () = - Error.log "SQL to C++ Code Generator Version %s (%s)" Version.version (Version.revision >> S.explode >> L.take 8 >> S.implode); - Error.log ""; - Error.log " Usage: %s file_with_statements.sql" (Filename.basename Sys.executable_name); - Error.log ""; - Error.log " Parse given file (treating content as SQL statements) and emit corresponding code to stdout" - -let main () = - match Array.to_list Sys.argv with - | _::"-test"::_ -> Test.run () - | _::[file] -> work file - | _ -> show_help () +let with_file filename f = + match catch Std.input_file filename with + | None -> Error.log "cannot open file : %s" filename + | Some s -> f s -let _ = Printexc.print main () diff --git a/sql2cpp.ml b/sql2cpp.ml dissimilarity index 69% index 9117c42..5a2f1a8 100644 --- a/sql2cpp.ml +++ b/sql2cpp.ml @@ -1,65 +1,26 @@ -(* - Main -*) - -open Printf -open Operators -open ListMore -open ExtString - -module L = List -module S = String - -let statements s = - let lexbuf = Lexing.from_string s in - let rec loop l = - match (try Sql_lexer.ruleStatement Props.empty lexbuf with exn -> None) with - | Some x -> loop (x::l) - | None -> l - in - L.rev (loop []) - -let parse_one (stmt,props) = - try -(* print_endline stmt; *) - Some ((Parser.parse_stmt stmt), Props.set props "sql" stmt) - with - | exn -> - begin - prerr_endline (Printexc.to_string exn); - None - end - -let show_one ((s,p),props) = - RA.Scheme.print s; - print_endline (Stmt.params_to_string p) - -let catch f x = try Some (f x) with _ -> None - -let with_file filename f = - match catch Std.input_file filename with - | None -> Error.log "cannot open file : %s" filename - | Some s -> f s - -let tee f x = f x; x - -let work filename = - with_file filename (fun s -> s - >> statements >> L.map parse_one >> L.filter_valid -(* >> tee (L.iter show_one) *) - >> Gen.process) - -let show_help () = - Error.log "SQL to C++ Code Generator Version %s (%s)" Version.version (Version.revision >> S.explode >> L.take 8 >> S.implode); - Error.log ""; - Error.log " Usage: %s file_with_statements.sql" (Filename.basename Sys.executable_name); - Error.log ""; - Error.log " Parse given file (treating content as SQL statements) and emit corresponding code to stdout" - -let main () = - match Array.to_list Sys.argv with - | _::"-test"::_ -> Test.run () - | _::[file] -> work file - | _ -> show_help () - -let _ = Printexc.print main () +(** command-line *) + +open ListMore +open ExtString +open Operators + +let work filename = + Main.with_file filename Main.parse_sql + +let show_help () = + Error.log "SQL to C++ Code Generator Version %s (%s)" + Version.version + (Version.revision >> String.explode >> List.take 8 >> String.implode); + Error.log ""; + Error.log " Usage: %s file_with_statements.sql" (Filename.basename Sys.executable_name); + Error.log ""; + Error.log " Parse given file (treating content as SQL statements) and emit corresponding code to stdout" + +let main () = + match Array.to_list Sys.argv with + | _::"-test"::_ -> Test.run () + | _::[file] -> work file + | _ -> show_help () + +let _ = Printexc.print main () + -- 2.11.4.GIT