Commit aaaf2601 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Fixed support for @-<prefix>-keyframes syntax

parent 94a36e40
......@@ -81,8 +81,6 @@ let X = ['x' 'X']
let Y = ['y' 'Y']
let Z = ['z' 'Z']
let uagent = ('-' ("webkit" | "moz" | "ms" | "o") '-')?
rule token = parse
| "\r\n" | '\r' | '\n' { new_line lexbuf; S }
......@@ -105,8 +103,9 @@ rule token = parse
| "@charset " { CHARSET_SYM }
| '@' F O N T '-' F A C E { FONT_FACE_SYM }
| '@' N A M E S P A C E { NAMESPACE_SYM }
| '@' uagent K E Y F R A M E S { KEYFRAMES_SYM }
| '@' 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) }
| (s | comment)* s comment* A N D comment* s (s | comment)*
{ advance_pos lexbuf; WS_AND }
......
......@@ -41,10 +41,10 @@
(* Tokens *)
%token S CDO CDC IMPORT_SYM PAGE_SYM MEDIA_SYM CHARSET_SYM FONT_FACE_SYM
%token NAMESPACE_SYM KEYFRAMES_SYM SUPPORTS_SYM IMPORTANT_SYM
%token NAMESPACE_SYM SUPPORTS_SYM IMPORTANT_SYM
%token <float> PERCENTAGE NUMBER
%token <float * string> UNIT_VALUE
%token <string> COMBINATOR RELATION STRING IDENT HASH URI FUNCTION
%token <string> KEYFRAMES_SYM 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 WS_AND WS_OR
......@@ -141,8 +141,8 @@ descriptor_declaration:
{ (name, value) }
keyframes_rule:
| KEYFRAMES_SYM S* id=IDENT S* LBRACE S* rules=keyframe_ruleset* RBRACE S*
{ Keyframes (id, rules) }
| pre=KEYFRAMES_SYM S* id=IDENT S* LBRACE S* rules=keyframe_ruleset* RBRACE S*
{ Keyframes (pre, id, rules) }
keyframe_ruleset:
| selector=keyframe_selector S* decls=decls_block
{ (selector, decls) }
......
......@@ -110,11 +110,12 @@ let rec string_of_statement = function
"@namespace " ^ string_of_expr uri ^ ";"
| Namespace (Some prefix, uri) ->
"@namespace " ^ prefix ^ " " ^ string_of_expr uri ^ ";"
| Keyframes (id, rules) ->
| Keyframes (prefix, id, rules) ->
let string_of_keyframe_ruleset (expr, decls) =
string_of_expr expr ^ block (cat "\n" string_of_declaration decls)
in
"@keyframes " ^ id ^ block (cat "\n\n" string_of_keyframe_ruleset rules)
"@" ^ prefix ^ "keyframes " ^ id ^
block (cat "\n\n" string_of_keyframe_ruleset rules)
| Supports (condition, statements) ->
"@supports " ^ stringify_condition " " condition ^
block (cat "\n\n" string_of_statement statements)
......@@ -165,7 +166,8 @@ let rec minify_statement = function
| Import (target, []) ->
"@import " ^ string_of_expr target ^ ";"
| Import (target, queries) ->
"@import " ^ string_of_expr target ^ " " ^ cat "," string_of_media_query queries ^ ";"
"@import " ^ string_of_expr target ^ " " ^
cat "," string_of_media_query queries ^ ";"
| Page (None, decls) ->
"@page{" ^ cat ";" minify_declaration decls ^ "}"
| Page (Some pseudo, decls) ->
......@@ -175,11 +177,12 @@ let rec minify_statement = function
name ^ ":" ^ string_of_expr value
in
"@font-face{" ^ cat ";" minify_descriptor_declaration decls ^ "}"
| Keyframes (id, rules) ->
| Keyframes (prefix, id, rules) ->
let minify_keyframe_ruleset (expr, decls) =
minify_expr expr ^ "{" ^ cat ";" minify_declaration decls ^ "}"
in
"@keyframes " ^ id ^ "{" ^ cat "" minify_keyframe_ruleset rules ^ "}"
"@" ^ prefix ^ "keyframes " ^ id ^
"{" ^ cat "" minify_keyframe_ruleset rules ^ "}"
| Supports (condition, statements) ->
"@supports " ^ stringify_condition "" condition ^
"{" ^ cat "" minify_statement statements ^ "}"
......
......@@ -46,8 +46,8 @@ type statement =
(* @font-face { <declarations> } *)
| Namespace of string option * expr
(* @namespace [<prefix>] "<uri>"; *)
| Keyframes of string * keyframe_ruleset list
(* @keyframes <id> { <rulesets> } *)
| Keyframes of string * string * keyframe_ruleset list
(* @[-<prefix>-]keyframes <id> { <rulesets> } *)
| Supports of condition * statement list
(* @supports <condition> { <rulesets> } *)
......
......@@ -203,9 +203,9 @@ let transform_stylesheet f stylesheet =
| Namespace (prefix, uri) ->
let uri = expect_expr uri in
f (Statement (Namespace (prefix, uri)))
| Keyframes (id, rules) ->
| Keyframes (prefix, id, rules) ->
let rules = trav_all_keyframe_ruleset rules in
f (Statement (Keyframes (id, rules)))
f (Statement (Keyframes (prefix, id, rules)))
| Supports (condition, statements) ->
let condition = expect_condition condition in
let statements = trav_all_statement statements in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment