Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mincss
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
mincss
Commits
20418d8e
Commit
20418d8e
authored
11 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Started implementing some color optimization
parent
e9ae0066
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+7
-7
7 additions, 7 deletions
Makefile
color.ml
+69
-0
69 additions, 0 deletions
color.ml
main.ml
+1
-0
1 addition, 0 deletions
main.ml
parser.mly
+8
-1
8 additions, 1 deletion
parser.mly
with
85 additions
and
8 deletions
Makefile
+
7
−
7
View file @
20418d8e
RESULT
:=
mincss
BASENAMES
:=
types util stringify parser lexer parse main
OFILES
:=
$(
addsuffix .cmx,
$(
BASENAMES
))
PRE_TGTS
:=
types
MODULES
:=
util stringify parser lexer parse color main
ALL_NAMES
:=
$(
PRE_TGTS
)
$(
MODULES
)
OCAMLCFLAGS
:=
-g
OCAMLLDFLAGS
:=
...
...
@@ -10,7 +11,7 @@ OCAMLLEX := ocamllex
OCAMLYACC
:=
menhir
--infer
--explain
--dump
.PHONY
:
all clean
.PRECIOUS
:
$(addprefix .cmi
,
$(
BASE
NAMES))
.PRECIOUS
:
$(addprefix .cmi
,
$(
ALL_
NAMES))
all
:
$(RESULT)
...
...
@@ -26,7 +27,7 @@ all: $(RESULT)
%.cmx
:
%.ml
ocamlfind ocamlopt
-package
batteries
-c
$(
OCAMLCFLAGS
)
-o
$@
$(
<:.cmi
=
.ml
)
$(RESULT)
:
$(
OFIL
ES)
$(RESULT)
:
$(
addsuffix .cmx
,
$(ALL_NAM
ES)
)
ocamlopt
-o
$@
$(
OCAMLLDFLAGS
)
$(
OCAMLLDLIBS
)
$^
# intra-module dependencies
...
...
@@ -34,9 +35,8 @@ lexer.cmi: lexer.ml
parser.cmx
:
parser.cmi lexer.cmi
parser.mli
:
parser.ml
parse.cmx
:
lexer.cmi parser.cmx
main.cmx
:
parse.cmx util.cmx
stringify.cmx parser.cmi parser.cmx lexer.cmx util.cmx parse.cmx main.cmx
:
\
types.cmi
main.cmx
:
parse.cmx util.cmx color.cmx
$(addsuffix .cmx,$(MODULES))
:
$(addsuffix .cmi
,
$(PRE_TGTS))
clean
:
rm
-f
*
.cmi
*
.cmx
*
.o lexer.ml parser.ml parser.mli parser.conflicts
\
...
...
This diff is collapsed.
Click to expand it.
color.ml
0 → 100644
+
69
−
0
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
This diff is collapsed.
Click to expand it.
main.ml
+
1
−
0
View file @
20418d8e
...
...
@@ -67,6 +67,7 @@ let handle_args args =
|
{
echo
=
true
}
->
write_output
(
Stringify
.
string_of_stylesheet
stylesheet
)
|
_
->
let
stylesheet
=
Color
.
compress
stylesheet
in
let
output
=
Stringify
.
minify_stylesheet
stylesheet
in
write_output
output
;
if
args
.
verbose
>=
2
then
begin
...
...
This diff is collapsed.
Click to expand it.
parser.mly
+
8
−
1
View file @
20418d8e
...
...
@@ -37,6 +37,13 @@
match
terms
|>
transform_ops
|>
flatten_nary
with
|
[
hd
]
->
hd
|
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 *)
...
...
@@ -260,7 +267,7 @@ expr:
|
COMMA
S
*
{
","
}
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
}
|
str
=
STRING
S
*
{
Strlit
str
}
|
id
=
IDENT
S
*
{
Ident
id
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment