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
3b7dc074
Commit
3b7dc074
authored
10 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Extended 'Simple' selector type to algebraic data types
parent
34391515
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Makefile
+2
-1
2 additions, 1 deletion
Makefile
parser.mly
+33
-16
33 additions, 16 deletions
parser.mly
stringify.ml
+23
-8
23 additions, 8 deletions
stringify.ml
types.ml
+12
-0
12 additions, 0 deletions
types.ml
util.ml
+18
-4
18 additions, 4 deletions
util.ml
with
88 additions
and
29 deletions
Makefile
+
2
−
1
View file @
3b7dc074
RESULT
:=
mincss
PRE_TGTS
:=
types
MODULES
:=
color_names util stringify parser lexer parse color shorthand main
MODULES
:=
color_names util stringify parser lexer parse color
\
shorthand main
ALL_NAMES
:=
$(
PRE_TGTS
)
$(
MODULES
)
OCAMLCFLAGS
:=
-g
...
...
This diff is collapsed.
Click to expand it.
parser.mly
+
33
−
16
View file @
3b7dc074
...
...
@@ -37,6 +37,18 @@
|
Unary
(
"-"
,
Number
(
n
,
u
))
->
Number
(
-.
n
,
u
)
|
Unary
(
"+"
,
(
Number
_
as
n
))
->
n
|
value
->
value
let
rec
append_addons
base
=
function
|
[]
->
base
|
`Id
id
::
tl
->
append_addons
(
Id
(
base
,
id
))
tl
|
`Class
cls
::
tl
->
append_addons
(
Class
(
base
,
cls
))
tl
|
`Attribute
(
attr
,
value
)
::
tl
->
append_addons
(
Attribute
(
base
,
attr
,
value
))
tl
|
`Pseudo
(
f
,
args
)
::
tl
->
append_addons
(
Pseudo
(
base
,
f
,
args
))
tl
%
}
(* Tokens *)
...
...
@@ -207,39 +219,44 @@ ruleset:
selector
:
|
simple
=
simple_selector
S
*
{
Simple
simple
}
{
simple
}
|
left
=
simple_selector
S
+
right
=
selector
{
Combinator
(
Simple
left
,
" "
,
right
)
}
{
Combinator
(
left
,
" "
,
right
)
}
|
left
=
simple_selector
S
*
com
=
combinator
right
=
selector
{
Combinator
(
Simple
left
,
com
,
right
)
}
{
Combinator
(
left
,
com
,
right
)
}
%
inline
combinator
:
|
PLUS
S
*
{
"+"
}
|
c
=
COMBINATOR
S
*
{
c
}
simple_selector
:
|
elem
=
element_name
addons
=
element_addon
*
{
elem
^
String
.
concat
""
addons
}
{
append_addons
elem
addons
}
|
addons
=
element_addon
+
{
String
.
concat
""
addons
}
%
inline
element_addon
:
a
=
HASH
|
a
=
cls
|
a
=
attrib
|
a
=
pseudo
{
a
}
{
append_addons
No_element
addons
}
%
inline
element_addon
:
|
id
=
HASH
{
`Id
id
}
|
addon
=
cls
|
addon
=
attrib
|
addon
=
pseudo
{
addon
}
element_name
:
|
tag
=
IDENT
{
String
.
lowercase
tag
}
|
STAR
{
"*"
}
|
tag
=
IDENT
{
Element
(
String
.
lowercase
tag
)
}
|
STAR
{
All_elements
}
cls
:
|
DOT
name
=
IDENT
{
"."
^
name
}
{
`Class
name
}
attrib
:
|
LBRACK
S
*
left
=
IDENT
S
*
right
=
pair
(
RELATION
,
rel_value
)
?
RBRACK
{
let
right
=
match
right
with
None
->
""
|
Some
(
op
,
term
)
->
op
^
term
in
"["
^
String
.
lowercase
left
^
right
^
"]"
}
|
LBRACK
S
*
left
=
IDENT
S
*
RBRACK
{
`Attribute
(
String
.
lowercase
left
,
None
)
}
|
LBRACK
S
*
left
=
IDENT
S
*
op
=
RELATION
right
=
rel_value
RBRACK
{
`Attribute
(
String
.
lowercase
left
,
Some
(
op
,
right
))
}
%
inline
rel_value
:
|
S
*
id
=
IDENT
S
*
{
id
}
|
S
*
s
=
STRING
S
*
{
"
\"
"
^
s
^
"
\"
"
}
|
S
*
id
=
IDENT
S
*
{
Ident
id
}
|
S
*
s
=
STRING
S
*
{
Strlit
s
}
pseudo
:
|
COLON
id
=
IDENT
{
":"
^
(
String
.
lowercase
id
)
}
{
`Pseudo
(
String
.
lowercase
id
,
None
)
}
|
COLON
f
=
FUNCTION
args
=
wslist
(
COMMA
,
simple_selector
)
RPAREN
{
":"
^
String
.
lowercase
f
^
"("
^
String
.
concat
","
args
^
")"
}
{
`Pseudo
(
String
.
lowercase
f
,
Some
args
)
}
declaration
:
|
name
=
property
S
*
COLON
S
*
value
=
expr
important
=
boption
(
ig2
(
IMPORTANT_SYM
,
S
*
))
...
...
This diff is collapsed.
Click to expand it.
stringify.ml
+
23
−
8
View file @
3b7dc074
...
...
@@ -39,12 +39,30 @@ let string_of_declaration (name, value, important) =
let
imp
=
if
important
then
" !important"
else
""
in
name
^
": "
^
string_of_expr
value
^
imp
^
";"
let
rec
string_of_selector
=
function
|
Simple
simple
->
simple
let
rec
stringify_selector
w
selector
=
let
str
=
stringify_selector
w
in
match
selector
with
|
No_element
->
""
|
All_elements
->
"*"
|
Element
elem
->
elem
|
Id
(
base
,
id
)
->
str
base
^
"#"
^
id
|
Class
(
base
,
cls
)
->
str
base
^
"."
^
cls
|
Attribute
(
base
,
attr
,
None
)
->
str
base
^
"["
^
attr
^
"]"
|
Attribute
(
base
,
attr
,
Some
(
op
,
value
))
->
str
base
^
"["
^
attr
^
w
^
op
^
w
^
string_of_expr
value
^
"]"
|
Pseudo
(
base
,
sel
,
None
)
->
str
base
^
":"
^
sel
|
Pseudo
(
base
,
fn
,
Some
args
)
->
str
base
^
":"
^
fn
^
"("
^
cat
(
","
^
w
)
str
args
^
")"
|
Combinator
(
left
,
" "
,
right
)
->
str
ing_of_selector
left
^
" "
^
str
ing_of_selector
right
str
left
^
" "
^
str
right
|
Combinator
(
left
,
com
,
right
)
->
string_of_selector
left
^
" "
^
com
^
" "
^
string_of_selector
right
str
left
^
w
^
com
^
w
^
str
right
let
string_of_selector
=
stringify_selector
" "
let
string_of_media_expr
=
function
|
(
feature
,
None
)
->
"("
^
feature
^
")"
...
...
@@ -140,10 +158,7 @@ let minify_declaration (name, value, important) =
let
imp
=
if
important
then
"!important"
else
""
in
name
^
":"
^
minify_expr
value
^
imp
let
rec
minify_selector
=
function
|
Simple
simple
->
simple
|
Combinator
(
left
,
com
,
right
)
->
minify_selector
left
^
com
^
minify_selector
right
let
rec
minify_selector
=
stringify_selector
""
let
minify_media_feature
=
function
|
(
feature
,
None
)
->
"("
^
feature
^
")"
...
...
This diff is collapsed.
Click to expand it.
types.ml
+
12
−
0
View file @
3b7dc074
...
...
@@ -11,9 +11,21 @@ type expr =
type
declaration
=
string
*
expr
*
bool
type
selector
=
|
No_element
|
All_elements
|
Element
of
string
|
Id
of
selector
*
string
|
Class
of
selector
*
string
|
Pseudo
of
selector
*
string
*
selector
list
option
|
Attribute
of
selector
*
string
*
(
string
*
expr
)
option
|
Combinator
of
selector
*
string
*
selector
(*
type selector =
| Simple of string
| Combinator of selector * string * selector
*)
type
media_expr
=
string
*
expr
option
type
media_query
=
string
option
*
string
option
*
media_expr
list
...
...
This diff is collapsed.
Click to expand it.
util.ml
+
18
−
4
View file @
3b7dc074
...
...
@@ -132,12 +132,26 @@ let transform_stylesheet f stylesheet =
in
let
TRAV_ALL
(
declaration
,
Declaration
)
in
let
trav_selector
=
function
|
Simple
_
as
s
->
f
(
Selector
s
)
let
rec
trav_selector
=
function
|
(
No_element
|
All_elements
|
Element
_
)
as
elem
->
f
(
Selector
elem
)
|
Id
(
base
,
id
)
->
f
(
Selector
(
Id
(
expect_selector
base
,
id
)))
|
Class
(
base
,
cls
)
->
f
(
Selector
(
Class
(
expect_selector
base
,
cls
)))
|
Attribute
(
base
,
attr
,
value
)
->
f
(
Selector
(
Attribute
(
expect_selector
base
,
attr
,
value
)))
|
Pseudo
(
base
,
sel
,
None
)
->
f
(
Selector
(
Pseudo
(
expect_selector
base
,
sel
,
None
)))
|
Pseudo
(
base
,
fn
,
Some
args
)
->
let
args
=
trav_all_selector
args
in
f
(
Selector
(
Pseudo
(
expect_selector
base
,
fn
,
Some
args
)))
|
Combinator
(
left
,
com
,
right
)
->
let
left
=
expect_selector
left
in
let
right
=
expect_selector
right
in
f
(
Selector
(
Combinator
(
left
,
com
,
right
)))
in
let
TRAV_ALL
(
selector
,
Selector
)
in
and
EXPECT
(
selector
,
Selector
)
and
TRAV_ALL
(
selector
,
Selector
)
in
let
trav_media_expr
=
function
|
(
_
,
None
)
as
value
->
...
...
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