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
e31ac97a
Commit
e31ac97a
authored
10 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Fixes in token case-sensitivity, hex color parsing and stringification
parent
7c7dcabd
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
-0
2 additions, 0 deletions
Makefile
lexer.mll
+17
-17
17 additions, 17 deletions
lexer.mll
parser.mly
+19
-23
19 additions, 23 deletions
parser.mly
stringify.ml
+59
-5
59 additions, 5 deletions
stringify.ml
types.ml
+5
-3
5 additions, 3 deletions
types.ml
with
102 additions
and
48 deletions
Makefile
+
2
−
0
View file @
e31ac97a
...
...
@@ -35,6 +35,8 @@ parser.mli: parser.ml
parse.cmx
:
lexer.cmi parser.cmx
util.cmx
:
stringify.cmx
main.cmx
:
parse.cmx util.cmx
stringify.cmx parser.cmi parser.cmx lexer.cmx util.cmx parse.cmx main.cmx
:
\
types.cmi
clean
:
rm
-f
*
.cmi
*
.cmx
*
.o lexer.ml parser.ml parser.mli parser.conflicts
\
...
...
This diff is collapsed.
Click to expand it.
lexer.mll
+
17
−
17
View file @
e31ac97a
...
...
@@ -15,30 +15,30 @@
let
strip_quotes
s
=
String
.
sub
s
1
(
String
.
length
s
-
2
)
}
let
h
=
[
'
0
'
-
'
9
''
a'
-
'
f'
]
let
wc
=
'\r''\n'
|
[
'
'
'\t''\r''\n''\012'
]
let
h
=
[
'
0
'
-
'
9
'
'
a'
-
'
f'
'
A'
-
'
F'
]
let
wc
=
'\r'
'\n'
|
[
'
'
'\t'
'\r'
'\n'
'\012'
]
let
nonascii
=
[
'\160'
-
'\255'
]
let
s
=
[
'
'
'\t''\r''\n''\012'
]
+
let
s
=
[
'
'
'\t'
'\r'
'\n'
'\012'
]
+
let
w
=
s
?
let
nl
=
'\n'
|
'\r''\n'
|
'\r'
|
'\012'
let
nl
=
'\n'
|
'\r'
'\n'
|
'\r'
|
'\012'
let
unicode
=
'\\'
h
(
h
(
h
(
h
(
h
(
h
)
?
)
?
)
?
)
?
)
?
wc
?
let
escape
=
unicode
|
'\\'
[
^
'\r''\n''\012'
'
0
'
-
'
9
''
a'
-
'
f'
]
let
nmstart
=
[
'
_''a'
-
'
z'
]
|
nonascii
|
escape
let
nmchar
=
[
'
_''a'
-
'
z''0'
-
'
9
''
-
'
]
|
nonascii
|
escape
let
string1
=
'
"'([^'
\n
''
\r
''
\012
''"
'
]
|
'\\'
nl
|
escape
)
*
'
"'
let string2 = '
\'
'([^'
\n
''
\r
''
\012
''
\'
'] | '
\\
'nl | escape)*'
\'
'
let
escape
=
unicode
|
'\\'
[
^
'\r'
'\n'
'\012'
'
0
'
-
'
9
'
'
a'
-
'
f'
'
A'
-
'
F'
]
let
nmstart
=
[
'
_'
'
a'
-
'
z'
'
A'
-
'
Z'
]
|
nonascii
|
escape
let
nmchar
=
[
'
_'
'
a'
-
'
z'
'
A'
-
'
Z'
'
0
'
-
'
9
'
'
-
'
]
|
nonascii
|
escape
let
string1
=
'
"'([^'
\n
'
'
\r
'
'
\012
'
'"
'
]
|
'\\'
nl
|
escape
)
*
'
"'
let string2 = '
\'
'
([^'
\n
'
'
\r
'
'
\012
'
'
\'
'] | '
\\
'
nl | escape)*
'
\'
'
let mystring = string1 | string2
let badstring1 = '"
'
([
^
'\n''\r''\012'
'
"'] | '
\\
'nl | escape)*'
\\
'?
let badstring2 = '
\'
'([^'
\n
''
\r
''
\012
''
\'
'] | '
\\
'nl | escape)*'
\\
'?
let badstring1 = '"
'
([
^
'\n'
'\r'
'\012'
'
"'] | '
\\
'nl | escape)*
'
\\
'?
let badstring2 = '
\'
'
([^'
\n
'
'
\r
'
'
\012
'
'
\'
'] | '
\\
'nl | escape)*
'
\\
'?
let badstring = badstring1 | badstring2
let badcomment1 = '/''*'[^'*']*'*'+([^'/''*'][^'*']*'*'+)*
let badcomment2 = '/''*'[^'*']*('*'+[^'/''*'][^'*']*)*
let badcomment1 = '/'
'*'[^'*']*'*'+([^'/'
'*'][^'*']*'*'+)*
let badcomment2 = '/'
'*'[^'*']*('*'+[^'/'
'*'][^'*']*)*
let badcomment = badcomment1 | badcomment2
let baduri1 = "
url
(
"
w
(['!''#''$''%''&''*'-'['']'-'~'] | nonascii | escape)*w
let baduri2 = "
url
(
"w mystring w
let baduri3 = "
url
(
"w badstring
let baduri1 = "
url
(
"
w
(['!'
'#'
'$'
'%'
'&'
'*'-'['
']'-'~'] | nonascii | escape)*
w
let baduri2 = "
url
(
"
w mystring w
let baduri3 = "
url
(
"
w badstring
let baduri = baduri1 | baduri2 | baduri3
let comment =
'/''*'
[^'*']*'*'+([^'/''*'][^'*']*'*'+)
'*''/'
let comment =
"
/*
"
[^'*']*
'*'+
([^'/'
'*']
[^'*']*
'*'+)
"
*/
"
let ident = '-'? nmstart nmchar*
let name = nmchar+
let num = ['0'-'9']+ | ['0'-'9']*'.'['0'-'9']+
...
...
This diff is collapsed.
Click to expand it.
parser.mly
+
19
−
23
View file @
e31ac97a
...
...
@@ -26,7 +26,7 @@
let
rec
transform_ops
=
function
|
[]
->
[]
|
Term
left
::
Operator
op
::
Term
right
::
tl
->
Nary
(
op
,
[
left
;
right
])
::
t
ransform_ops
t
l
transform_ops
(
Term
(
Nary
(
op
,
[
left
;
right
])
)
::
tl
)
|
Term
hd
::
tl
->
hd
::
transform_ops
tl
|
Operator
op
::
_
->
raise
(
SyntaxError
(
"unexpected operator
\"
"
^
op
^
"
\"
"
))
in
...
...
@@ -36,13 +36,7 @@
Nary
(
op
,
flatten_nary
left
@
flatten_nary
right
)
::
flatten_nary
tl
|
hd
::
tl
->
hd
::
flatten_nary
tl
in
let
comma_to_concat
=
List
.
map
(
transform_value
(
function
|
Nary
(
","
,
terms
)
->
Concat
terms
|
value
->
value
))
in
match
terms
|>
transform_ops
|>
flatten_nary
|>
comma_to_concat
with
match
terms
|>
transform_ops
|>
flatten_nary
with
|
[
hd
]
->
hd
|
l
->
Concat
l
%
}
...
...
@@ -79,15 +73,15 @@ stylesheet:
{
s
}
charset
:
|
CHARSET_SYM
name
=
STRING
SEMICOL
|
CHARSET_SYM
S
?
name
=
STRING
S
?
SEMICOL
{
Charset
name
}
%
inline
string_or_uri
:
|
s
=
STRING
|
s
=
URI
{
s
}
import
:
|
IMPORT_SYM
S
?
tgt
=
string_or_uri
media
=
wslist
(
COMMA
,
IDENT
)
SEMICOL
S
?
{
Import
(
tgt
,
media
)
}
%
inline
string_or_uri
:
|
str
=
STRING
{
Strlit
str
}
|
uri
=
URI
{
Uri
uri
}
media
:
|
MEDIA_SYM
queries
=
wslist
(
COMMA
,
IDENT
)
LBRACE
S
?
rulesets
=
ruleset
*
RBRACE
S
?
...
...
@@ -112,12 +106,12 @@ ruleset:
{
Ruleset
(
selectors_hd
::
selectors_tl
,
decls
)
}
selector
:
|
hd
=
simple_selector
S
?
{
[
hd
]
}
|
hd
=
simple_selector
S
t
l
=
selector
{
hd
::
tl
}
|
hd
=
simple_selector
S
?
c
=
combinator
t
l
=
selector
{
hd
::
c
::
tl
}
|
simple
=
simple_selector
S
?
{
Simple
simple
}
|
left
=
simple_selector
S
righ
t
=
selector
{
Combinator
(
Simple
left
,
" "
,
right
)
}
|
left
=
simple_selector
S
?
c
om
=
combinator
righ
t
=
selector
{
Combinator
(
Simple
left
,
com
,
right
)
}
%
inline
combinator
:
|
PLUS
S
?
{
"+"
}
|
c
=
COMBINATOR
S
?
{
c
}
...
...
@@ -145,7 +139,7 @@ attrib:
"["
^
left
^
right
^
"]"
}
%
inline
rel_value
:
|
S
?
id
=
IDENT
S
?
{
id
}
|
S
?
s
=
STRING
S
?
{
s
}
|
S
?
s
=
STRING
S
?
{
"
\"
"
^
s
^
"
\"
"
}
pseudo
:
|
COLON
id
=
IDENT
...
...
@@ -156,7 +150,7 @@ pseudo:
declaration
:
|
name
=
IDENT
S
?
COLON
S
?
value
=
expr
important
=
boption
(
pair
(
IMPORTANT_SYM
,
S
?
))
{
(
name
,
value
,
important
)
}
{
(
String
.
lowercase
name
,
value
,
important
)
}
expr
:
|
l
=
exprl
{
concat_terms
l
}
...
...
@@ -187,9 +181,11 @@ term:
|
fn
=
FUNCTION
arg
=
expr
RPAREN
S
?
{
Function
(
fn
,
arg
)
}
|
hex
=
HASH
S
?
{
if
Str
.
string_match
(
Str
.
regexp
"
\\
d{3}
\\
d{3}?"
)
hex
0
then
Hexcolor
hex
{
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
(
SyntaxError
(
"invalid color #"
^
hex
))
}
%
inline
unary_operator
:
unary_operator
:
|
MINUS
{
"-"
}
|
PLUS
{
"+"
}
This diff is collapsed.
Click to expand it.
stringify.ml
+
59
−
5
View file @
e31ac97a
...
...
@@ -14,6 +14,10 @@ let string_of_num n =
then
string_of_int
(
int_of_float
n
)
else
string_of_float
n
(*
* Pretty-printing
*)
let
rec
string_of_expr
=
function
|
Ident
id
->
id
|
Strlit
str
->
"
\"
"
^
str
^
"
\"
"
...
...
@@ -25,25 +29,33 @@ let rec string_of_expr = function
|
Function
(
name
,
arg
)
->
name
^
"("
^
string_of_expr
arg
^
")"
|
Hexcolor
hex
->
"#"
^
hex
|
Unary
(
op
,
opnd
)
->
op
^
string_of_expr
opnd
|
Nary
(
","
,
opnds
)
->
cat
", "
string_of_expr
opnds
|
Nary
(
op
,
opnds
)
->
cat
op
string_of_expr
opnds
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
|
Combinator
(
left
,
" "
,
right
)
->
string_of_selector
left
^
" "
^
string_of_selector
right
|
Combinator
(
left
,
com
,
right
)
->
string_of_selector
left
^
" "
^
com
^
" "
^
string_of_selector
right
let
block
body
=
" {
\n
"
^
indent
body
^
"
\n
}"
let
rec
string_of_statement
=
function
|
Ruleset
(
selectors
,
decls
)
->
cat
", "
(
S
tring
.
concat
" "
)
selectors
^
cat
", "
s
tring
_of_selector
selectors
^
block
(
cat
"
\n
"
string_of_declaration
decls
)
|
Media
(
queries
,
rulesets
)
->
"@media "
^
String
.
concat
", "
queries
^
block
(
cat
"
\n\n
"
string_of_statement
rulesets
)
|
Import
(
filename
,
[]
)
->
"@import
\"
"
^
filename
^
"
\
"
;"
|
Import
(
filename
,
queries
)
->
"@import
\"
"
^
filename
^
"
\"
"
^
String
.
concat
", "
queries
^
";"
|
Import
(
target
,
[]
)
->
"@import "
^
string_of_expr
target
^
";"
|
Import
(
target
,
queries
)
->
"@import "
^
string_of_expr
target
^
" "
^
String
.
concat
", "
queries
^
";"
|
Charset
charset
->
"@charset
\"
"
^
charset
^
"
\"
;"
|
Page
(
None
,
decls
)
->
...
...
@@ -58,3 +70,45 @@ let rec string_of_statement = function
"@namespace "
^
prefix
^
"
\"
"
^
uri
^
"
\"
;"
let
string_of_stylesheet
=
cat
"
\n\n
"
string_of_statement
(*
* Minified stringification
*)
let
rec
minify_expr
=
function
|
Concat
values
->
cat
" "
minify_expr
values
|
Function
(
name
,
arg
)
->
name
^
"("
^
minify_expr
arg
^
")"
|
Unary
(
op
,
opnd
)
->
op
^
minify_expr
opnd
|
Nary
(
","
,
opnds
)
->
cat
","
minify_expr
opnds
|
Nary
(
op
,
opnds
)
->
cat
op
minify_expr
opnds
|
expr
->
string_of_expr
expr
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_statement
=
function
|
Ruleset
(
selectors
,
decls
)
->
cat
","
minify_selector
selectors
^
"{"
^
(
cat
";"
minify_declaration
decls
)
^
"}"
|
Media
(
queries
,
rulesets
)
->
"@media "
^
String
.
concat
","
queries
^
"{"
^
(
cat
""
minify_statement
rulesets
)
^
"}"
|
Import
(
target
,
[]
)
->
"@import "
^
string_of_expr
target
^
";"
|
Import
(
target
,
queries
)
->
"@import "
^
string_of_expr
target
^
" "
^
String
.
concat
","
queries
^
";"
|
Page
(
None
,
decls
)
->
"@page{"
^
cat
""
minify_declaration
decls
^
"}"
|
Page
(
Some
pseudo
,
decls
)
->
"@page :"
^
pseudo
^
"{"
^
cat
""
minify_declaration
decls
^
"}"
|
Fontface
decls
->
"@font-face{"
^
cat
""
minify_declaration
decls
^
"}"
|
statement
->
string_of_statement
statement
let
minify_stylesheet
=
cat
""
minify_statement
This diff is collapsed.
Click to expand it.
types.ml
+
5
−
3
View file @
e31ac97a
...
...
@@ -11,15 +11,17 @@ type expr =
type
declaration
=
string
*
expr
*
bool
type
selector
=
string
list
type
selector
=
|
Simple
of
string
|
Combinator
of
selector
*
string
*
selector
type
statement
=
|
Ruleset
of
selector
list
*
declaration
list
(* <selectors> { <declarations> } *)
|
Media
of
string
list
*
statement
list
(* @media <queries> { <rulesets> } *)
|
Import
of
string
*
string
list
(* @import
"<file>"
[<media>]; *)
|
Import
of
expr
*
string
list
(* @import
<target>
[<media>]; *)
|
Charset
of
string
(* @charset "<charset>"; *)
|
Page
of
string
option
*
declaration
list
...
...
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