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