Subject: | observations and adjustments for the CSS::Parse::PRDGrammar |
From: | chrispitude [...] gmail.com |
While adapting CSS::Parse::PRDGrammar to some custom CSS parsing, I noticed the following:
1. PRD accepts the first valid match, whereas the CSS specification is that the longest possible match should be used. Accordingly, I use the following production order for any_item:
any_item: URI | PERCENTAGE | DIMENSION | NUMBER | STRING | HASH | UNICODERANGE | IDENT | INCLUDES | DASHMATCH | '(' any(s?) ')' | '[' any(s?) ']' | FUNCTION | DELIM
2. I was able to provide basic comment-handling support directly in the grammar as follows:
WS: m{([ \t\r\n\f]|/\*.*?\*/|//.*?\r?\n)+}s
OWS: WS(?)
(I needed access to comment text during parsing in my use case.)
3. I needed to parse property/value declarations inside @page at-rules, so I modified the grammar as follows:
atrule: ATKEYWORD OWS any(s?) (atblock | ';' )
atblock: '{' OWS (ruleset | declaration | ';' | WS)(s?) '}'
This handles both selector/block rulesets and bare declarations in the at-rule block. I don't know if this handles all cases strictly well, but it worked well for me.