Commit 8818b317 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Comment parsing fix

parent 3ef13b70
...@@ -31,17 +31,17 @@ let mystring = string1 | string2 ...@@ -31,17 +31,17 @@ let mystring = string1 | string2
let badstring1 = '"' ([^'\n' '\r' '\012' '"'] | '\\'nl | escape)* '\\'? let badstring1 = '"' ([^'\n' '\r' '\012' '"'] | '\\'nl | escape)* '\\'?
let badstring2 = '\'' ([^'\n' '\r' '\012' '\''] | '\\'nl | escape)* '\\'? let badstring2 = '\'' ([^'\n' '\r' '\012' '\''] | '\\'nl | escape)* '\\'?
let badstring = badstring1 | badstring2 let badstring = badstring1 | badstring2
let badcomment1 = '/' '*'[^'*']*'*'+([^'/' '*'][^'*']*'*'+)* let badcomment1 = "/*" [^'*']* '*'+ ([^'/' '*'] [^'*']* '*'+)*
let badcomment2 = '/' '*'[^'*']*('*'+[^'/' '*'][^'*']*)* let badcomment2 = "/*" [^'*']* ('*'+ [^'/' '*'] [^'*']*)*
let badcomment = badcomment1 | badcomment2 let badcomment = badcomment1 | badcomment2
let baduri1 = "url(" w (['!' '#' '$' '%' '&' '*'-'[' ']'-'~'] | nonascii | escape)* w let baduri1 = "url(" w (['!' '#' '$' '%' '&' '*'-'[' ']'-'~'] | nonascii | escape)* w
let baduri2 = "url(" w mystring w let baduri2 = "url(" w mystring w
let baduri3 = "url(" w badstring let baduri3 = "url(" w badstring
let baduri = baduri1 | baduri2 | baduri3 let baduri = baduri1 | baduri2 | baduri3
let comment = "/*" [^'*']* '*'+ ([^'/' '*'] [^'*']* '*'+) "*/" let comment = "/*" [^'*']* '*'+ ([^'/' '*'] [^'*']* '*'+)* '/'
let ident = '-'? nmstart nmchar* let ident = '-'? nmstart nmchar*
let name = nmchar+ let name = nmchar+
let num = ['0'-'9']+ | ['0'-'9']*'.'['0'-'9']+ let num = ['0'-'9']+ | ['0'-'9']* '.' ['0'-'9']+
let url = (['!' '#' '$' '%' '&' '*'-'~'] | nonascii | escape)* let url = (['!' '#' '$' '%' '&' '*'-'~'] | nonascii | escape)*
let A = ['a' 'A'] let A = ['a' 'A']
...@@ -75,8 +75,8 @@ let Z = ['z' 'Z'] ...@@ -75,8 +75,8 @@ let Z = ['z' 'Z']
rule token = parse rule token = parse
| s { S } | s { S }
| comment (* ignore comments *) | comment (* ignore comments *)
| badcomment (* unclosed comment at EOF *) | badcomment { token lexbuf } (* unclosed comment at EOF *)
| "<!--" { CDO } | "<!--" { CDO }
| "-->" { CDC } | "-->" { CDC }
......
...@@ -58,13 +58,13 @@ ...@@ -58,13 +58,13 @@
%% %%
(* list with arbitrary whitespace between elements and separators *) (* list with arbitrary whitespace between elements and separators *)
%inline wslist(sep, x): S? l=separated_list(sep, terminated(x, S?)) { l } %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(pair(prefix, S*), x) { p }
cd: CDO S? | CDC S? {} cd: CDO S* | CDC S* {}
stylesheet: stylesheet:
| charset = charset? S? cd* | charset = charset? S* cd*
imports = terminated(import, cd*)* imports = terminated(import, cd*)*
namespaces = terminated(namespace, cd*)* namespaces = terminated(namespace, cd*)*
statements = terminated(nested_statement, cd*)* statements = terminated(nested_statement, cd*)*
...@@ -78,22 +78,22 @@ nested_statement: ...@@ -78,22 +78,22 @@ nested_statement:
{ s } { s }
group_rule_body: group_rule_body:
| LBRACE S? statements=nested_statement* RBRACE S? | LBRACE S* statements=nested_statement* RBRACE S*
{ statements } { statements }
charset: charset:
| CHARSET_SYM name=STRING S? SEMICOL | CHARSET_SYM name=STRING S* SEMICOL
{ Charset name } { Charset name }
import: import:
| IMPORT_SYM S? tgt=string_or_uri media=media_query_list SEMICOL S? | IMPORT_SYM S* tgt=string_or_uri media=media_query_list SEMICOL S*
{ Import (tgt, media) } { Import (tgt, media) }
%inline string_or_uri: %inline string_or_uri:
| str=STRING { Strlit str } | str=STRING { Strlit str }
| uri=URI { Uri uri } | uri=URI { Uri uri }
namespace: namespace:
| NAMESPACE_SYM S? prefix=terminated(namespace_prefix, S?)? ns=string_or_uri S? SEMICOL S? | NAMESPACE_SYM S* prefix=terminated(namespace_prefix, S*)? ns=string_or_uri S* SEMICOL S*
{ Namespace (prefix, ns) } { Namespace (prefix, ns) }
%inline namespace_prefix: %inline namespace_prefix:
| prefix=IDENT | prefix=IDENT
...@@ -103,46 +103,46 @@ media: ...@@ -103,46 +103,46 @@ media:
| MEDIA_SYM queries=media_query_list rulesets=group_rule_body | MEDIA_SYM queries=media_query_list rulesets=group_rule_body
{ Media (queries, rulesets) } { Media (queries, rulesets) }
media_query_list: media_query_list:
| S? | S*
{ [] } { [] }
| S? hd=media_query tl=wspreceded(COMMA, media_query)* | S* hd=media_query tl=wspreceded(COMMA, media_query)*
{ hd :: tl } { hd :: tl }
media_query: 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(AND, media_expr)*
{ (prefix, Some typ, feat) } { (prefix, Some typ, feat) }
| hd=media_expr tl=wspreceded(AND, media_expr)* | hd=media_expr tl=wspreceded(AND, media_expr)*
{ (None, None, (hd :: tl)) } { (None, None, (hd :: tl)) }
%inline only_or_not: %inline only_or_not:
| ONLY S? { "only" } | ONLY S* { "only" }
| NOT S? { "not" } | NOT S* { "not" }
%inline media_type: %inline media_type:
| id=IDENT { id } | id=IDENT { id }
media_expr: media_expr:
| LPAREN S? feature=media_feature S? value=wspreceded(COLON, expr)? RPAREN S? | LPAREN S* feature=media_feature S* value=wspreceded(COLON, expr)? RPAREN S*
{ (feature, value) } { (feature, value) }
%inline media_feature: %inline media_feature:
| id=IDENT { id } | id=IDENT { id }
page: page:
| PAGE_SYM S? pseudo=pseudo_page? decls=decls_block | PAGE_SYM S* pseudo=pseudo_page? decls=decls_block
{ Page (pseudo, decls) } { Page (pseudo, decls) }
pseudo_page: pseudo_page:
| COLON pseudo=IDENT S? | COLON pseudo=IDENT S*
{ pseudo } { pseudo }
font_face_rule: font_face_rule:
| FONT_FACE_SYM S? LBRACE S? hd=descriptor_declaration? | FONT_FACE_SYM S* LBRACE S* hd=descriptor_declaration?
tl=wspreceded(SEMICOL, descriptor_declaration?)* RBRACE S? tl=wspreceded(SEMICOL, descriptor_declaration?)* RBRACE S*
{ Font_face (filter_none (hd :: tl)) } { Font_face (filter_none (hd :: tl)) }
descriptor_declaration: descriptor_declaration:
| name=property COLON S? value=expr | name=property COLON S* value=expr
{ (name, value) } { (name, value) }
keyframes_rule: keyframes_rule:
| KEYFRAMES_SYM S? id=IDENT S? LBRACE S? rules=keyframe_ruleset* RBRACE S? | KEYFRAMES_SYM S* id=IDENT S* LBRACE S* rules=keyframe_ruleset* RBRACE S*
{ Keyframes (id, rules) } { Keyframes (id, rules) }
keyframe_ruleset: keyframe_ruleset:
| selector=keyframe_selector S? decls=decls_block | selector=keyframe_selector S* decls=decls_block
{ (selector, decls) } { (selector, decls) }
keyframe_selector: keyframe_selector:
| FROM { Ident "from" } | FROM { Ident "from" }
...@@ -150,7 +150,7 @@ keyframe_selector: ...@@ -150,7 +150,7 @@ keyframe_selector:
| n=PERCENTAGE { Number (n, Some "%") } | n=PERCENTAGE { Number (n, Some "%") }
supports_rule: supports_rule:
| SUPPORTS_SYM S? cond=supports_condition S? body=group_rule_body | SUPPORTS_SYM S* cond=supports_condition S* body=group_rule_body
{ Supports (cond, body) } { Supports (cond, body) }
supports_condition: supports_condition:
| c=supports_negation | c=supports_negation
...@@ -159,21 +159,21 @@ supports_condition: ...@@ -159,21 +159,21 @@ supports_condition:
| c=supports_condition_in_parens | c=supports_condition_in_parens
{ c } { c }
supports_condition_in_parens: supports_condition_in_parens:
| LPAREN S? c=supports_condition S? RPAREN | LPAREN S* c=supports_condition S* RPAREN
| c=supports_declaration_condition | c=supports_declaration_condition
(*XXX: | c=general_enclosed*) (*XXX: | c=general_enclosed*)
{ c } { c }
supports_negation: supports_negation:
| NOT S c=supports_condition_in_parens | NOT S+ c=supports_condition_in_parens
{ Not c } { Not c }
supports_conjunction: supports_conjunction:
| hd=supports_condition_in_parens tl=preceded(delimited(S, AND, S), supports_condition_in_parens)+ | hd=supports_condition_in_parens tl=preceded(delimited(S+, AND, S+), supports_condition_in_parens)+
{ And (hd :: tl) } { And (hd :: tl) }
supports_disjunction: supports_disjunction:
| hd=supports_condition_in_parens tl=preceded(delimited(S, OR, S), supports_condition_in_parens)+ | hd=supports_condition_in_parens tl=preceded(delimited(S+, OR, S+), supports_condition_in_parens)+
{ Or (hd :: tl) } { Or (hd :: tl) }
supports_declaration_condition: supports_declaration_condition:
| LPAREN S? decl=declaration RPAREN | LPAREN S* decl=declaration RPAREN
{ Decl decl } { Decl decl }
(*XXX: (*XXX:
general_enclosed: general_enclosed:
...@@ -191,7 +191,7 @@ unused : block | ATKEYWORD S* | ';' S* | CDO S* | CDC S*; ...@@ -191,7 +191,7 @@ unused : block | ATKEYWORD S* | ';' S* | CDO S* | CDC S*;
*) *)
%inline decls_block: %inline decls_block:
| LBRACE S? hd=declaration? tl=wspreceded(SEMICOL, declaration?)* RBRACE S? | LBRACE S* hd=declaration? tl=wspreceded(SEMICOL, declaration?)* RBRACE S*
{ filter_none (hd :: tl) } { filter_none (hd :: tl) }
ruleset: ruleset:
...@@ -201,15 +201,15 @@ ruleset: ...@@ -201,15 +201,15 @@ ruleset:
{ Ruleset (selectors_hd :: selectors_tl, decls) } { Ruleset (selectors_hd :: selectors_tl, decls) }
selector: selector:
| simple=simple_selector S? | simple=simple_selector S*
{ Simple simple } { Simple simple }
| left=simple_selector S right=selector | left=simple_selector S+ right=selector
{ Combinator (Simple left, " ", right) } { Combinator (Simple left, " ", right) }
| left=simple_selector S? com=combinator right=selector | left=simple_selector S* com=combinator right=selector
{ Combinator (Simple left, com, right) } { Combinator (Simple left, com, right) }
%inline combinator: %inline combinator:
| PLUS S? { "+" } | PLUS S* { "+" }
| c=COMBINATOR S? { c } | c=COMBINATOR S* { c }
simple_selector: simple_selector:
| elem=element_name addons=element_addon* | elem=element_name addons=element_addon*
...@@ -229,22 +229,22 @@ cls: ...@@ -229,22 +229,22 @@ cls:
{ "." ^ name } { "." ^ name }
attrib: attrib:
| LBRACK S? left=IDENT S? right=pair(RELATION, rel_value)? RBRACK | LBRACK S* left=IDENT S* right=pair(RELATION, rel_value)? RBRACK
{ let right = match right with None -> "" | Some (op, term) -> op ^ term in { let right = match right with None -> "" | Some (op, term) -> op ^ term in
"[" ^ left ^ right ^ "]" } "[" ^ left ^ right ^ "]" }
%inline rel_value: %inline rel_value:
| S? id=IDENT S? { id } | S* id=IDENT S* { id }
| S? s=STRING S? { "\"" ^ s ^ "\"" } | S* s=STRING S* { "\"" ^ s ^ "\"" }
pseudo: pseudo:
| COLON id=IDENT | COLON id=IDENT
{ ":" ^ id } { ":" ^ id }
| COLON f=FUNCTION S? arg=terminated(IDENT, S?)? RPAREN | COLON f=FUNCTION S* arg=terminated(IDENT, S*)? RPAREN
{ let arg = match arg with None -> "" | Some id -> id in { let arg = match arg with None -> "" | Some id -> id in
":" ^ f ^ "(" ^ arg ^ ")" } ":" ^ f ^ "(" ^ arg ^ ")" }
declaration: declaration:
| name=property S? COLON S? value=expr important=boption(pair(IMPORTANT_SYM, S?)) | name=property S* COLON S* value=expr important=boption(pair(IMPORTANT_SYM, S*))
{ (String.lowercase name, value, important) } { (String.lowercase name, value, important) }
%inline property: name=IDENT { name } %inline property: name=IDENT { name }
...@@ -256,17 +256,17 @@ expr: ...@@ -256,17 +256,17 @@ expr:
| t=term { [Term t] } | t=term { [Term t] }
| op=operator t=term { [Operator op; Term t] } | op=operator t=term { [Operator op; Term t] }
%inline operator: %inline operator:
| SLASH S? { "/" } | SLASH S* { "/" }
| COMMA S? { "," } | COMMA S* { "," }
term: term:
| op=unary_operator v=numval S? { Unary (op, v) } | op=unary_operator v=numval S* { Unary (op, v) }
| v=numval S? { v } | v=numval S* { v }
| str=STRING S? { Strlit str } | str=STRING S* { Strlit str }
| id=IDENT S? { Ident id } | id=IDENT S* { Ident id }
| uri=URI S? { Uri uri } | uri=URI S* { Uri uri }
| fn=FUNCTION arg=expr RPAREN S? { Function (fn, arg) } | fn=FUNCTION arg=expr RPAREN S* { Function (fn, arg) }
| hex=HASH S? | 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 if Str.string_match (Str.regexp ("^" ^ h ^ "\\(" ^ h ^ "\\)?$")) hex 0
then Hexcolor (String.lowercase hex) then Hexcolor (String.lowercase hex)
......
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