Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mincss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
mincss
Commits
20418d8e
Commit
20418d8e
authored
Jul 21, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started implementing some color optimization
parent
e9ae0066
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
8 deletions
+85
-8
Makefile
Makefile
+7
-7
color.ml
color.ml
+69
-0
main.ml
main.ml
+1
-0
parser.mly
parser.mly
+8
-1
No files found.
Makefile
View file @
20418d8e
RESULT
:=
mincss
RESULT
:=
mincss
BASENAMES
:=
types util stringify parser lexer parse main
PRE_TGTS
:=
types
OFILES
:=
$(
addsuffix
.cmx,
$(BASENAMES)
)
MODULES
:=
util stringify parser lexer parse color main
ALL_NAMES
:=
$(PRE_TGTS)
$(MODULES)
OCAMLCFLAGS
:=
-g
OCAMLCFLAGS
:=
-g
OCAMLLDFLAGS
:=
OCAMLLDFLAGS
:=
...
@@ -10,7 +11,7 @@ OCAMLLEX := ocamllex
...
@@ -10,7 +11,7 @@ OCAMLLEX := ocamllex
OCAMLYACC
:=
menhir
--infer
--explain
--dump
OCAMLYACC
:=
menhir
--infer
--explain
--dump
.PHONY
:
all clean
.PHONY
:
all clean
.PRECIOUS
:
$(addprefix .cmi
,
$(
BASE
NAMES))
.PRECIOUS
:
$(addprefix .cmi
,
$(
ALL_
NAMES))
all
:
$(RESULT)
all
:
$(RESULT)
...
@@ -26,7 +27,7 @@ all: $(RESULT)
...
@@ -26,7 +27,7 @@ all: $(RESULT)
%.cmx
:
%.ml
%.cmx
:
%.ml
ocamlfind ocamlopt
-package
batteries
-c
$(OCAMLCFLAGS)
-o
$@
$
(
<:.cmi
=
.ml
)
ocamlfind ocamlopt
-package
batteries
-c
$(OCAMLCFLAGS)
-o
$@
$
(
<:.cmi
=
.ml
)
$(RESULT)
:
$(
OFILES
)
$(RESULT)
:
$(
addsuffix .cmx
,
$(ALL_NAMES)
)
ocamlopt
-o
$@
$(OCAMLLDFLAGS)
$(OCAMLLDLIBS)
$^
ocamlopt
-o
$@
$(OCAMLLDFLAGS)
$(OCAMLLDLIBS)
$^
# intra-module dependencies
# intra-module dependencies
...
@@ -34,9 +35,8 @@ lexer.cmi: lexer.ml
...
@@ -34,9 +35,8 @@ lexer.cmi: lexer.ml
parser.cmx
:
parser.cmi lexer.cmi
parser.cmx
:
parser.cmi lexer.cmi
parser.mli
:
parser.ml
parser.mli
:
parser.ml
parse.cmx
:
lexer.cmi parser.cmx
parse.cmx
:
lexer.cmi parser.cmx
main.cmx
:
parse.cmx util.cmx
main.cmx
:
parse.cmx util.cmx color.cmx
stringify.cmx parser.cmi parser.cmx lexer.cmx util.cmx parse.cmx main.cmx
:
\
$(addsuffix .cmx,$(MODULES))
:
$(addsuffix .cmi
,
$(PRE_TGTS))
types.cmi
clean
:
clean
:
rm
-f
*
.cmi
*
.cmx
*
.o lexer.ml parser.ml parser.mli parser.conflicts
\
rm
-f
*
.cmi
*
.cmx
*
.o lexer.ml parser.ml parser.mli parser.conflicts
\
...
...
color.ml
0 → 100644
View file @
20418d8e
open
Types
let
hex6
=
Str
.
regexp
"
\\
([0-9a-f]
\\
)
\\
1
\\
([0-9a-f]
\\
)
\\
2
\\
([0-9a-f]
\\
)
\\
3"
let
is_num
=
function
|
Number
(
n
,
(
None
|
Some
"%"
))
->
true
|
_
->
false
let
clip
=
function
|
Number
(
n
,
(
None
|
Some
"%"
))
when
n
<
0
.
->
Number
(
0
.,
Some
"%"
)
|
Number
(
n
,
None
)
when
n
>
255
.
->
Number
(
255
.,
None
)
|
Number
(
n
,
Some
"%"
)
when
n
>
100
.
->
Number
(
100
.,
Some
"%"
)
|
value
->
value
let
rec
short
=
function
|
Ident
"aqua"
->
Hexcolor
"0ff"
|
Ident
"black"
->
Hexcolor
"000"
|
Ident
"blue"
->
Hexcolor
"00f"
|
Ident
"fuchsia"
->
Hexcolor
"f0f"
|
Ident
"lime"
->
Hexcolor
"0f0"
|
Ident
"white"
->
Hexcolor
"fff"
|
Ident
"yellow"
->
Hexcolor
"ff0"
|
Hexcolor
"808080"
->
Ident
"gray"
|
Hexcolor
"008000"
->
Ident
"green"
|
Hexcolor
"800000"
->
Ident
"maroon"
|
Hexcolor
"000080"
->
Ident
"navy"
|
Hexcolor
"8080000"
->
Ident
"olive"
|
Hexcolor
"800080"
->
Ident
"purple"
|
Hexcolor
"ff0000"
|
Hexcolor
"f00"
->
Ident
"red"
|
Hexcolor
"c0c0c0"
->
Ident
"silver"
|
Hexcolor
"008080"
->
Ident
"teal"
(* #aabbcc -> #abc *)
|
Hexcolor
h
when
Str
.
string_match
hex6
h
0
->
let
gr
n
=
Str
.
matched_group
n
h
in
Hexcolor
(
gr
1
^
gr
2
^
gr
3
)
(* rgb(r,g,b) -> #rrggbb *)
|
Function
(
"rgb"
,
Nary
(
","
,
[
r
;
g
;
b
]))
when
is_num
r
&
is_num
g
&
is_num
b
->
let
i
c
=
match
clip
c
with
|
Number
(
n
,
None
)
->
int_of_float
n
|
Number
(
n
,
Some
"%"
)
->
int_of_float
(
n
*.
2
.
55
+.
0
.
5
)
|
_
->
assert
false
in
short
(
Hexcolor
(
Printf
.
sprintf
"%02x%02x%02x"
(
i
r
)
(
i
g
)
(
i
b
)))
(* clip rgb values, e.g. rgb(-1,256,0) -> rgb(0,255,0) *)
|
Function
(
"rgb"
,
Nary
(
","
,
[
r
;
g
;
b
]))
->
Function
(
"rgb"
,
Nary
(
","
,
[
clip
r
;
clip
g
;
clip
b
]))
|
c
->
c
let
rec
compress_props
=
function
|
[]
->
[]
|
(
"color"
,
c
,
i
)
::
tl
->
(
"color"
,
short
c
,
i
)
::
compress_props
tl
|
hd
::
tl
->
hd
::
compress_props
tl
let
rec
compress
=
function
|
[]
->
[]
|
Ruleset
(
selectors
,
properties
)
::
tl
->
Ruleset
(
selectors
,
compress_props
properties
)
::
compress
tl
|
hd
::
tl
->
hd
::
compress
tl
main.ml
View file @
20418d8e
...
@@ -67,6 +67,7 @@ let handle_args args =
...
@@ -67,6 +67,7 @@ let handle_args args =
|
{
echo
=
true
}
->
|
{
echo
=
true
}
->
write_output
(
Stringify
.
string_of_stylesheet
stylesheet
)
write_output
(
Stringify
.
string_of_stylesheet
stylesheet
)
|
_
->
|
_
->
let
stylesheet
=
Color
.
compress
stylesheet
in
let
output
=
Stringify
.
minify_stylesheet
stylesheet
in
let
output
=
Stringify
.
minify_stylesheet
stylesheet
in
write_output
output
;
write_output
output
;
if
args
.
verbose
>=
2
then
begin
if
args
.
verbose
>=
2
then
begin
...
...
parser.mly
View file @
20418d8e
...
@@ -37,6 +37,13 @@
...
@@ -37,6 +37,13 @@
match
terms
|>
transform_ops
|>
flatten_nary
with
match
terms
|>
transform_ops
|>
flatten_nary
with
|
[
hd
]
->
hd
|
[
hd
]
->
hd
|
l
->
Concat
l
|
l
->
Concat
l
(* TODO: move this to a normalization stage, because the syntax should be
* preserved during parsing (e.g. for -echo command) *)
let
unary_number
=
function
|
Unary
(
"-"
,
Number
(
n
,
u
))
->
Number
(
-.
n
,
u
)
|
Unary
(
"+"
,
(
Number
_
as
n
))
->
n
|
value
->
value
%
}
%
}
(* Tokens *)
(* Tokens *)
...
@@ -260,7 +267,7 @@ expr:
...
@@ -260,7 +267,7 @@ expr:
|
COMMA
S
*
{
","
}
|
COMMA
S
*
{
","
}
term
:
term
:
|
op
=
unary_operator
v
=
numval
S
*
{
Unary
(
op
,
v
)
}
|
op
=
unary_operator
v
=
numval
S
*
{
unary_number
(
Unary
(
op
,
v
)
)
}
|
v
=
numval
S
*
{
v
}
|
v
=
numval
S
*
{
v
}
|
str
=
STRING
S
*
{
Strlit
str
}
|
str
=
STRING
S
*
{
Strlit
str
}
|
id
=
IDENT
S
*
{
Ident
id
}
|
id
=
IDENT
S
*
{
Ident
id
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment