From 29bd5dae627271808d3b57e8fcee1b69e1ff9054 Mon Sep 17 00:00:00 2001 From: ygrek Date: Sun, 25 Oct 2009 10:29:46 +0200 Subject: [PATCH] prelude.ml, cleanup --- .gitignore | 2 +- src/gen.ml | 9 ++++----- src/gen_caml.ml | 9 ++++----- src/gen_csharp.ml | 7 +++---- src/gen_cxx.ml | 18 ++++++++---------- src/gen_java.ml | 7 +++---- src/gen_xml.ml | 9 ++++----- src/listMore.ml | 4 ++-- src/main.ml | 5 ++--- src/operators.ml | 4 ---- src/{apply.ml => prelude.ml} | 3 +++ src/rA.ml | 2 +- src/sql_parser.mly | 2 +- src/sqlgg.ml | 4 ++-- src/syntax.ml | 9 ++++----- 15 files changed, 42 insertions(+), 52 deletions(-) delete mode 100644 src/operators.ml rename src/{apply.ml => prelude.ml} (69%) diff --git a/.gitignore b/.gitignore index 93415f8..b40fc11 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,6 @@ impl/*.cm? myocamlbuild.config # autogenerated version.ml -*.md.html +*.html # vim *.swp diff --git a/src/gen.ml b/src/gen.ml index 9a0f166..3cf0b7a 100644 --- a/src/gen.ml +++ b/src/gen.ml @@ -1,9 +1,8 @@ (* Code generation *) open Printf -open ExtList -open ExtString -open Operators +open ExtLib +open Prelude open Stmt type subst_mode = | Named | Unnamed | Oracle @@ -97,10 +96,10 @@ module Translate(T : LangTypes) = struct let param_type_to_string = T.as_api_type let schema_to_values = List.mapi (fun i attr -> name_of attr i, T.as_lang_type attr.RA.domain) -(* let schema_to_string = G.Values.to_string & schema_to_values *) +(* let schema_to_string = G.Values.to_string $ schema_to_values *) let all_params_to_values = List.mapi (fun i (n,t) -> param_name_to_string n i, T.as_lang_type t) (* rev unique rev -- to preserve ordering with respect to first occurrences *) -let params_to_values = List.rev & List.unique & List.rev & all_params_to_values +let params_to_values = List.rev $ List.unique $ List.rev $ all_params_to_values end diff --git a/src/gen_caml.ml b/src/gen_caml.ml index 6d27374..73c1c98 100644 --- a/src/gen_caml.ml +++ b/src/gen_caml.ml @@ -1,8 +1,7 @@ (* OCaml code generation *) -open ExtList -open ExtString -open Operators +open ExtLib +open Prelude open Printf open Stmt @@ -24,7 +23,7 @@ let quote_comment_inline str = replace_all ~str ~sub:"(*" ~by:"( *" let make_comment str = "(* " ^ (quote_comment_inline str) ^ " *)" -let comment () fmt = Printf.kprintf (indent_endline & make_comment) fmt +let comment () fmt = Printf.kprintf (indent_endline $ make_comment) fmt let empty_line () = print_newline () @@ -77,7 +76,7 @@ let is_callback stmt = | _,Select true -> false | _ -> true -let params_to_values = List.map fst & params_to_values +let params_to_values = List.map fst $ params_to_values let set_param index param = let (id,t) = param in diff --git a/src/gen_csharp.ml b/src/gen_csharp.ml index a06c40e..26b7115 100644 --- a/src/gen_csharp.ml +++ b/src/gen_csharp.ml @@ -1,8 +1,7 @@ (* C# code generation *) -open ExtList -open ExtString -open Operators +open ExtLib +open Prelude open Printf open Stmt @@ -56,7 +55,7 @@ let get_column attr index = (attr.RA.domain >> as_api_type) index -let schema_to_string = G.Values.to_string & schema_to_values +let schema_to_string = G.Values.to_string $ schema_to_values let output_schema_binder _ schema = let name = "callback" in diff --git a/src/gen_cxx.ml b/src/gen_cxx.ml index a89219e..a32dd30 100644 --- a/src/gen_cxx.ml +++ b/src/gen_cxx.ml @@ -1,10 +1,8 @@ (* C++ code generation *) -open ExtList -open ExtString -open Operators +open ExtLib +open Prelude open Printf -open Apply open Stmt open Gen @@ -14,8 +12,8 @@ module Values = struct let names = List.map fst let join = String.concat ", " -let inline = join & names -let to_string = join & (List.map (fun (n,t) -> t ^ " " ^ n)) +let inline = join $ names +let to_string = join $ (List.map (fun (n,t) -> t ^ " " ^ n)) end @@ -28,7 +26,7 @@ let quote = String.replace_chars (function '\n' -> "\\n\\\n" | '\r' -> "" | '"' let quote s = "\"" ^ quote s ^ "\"" let quote_comment_inline = String.replace_chars (function '\n' -> "\n// " | c -> String.make 1 c) -let comment () fmt = Printf.kprintf (indent_endline & quote_comment_inline & (^) "// ") fmt +let comment () fmt = Printf.kprintf (indent_endline $ quote_comment_inline $ (^) "// ") fmt let empty_line () = print_newline () let open_curly () = output "{"; inc_indent () let close_curly fmt = dec_indent (); indent "}"; print fmt @@ -136,7 +134,7 @@ let struct_params name values k = let struct_ctor name values k = struct_params name values (fun () -> - func "" name values ~tail:(value_inits values) Apply.id; + func "" name values ~tail:(value_inits values) id; empty_line (); k ()) @@ -168,7 +166,7 @@ let make_stmt index stmt = let name = choose_name stmt.props stmt.kind index in let sql = quote (get_sql stmt) in struct_params name ["stmt","typename Traits::statement"] (fun () -> - func "" name ["db","typename Traits::connection"] ~tail:(sprintf ": stmt(db,SQLGG_STR(%s))" sql) Apply.id; + func "" name ["db","typename Traits::connection"] ~tail:(sprintf ": stmt(db,SQLGG_STR(%s))" sql) id; let schema_binder_name = output_schema_binder index stmt.schema in let params_binder_name = output_params_binder index stmt.params in (* if (Option.is_some schema_binder_name) then output_schema_data index stmt.schema; *) @@ -194,7 +192,7 @@ let make_all name names = | [] -> "" | _ -> ": " ^ (String.concat ", " (List.map (fun name -> sprintf "%s(db)" name) names)) in - func "" name ["db","typename Traits::connection"] ~tail Apply.id + func "" name ["db","typename Traits::connection"] ~tail id let generate () name stmts = output "#pragma once"; diff --git a/src/gen_java.ml b/src/gen_java.ml index f1740c0..a30363c 100644 --- a/src/gen_java.ml +++ b/src/gen_java.ml @@ -1,8 +1,7 @@ (* Java code generation *) -open ExtList -open ExtString -open Operators +open ExtLib +open Prelude open Printf open Stmt @@ -42,7 +41,7 @@ let as_lang_type = function | Type.Bool -> "boolean" | Type.Datetime -> "Timestamp" -let as_api_type = String.capitalize & as_lang_type +let as_api_type = String.capitalize $ as_lang_type end diff --git a/src/gen_xml.ml b/src/gen_xml.ml index 42dff8b..4221203 100644 --- a/src/gen_xml.ml +++ b/src/gen_xml.ml @@ -1,8 +1,7 @@ (** XML generation *) -open ExtList -open ExtString -open Operators +open ExtLib +open Prelude open Printf open Stmt @@ -53,8 +52,8 @@ let value n t = Node ("value",["name",n; "type",t;],[]) open Gen_caml.L open Gen_caml.T -let params_to_values = List.map (fun (n,t) -> value n t) & all_params_to_values -let schema_to_values = List.map (fun (n,t) -> value n t) & schema_to_values +let params_to_values = List.map (fun (n,t) -> value n t) $ all_params_to_values +let schema_to_values = List.map (fun (n,t) -> value n t) $ schema_to_values type t = xml list ref * xml list ref diff --git a/src/listMore.ml b/src/listMore.ml index f40e0a4..12098eb 100644 --- a/src/listMore.ml +++ b/src/listMore.ml @@ -1,6 +1,6 @@ (* *) -open Apply +open Prelude module List = struct @@ -11,6 +11,6 @@ struct (*List.fold_left (fun l elem -> match elem with | Some x -> x::l | None -> l) [] (List.rev lst)*) filter_map id lst - let find_option f l = try Some (find f l) with Not_found -> None + let find_option f = catch (find f) end (* List *) diff --git a/src/main.ml b/src/main.ml index eee74d9..45b0eff 100644 --- a/src/main.ml +++ b/src/main.ml @@ -3,10 +3,9 @@ *) open Printf -open Operators +open Prelude open ListMore -open ExtString -open Apply +open ExtLib module L = List module S = String diff --git a/src/operators.ml b/src/operators.ml deleted file mode 100644 index 6fa9608..0000000 --- a/src/operators.ml +++ /dev/null @@ -1,4 +0,0 @@ -(* $Id$ *) - -let (&) f g = function x -> f (g x) -let (>>) x f = f x diff --git a/src/apply.ml b/src/prelude.ml similarity index 69% rename from src/apply.ml rename to src/prelude.ml index c3715bf..f719247 100644 --- a/src/apply.ml +++ b/src/prelude.ml @@ -1,4 +1,7 @@ +let ($) f g = function x -> f (g x) +let (>>) x f = f x + external id : 'a -> 'a = "%identity" let catch f x = try Some (f x) with _ -> None let tee f x = f x; x diff --git a/src/rA.ml b/src/rA.ml index a1f010e..5a6b253 100644 --- a/src/rA.ml +++ b/src/rA.ml @@ -4,7 +4,7 @@ open ListMore open Printf -open Operators +open Prelude module Type = Sql.Type diff --git a/src/sql_parser.mly b/src/sql_parser.mly index 5fdd8c0..503a99d 100644 --- a/src/sql_parser.mly +++ b/src/sql_parser.mly @@ -10,7 +10,7 @@ open ListMore open Stmt open Syntax - open Operators + open Prelude let params_of select = List.map (fun x -> `Param x) (snd select) diff --git a/src/sqlgg.ml b/src/sqlgg.ml index d47b9ca..6cda7bd 100644 --- a/src/sqlgg.ml +++ b/src/sqlgg.ml @@ -1,7 +1,7 @@ (** command-line *) open Printf -open Operators +open Prelude open ExtLib module Cxx = Gen.Make(Gen_cxx) @@ -11,7 +11,7 @@ module Java = Gen.Make(Gen_java) module CSharp = Gen.Make(Gen_csharp) (* - special workaround for usecase: + common usecase: -gen none ddl.sql -gen cxx dml.sql *) let generate = ref (Some Cxx.process) diff --git a/src/syntax.ml b/src/syntax.ml index c5c6c13..1b7f3a0 100644 --- a/src/syntax.ml +++ b/src/syntax.ml @@ -1,9 +1,8 @@ (** SQL syntax and RA *) open Stmt -open Operators +open Prelude open ListMore -open Apply open Sql open Printf @@ -79,7 +78,7 @@ let resolve_types tables joined_schema expr = >> resolve_columns tables joined_schema >> tee (if Config.debug1 () then show_e else ignore) >> assign_types - >> tee (if Config.debug1 () then print_newline & show_e & fst else ignore) + >> tee (if Config.debug1 () then print_newline $ show_e $ fst else ignore) let infer_schema columns tables joined_schema = (* let all = tables >> List.map snd >> List.flatten in *) @@ -174,8 +173,8 @@ let cross = List.fold_left RA.Schema.cross [] (* all columns from tables, without duplicates *) (* FIXME check type of duplicates *) -let all_columns = RA.Schema.make_unique & cross -let all_tbl_columns = all_columns & List.map snd +let all_columns = RA.Schema.make_unique $ cross +let all_tbl_columns = all_columns $ List.map snd let split_column_assignments tables l = let cols = ref [] in -- 2.11.4.GIT