diff --git a/Makefile b/Makefile index 3bfdd39ce7867fb4825fa02bda86851e068b00cf..576eb2312fa725e9995bf102f1b377366305caec 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 f9845388765bb4c59d0add89a7d2e0d3fdac8985..5f5b51b96a6c03dc25586c8313ec349f3360351b 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 b165a599d2237c18ed410931106b29cca502169d..89e2473adc1f5148b9659dc5851b9e8ae40ebc3b 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 6453b5d236ccb899261757721ae3d307269c0a32..fbe35eff007fb38a2b6b7d62a9c314cd3ecb3643 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