From e9ae0066f55bef7450498a94893b1c96adccfd03 Mon Sep 17 00:00:00 2001
From: Taddeus Kroes <taddeuskroes@gmail.com>
Date: Mon, 21 Jul 2014 15:29:11 +0200
Subject: [PATCH] Moved some helper functions to utils

---
 Makefile     |  3 +--
 parser.mly   |  9 +--------
 stringify.ml | 20 +-------------------
 util.ml      | 22 +++++++++++++++-------
 4 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/Makefile b/Makefile
index 3bfdd39..576eb23 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 RESULT    := mincss
-BASENAMES := types stringify parser lexer util parse main
+BASENAMES := types util stringify parser lexer parse main
 OFILES    := $(addsuffix .cmx,$(BASENAMES))
 
 OCAMLCFLAGS  := -g
@@ -34,7 +34,6 @@ lexer.cmi: lexer.ml
 parser.cmx: parser.cmi lexer.cmi
 parser.mli: parser.ml
 parse.cmx: lexer.cmi parser.cmx
-util.cmx: stringify.cmx
 main.cmx: parse.cmx util.cmx
 stringify.cmx parser.cmi parser.cmx lexer.cmx util.cmx parse.cmx main.cmx: \
 	types.cmi
diff --git a/parser.mly b/parser.mly
index f984538..5f5b51b 100644
--- a/parser.mly
+++ b/parser.mly
@@ -9,14 +9,7 @@
    *)
   open Lexing
   open Types
-
-  (* TODO: move this to utils *)
-  let ( |> ) a b = b a
-
-  let rec filter_none = function
-    | [] -> []
-    | None :: tl -> filter_none tl
-    | Some hd :: tl -> hd :: filter_none tl
+  open Util
 
   type term_t = Term of expr | Operator of string
 
diff --git a/stringify.ml b/stringify.ml
index b165a59..89e2473 100644
--- a/stringify.ml
+++ b/stringify.ml
@@ -1,4 +1,5 @@
 open Types
+open Util
 
 let tab = "    "
 
@@ -16,19 +17,6 @@ let string_of_num n =
     then string_of_int (int_of_float n)
     else string_of_float n
 
-(* TODO: move this to utils *)
-let (@@) f g x = f (g x)
-
-let rec filter_none = function
-  | [] -> []
-  | None :: tl -> filter_none tl
-  | Some hd :: tl -> hd :: filter_none tl
-
-let add_parens s =
-  let l = String.length s in
-  if l > 0 & s.[0] = '(' & s.[l - 1] = ')'
-    then s else "(" ^ s ^ ")"
-
 (*
  * Pretty-printing
  *)
@@ -167,12 +155,6 @@ let minify_media_query query =
     pre ^ " " ^ mtype ^ " and " ^ features_str features
   | _ -> string_of_media_query query
 
-let rec minify_condition = function
-  | Not c -> "not " ^ add_parens (minify_condition c)
-  | And c -> cat " and " (add_parens @@ minify_condition) c
-  | Or c -> cat " or " (add_parens @@ minify_condition) c
-  | Decl (name, value) -> "(" ^ name ^ ":" ^ minify_expr value ^ ")"
-
 let rec minify_statement = function
   | Ruleset (selectors, decls) ->
     cat "," minify_selector selectors ^
diff --git a/util.ml b/util.ml
index 6453b5d..fbe35ef 100644
--- a/util.ml
+++ b/util.ml
@@ -1,7 +1,19 @@
 open Printf
-open Str
 open Types
 
+(** Operators *)
+
+let (|>) a b = b a
+
+(** List utilities *)
+
+let rec filter_none = function
+  | [] -> []
+  | None :: tl -> filter_none tl
+  | Some hd :: tl -> hd :: filter_none tl
+
+(** Reading input from file/stdin *)
+
 let input_all ic =
   let n = in_channel_length ic in
   let buf = String.create n in
@@ -22,11 +34,7 @@ let input_buffered ic chunksize =
   in
   read_all (String.create chunksize) chunksize 0
 
-let output_css oc decls =
-  output_string oc (Stringify.string_of_stylesheet decls);
-  output_char oc '\n'
-
-let print_css = output_css stdout
+(** Error printing *)
 
 let noloc = ("", 0, 0, 0, 0)
 
@@ -41,7 +49,7 @@ let count_tabs str upto =
 
 let rec repeat s n = if n < 1 then "" else s ^ (repeat s (n - 1))
 
-let retab str = global_replace (regexp "\t") (repeat " " tabwidth) str
+let retab str = Str.global_replace (Str.regexp "\t") (repeat " " tabwidth) str
 
 let indent n = repeat (repeat " " (tabwidth - 1)) n
 
-- 
GitLab