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
bc51af63
Commit
bc51af63
authored
Oct 02, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for exotic browser-specific syntax such as @-ms-viewport and filter(opacity=60)
parent
ef3a6884
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
4 deletions
+37
-4
lexer.mll
lexer.mll
+2
-0
parser.mly
parser.mly
+26
-4
stringify.ml
stringify.ml
+6
-0
types.ml
types.ml
+3
-0
No files found.
lexer.mll
View file @
bc51af63
...
...
@@ -106,6 +106,8 @@ rule token = parse
| '@' S U P P O R T S { SUPPORTS_SYM }
| '@' (('-' ident '-')? as prefix) K E Y F R A M E S
{ KEYFRAMES_SYM (String.lowercase prefix) }
| '@' (('-' ident '-')? as prefix) V I E W P O R T
{ VIEWPORT_SYM (String.lowercase prefix) }
| (s | comment)* s comment* A N D comment* s (s | comment)*
{ advance_pos lexbuf; WS_AND }
...
...
parser.mly
View file @
bc51af63
...
...
@@ -58,7 +58,8 @@
%
token
NAMESPACE_SYM
SUPPORTS_SYM
IMPORTANT_SYM
%
token
<
float
>
PERCENTAGE
NUMBER
%
token
<
float
*
string
>
UNIT_VALUE
%
token
<
string
>
KEYFRAMES_SYM
COMBINATOR
RELATION
STRING
IDENT
HASH
URI
FUNCTION
%
token
<
string
>
KEYFRAMES_SYM
VIEWPORT_SYM
COMBINATOR
RELATION
STRING
IDENT
HASH
%
token
<
string
>
URI
FUNCTION
%
token
LPAREN
RPAREN
LBRACE
RBRACE
LBRACK
RBRACK
SEMICOL
COLON
DOUBLE_COLON
%
token
COMMA
DOT
PLUS
MINUS
SLASH
STAR
ONLY
AND
(*OR*)
NOT
FROM
TO
EOF
%
token
WS_AND
WS_OR
...
...
@@ -90,7 +91,7 @@ stylesheet:
nested_statement
:
|
s
=
ruleset
|
s
=
media
|
s
=
page
|
s
=
font_face_rule
|
s
=
keyframes_rule
|
s
=
supports_rule
|
s
=
supports_rule
|
s
=
viewport_rule
{
s
}
group_rule_body
:
...
...
@@ -209,6 +210,10 @@ S*;
unused : block | ATKEYWORD S* | ';' S* | CDO S* | CDC S*;
*)
viewport_rule
:
|
pre
=
VIEWPORT_SYM
S
*
decls
=
decls_block
{
Viewport
(
pre
,
decls
)
}
%
inline
decls_block
:
|
LBRACE
S
*
hd
=
declaration
?
tl
=
wspreceded
(
SEMICOL
,
declaration
?
)
*
RBRACE
S
*
{
filter_none
(
hd
::
tl
)
}
...
...
@@ -285,13 +290,30 @@ term:
|
v
=
numval
S
*
{
v
}
|
str
=
STRING
S
*
{
Strlit
str
}
|
id
=
IDENT
S
*
{
Ident
(
String
.
lowercase
id
)
}
|
ONLY
S
*
{
Ident
"only"
}
|
NOT
S
*
{
Ident
"not"
}
|
AND
S
*
{
Ident
"and"
}
|
FROM
S
*
{
Ident
"from"
}
|
TO
S
*
{
Ident
"to"
}
|
uri
=
URI
S
*
{
Uri
uri
}
|
fn
=
FUNCTION
arg
=
expr
RPAREN
S
*
{
Function
(
String
.
lowercase
fn
,
arg
)
}
|
key
=
IDENT
S
*
COLON
S
*
value
=
term
{
Key_value
(
key
,
":"
,
value
)
}
|
key
=
IDENT
S
*
DOT
S
*
value
=
term
{
Key_value
(
key
,
"."
,
value
)
}
|
key
=
IDENT
S
*
rel
=
RELATION
S
*
value
=
term
{
if
rel
=
"="
then
Key_value
(
key
,
"="
,
value
)
else
raise
(
Syntax_error
(
"unexpected '"
^
rel
^
"'"
))
}
|
hex
=
HASH
S
*
{
let
h
=
"[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
in
{
let
h
=
"[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
in
if
Str
.
string_match
(
Str
.
regexp
(
"^"
^
h
^
"
\\
("
^
h
^
"
\\
)?$"
))
hex
0
then
Hexcolor
(
String
.
lowercase
hex
)
else
raise
(
Syntax_error
(
"invalid color #"
^
hex
))
}
else
raise
(
Syntax_error
(
"invalid color #"
^
hex
))
}
unary_operator
:
|
MINUS
{
"-"
}
|
PLUS
{
"+"
}
...
...
stringify.ml
View file @
bc51af63
...
...
@@ -34,6 +34,7 @@ let rec string_of_expr = function
|
Unary
(
op
,
opnd
)
->
op
^
string_of_expr
opnd
|
Nary
(
","
,
opnds
)
->
cat
", "
string_of_expr
opnds
|
Nary
(
op
,
opnds
)
->
cat
op
string_of_expr
opnds
|
Key_value
(
key
,
op
,
value
)
->
key
^
op
^
string_of_expr
value
let
string_of_declaration
(
name
,
value
,
important
)
=
let
imp
=
if
important
then
" !important"
else
""
in
...
...
@@ -141,6 +142,8 @@ let rec string_of_statement = function
|
Supports
(
condition
,
statements
)
->
"@supports "
^
string_of_condition
condition
^
block
(
cat
"
\n\n
"
string_of_statement
statements
)
|
Viewport
(
prefix
,
decls
)
->
"@"
^
prefix
^
"viewport"
^
block
(
cat
"
\n
"
string_of_declaration
decls
)
let
string_of_stylesheet
=
cat
"
\n\n
"
string_of_statement
...
...
@@ -168,6 +171,7 @@ let rec minify_expr = function
|
Nary
(
op
,
opnds
)
->
cat
op
minify_expr
opnds
|
Number
(
n
,
None
)
->
minify_num
n
|
Number
(
n
,
Some
u
)
->
minify_num
n
^
u
|
Key_value
(
key
,
op
,
value
)
->
key
^
op
^
minify_expr
value
|
expr
->
string_of_expr
expr
let
minify_declaration
(
name
,
value
,
important
)
=
...
...
@@ -219,6 +223,8 @@ let rec minify_statement = function
|
Supports
(
condition
,
statements
)
->
"@supports "
^
stringify_condition
""
condition
^
"{"
^
cat
""
minify_statement
statements
^
"}"
|
Viewport
(
prefix
,
decls
)
->
"@"
^
prefix
^
"viewport{"
^
cat
";"
minify_declaration
decls
^
"}"
|
statement
->
string_of_statement
statement
let
minify_stylesheet
=
cat
""
minify_statement
...
...
types.ml
View file @
bc51af63
...
...
@@ -8,6 +8,7 @@ type expr =
|
Hexcolor
of
string
|
Unary
of
string
*
expr
|
Nary
of
string
*
expr
list
|
Key_value
of
string
*
string
*
expr
type
declaration
=
string
*
expr
*
bool
...
...
@@ -63,6 +64,8 @@ type statement =
(* @[-<prefix>-]keyframes <id> { <rulesets> } *)
|
Supports
of
condition
*
statement
list
(* @supports <condition> { <rulesets> } *)
|
Viewport
of
string
*
declaration
list
(* @[-<prefix>-]viewport { <declarations> } *)
type
stylesheet
=
statement
list
...
...
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