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
90db3f19
Commit
90db3f19
authored
10 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Fixed parsing conflicts and stringification issues with @supports
parent
5d9a7709
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lexer.mll
+4
-1
4 additions, 1 deletion
lexer.mll
parser.mly
+17
-9
17 additions, 9 deletions
parser.mly
stringify.ml
+24
-14
24 additions, 14 deletions
stringify.ml
types.ml
+3
-1
3 additions, 1 deletion
types.ml
with
48 additions
and
25 deletions
lexer.mll
+
4
−
1
View file @
90db3f19
...
...
@@ -97,10 +97,13 @@ rule token = parse
| '@' K E Y F R A M E S { KEYFRAMES_SYM }
| '@' S U P P O R T S { SUPPORTS_SYM }
| (w | comment)* w A N D w (w | comment)* { SUPPORTS_AND }
| (w | comment)* w O R w (w | comment)* { SUPPORTS_OR }
| O N L Y { ONLY }
| N O T { NOT }
| A N D { AND }
| O R { OR }
(*
| O R { OR }
removed in favor of SUPPORTS_OR *)
| F R O M { FROM }
| T O { TO }
...
...
This diff is collapsed.
Click to expand it.
parser.mly
+
17
−
9
View file @
90db3f19
...
...
@@ -53,7 +53,8 @@
%
token
<
float
*
string
>
UNIT_VALUE
%
token
<
string
>
COMBINATOR
RELATION
STRING
IDENT
HASH
URI
FUNCTION
%
token
LPAREN
RPAREN
LBRACE
RBRACE
LBRACK
RBRACK
SEMICOL
COLON
COMMA
DOT
PLUS
%
token
MINUS
SLASH
STAR
ONLY
AND
OR
NOT
FROM
TO
EOF
%
token
MINUS
SLASH
STAR
ONLY
AND
(*OR*)
NOT
FROM
TO
EOF
%
token
SUPPORTS_AND
SUPPORTS_OR
(* Start symbol *)
%
type
<
Types
.
stylesheet
>
stylesheet
...
...
@@ -62,8 +63,12 @@
%%
(* list with arbitrary whitespace between elements and separators *)
%
inline
ig2
(
a
,
b
)
:
a
b
{}
%
inline
ig3
(
a
,
b
,
c
)
:
a
b
c
{}
%
inline
wslist
(
sep
,
x
)
:
S
*
l
=
separated_list
(
sep
,
terminated
(
x
,
S
*
))
{
l
}
%
inline
wspreceded
(
prefix
,
x
)
:
p
=
preceded
(
pair
(
prefix
,
S
*
)
,
x
)
{
p
}
%
inline
wspreceded
(
prefix
,
x
)
:
p
=
preceded
(
ig2
(
prefix
,
S
*
)
,
x
)
{
p
}
%
inline
all_and
:
AND
|
SUPPORTS_AND
{}
cd
:
CDO
S
*
|
CDC
S
*
{}
...
...
@@ -112,9 +117,9 @@ media_query_list:
|
S
*
hd
=
media_query
tl
=
wspreceded
(
COMMA
,
media_query
)
*
{
hd
::
tl
}
media_query
:
|
prefix
=
only_or_not
?
typ
=
media_type
S
*
feat
=
wspreceded
(
AND
,
media_expr
)
*
|
prefix
=
only_or_not
?
typ
=
media_type
S
*
feat
=
wspreceded
(
all_and
,
media_expr
)
*
{
(
prefix
,
Some
typ
,
feat
)
}
|
hd
=
media_expr
tl
=
wspreceded
(
AND
,
media_expr
)
*
|
hd
=
media_expr
tl
=
wspreceded
(
all_and
,
media_expr
)
*
{
(
None
,
None
,
(
hd
::
tl
))
}
%
inline
only_or_not
:
|
ONLY
S
*
{
"only"
}
...
...
@@ -171,18 +176,21 @@ supports_negation:
|
NOT
S
+
c
=
supports_condition_in_parens
{
Not
c
}
supports_conjunction
:
|
hd
=
supports_condition_in_parens
tl
=
preceded
(
delimited
(
S
+,
AND
,
S
+
)
,
supports_condition_in_parens
)
+
|
hd
=
supports_condition_in_parens
tl
=
preceded
(
SUPPORTS_AND
,
supports_condition_in_parens
)
+
{
And
(
hd
::
tl
)
}
supports_disjunction
:
|
hd
=
supports_condition_in_parens
tl
=
preceded
(
delimited
(
S
+,
OR
,
S
+
)
,
supports_condition_in_parens
)
+
|
hd
=
supports_condition_in_parens
tl
=
preceded
(
SUPPORTS_OR
,
supports_condition_in_parens
)
+
{
Or
(
hd
::
tl
)
}
supports_declaration_condition
:
|
LPAREN
S
*
decl
=
declaration
RPAREN
|
LPAREN
S
*
decl
=
supports_
declaration
RPAREN
{
Decl
decl
}
supports_declaration
:
|
name
=
property
S
*
COLON
S
*
value
=
expr
{
(
name
,
value
)
}
(*XXX:
general_enclosed:
| ( FUNCTION | LPAREN ) ( any | unused )* RPAREN
{ }
{
Enclosed expr
}
any:
[ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
...
...
@@ -248,7 +256,7 @@ pseudo:
":"
^
f
^
"("
^
arg
^
")"
}
declaration
:
|
name
=
property
S
*
COLON
S
*
value
=
expr
important
=
boption
(
pair
(
IMPORTANT_SYM
,
S
*
))
|
name
=
property
S
*
COLON
S
*
value
=
expr
important
=
boption
(
ig2
(
IMPORTANT_SYM
,
S
*
))
{
(
String
.
lowercase
name
,
value
,
important
)
}
%
inline
property
:
name
=
IDENT
{
name
}
...
...
This diff is collapsed.
Click to expand it.
stringify.ml
+
24
−
14
View file @
90db3f19
...
...
@@ -27,8 +27,7 @@ let rec filter_none = function
let
add_parens
s
=
let
l
=
String
.
length
s
in
if
l
>
0
&
s
.
[
0
]
=
'
(
'
&
s
.
[
l
-
1
]
=
'
)
'
then
String
.
sub
s
1
(
l
-
2
)
else
s
then
s
else
"("
^
s
^
")"
(*
* Pretty-printing
...
...
@@ -76,12 +75,24 @@ let string_of_media_query query =
|
(
Some
pre
,
None
,
_
)
->
failwith
"unexpected media query prefix
\"
"
^
pre
^
"
\"
"
let
rec
string_of_condition
=
function
|
Not
c
->
"not "
^
add_parens
(
string_of_condition
c
)
|
And
c
->
cat
" and "
(
add_parens
@@
string_of_condition
)
c
|
Or
c
->
cat
" or "
(
add_parens
@@
string_of_condition
)
c
|
Decl
(
name
,
value
,
false
)
->
"("
^
name
^
": "
^
string_of_expr
value
^
")"
|
Decl
(
_
,
_
,
true
)
->
failwith
"unexpected
\"
!important
\"
"
let
stringify_condition
w
c
=
let
rec
transform
=
let
p
c
=
`Parens
(
transform
c
)
in
function
|
Not
c
->
`Not
(
p
c
)
|
And
c
->
`And
(
List
.
map
p
c
)
|
Or
c
->
`Or
(
List
.
map
p
c
)
|
Decl
(
name
,
value
)
->
`Decl
(
name
,
value
)
in
let
rec
str
=
function
|
`Not
c
->
"not "
^
str
c
|
`And
c
->
cat
" and "
str
c
|
`Or
c
->
cat
" or "
str
c
|
`Decl
(
name
,
value
)
->
"("
^
name
^
":"
^
w
^
string_of_expr
value
^
")"
|
`Parens
(
`Decl
_
as
d
)
->
str
d
|
`Parens
c
->
"("
^
str
c
^
")"
in
str
(
transform
c
)
let
block
=
function
""
->
" {}"
|
body
->
" {
\n
"
^
indent
body
^
"
\n
}"
...
...
@@ -117,7 +128,7 @@ let rec string_of_statement = function
in
"@keyframes "
^
id
^
block
(
cat
"
\n\n
"
string_of_keyframe_ruleset
rules
)
|
Supports
(
condition
,
statements
)
->
"@supports "
^
string
_of
_condition
condition
^
"@supports "
^
string
ify
_condition
" "
condition
^
block
(
cat
"
\n\n
"
string_of_statement
statements
)
let
string_of_stylesheet
=
cat
"
\n\n
"
string_of_statement
...
...
@@ -158,10 +169,9 @@ let minify_media_query query =
let
rec
minify_condition
=
function
|
Not
c
->
"not "
^
add_parens
(
minify_condition
c
)
|
And
c
->
cat
"and "
(
add_parens
@@
minify_condition
)
c
|
Or
c
->
cat
"or "
(
add_parens
@@
minify_condition
)
c
|
Decl
(
name
,
value
,
false
)
->
"("
^
name
^
":"
^
minify_expr
value
^
")"
|
Decl
(
_
,
_
,
true
)
->
failwith
"unexpected
\"
!important
\"
"
|
And
c
->
cat
" and "
(
add_parens
@@
minify_condition
)
c
|
Or
c
->
cat
" or "
(
add_parens
@@
minify_condition
)
c
|
Decl
(
name
,
value
)
->
"("
^
name
^
":"
^
minify_expr
value
^
")"
let
rec
minify_statement
=
function
|
Ruleset
(
selectors
,
decls
)
->
...
...
@@ -189,7 +199,7 @@ let rec minify_statement = function
in
"@keyframes "
^
id
^
"{"
^
cat
""
minify_keyframe_ruleset
rules
^
"}"
|
Supports
(
condition
,
statements
)
->
"@supports "
^
m
inify_condition
condition
^
"@supports "
^
str
in
g
ify_condition
""
condition
^
"{"
^
cat
""
minify_statement
statements
^
"}"
|
statement
->
string_of_statement
statement
...
...
This diff is collapsed.
Click to expand it.
types.ml
+
3
−
1
View file @
90db3f19
...
...
@@ -22,11 +22,13 @@ type descriptor_declaration = string * expr
type
keyframe_ruleset
=
expr
*
declaration
list
type
supports_declaration
=
string
*
expr
type
condition
=
|
Not
of
condition
|
And
of
condition
list
|
Or
of
condition
list
|
Decl
of
declaration
|
Decl
of
supports_
declaration
(*XXX: | Enclosed of expr*)
type
statement
=
...
...
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