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

Implemented duplicate declaration pruning

parent 944d6cff
RESULT := mincss
PRE_TGTS := types
MODULES := color_names util stringify parser lexer parse selector color \
shorthand main
shorthand duplicates main
ALL_NAMES := $(PRE_TGTS) $(MODULES)
OCAMLCFLAGS := -g
......@@ -36,7 +36,7 @@ lexer.cmi: lexer.ml
parser.cmx: parser.cmi lexer.cmx
parser.mli: parser.ml
parse.cmx: lexer.cmi parser.cmx
main.cmx: parse.cmx util.cmx color.cmx shorthand.cmx
main.cmx: parse.cmx util.cmx color.cmx shorthand.cmx duplicates.cmx
util.cmx: OCAMLCFLAGS += -pp cpp
util.cmx color.cmx: color_names.cmx
stringify.cmx parser.cmx color.cmx shorthand.cmx: util.cmi
......
open Types
module SM = Map.Make(String)
let prune_duplicates decls =
let keep = Array.make (List.length decls) true in
let rec tag db index = function
| (name, _, imp) :: tl when SM.mem name db ->
(* previous value exists, one needs to be removed *)
let prev_index, prev_imp = SM.find name db in
if not imp && prev_imp then begin
keep.(index) <- false;
tag db (index + 1) tl
end else begin
keep.(prev_index) <- false;
tag (SM.add name (index, imp) db) (index + 1) tl
end
| (name, _, imp) :: tl ->
tag (SM.add name (index, imp) db) (index + 1) tl
| [] -> ()
in
tag SM.empty 0 decls;
let rec prune i = function
| [] -> []
| hd :: tl when keep.(i) -> hd :: prune (i + 1) tl
| _ :: tl -> prune (i + 1) tl
in
prune 0 decls
let transform = function
| Statement (Ruleset (selectors, decls)) ->
Statement (Ruleset (selectors, prune_duplicates decls))
| v -> v
let compress = Util.transform_stylesheet transform
......@@ -136,7 +136,7 @@ let handle_args args =
(* unfold before pruning duplicates so that shorthand components are
* correctly pruned *)
|> switch args.shorthands Shorthand.unfold_stylesheet
(*|> switch args.duplicates Duplicates.compress*)
|> switch args.duplicates Duplicates.compress
|> switch args.shorthands Shorthand.compress
in
let output =
......
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