Commit e9ae0066 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Moved some helper functions to utils

parent 0829ab94
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
......
......@@ -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
......
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 ^
......
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment