From: Robin B. <da...@us...> - 2001-08-17 17:50:18
|
Update of /cvsroot/perl-css/CSS-SAC In directory usw-pr-cvs1:/tmp/cvs-serv18736 Modified Files: Changes Makefile.PL README SAC.pm Log Message: first batch of 0.04 changes Index: Changes =================================================================== RCS file: /cvsroot/perl-css/CSS-SAC/Changes,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Changes 2001/08/17 13:32:14 1.1.1.1 +++ Changes 2001/08/17 17:50:15 1.2 @@ -1,5 +1,17 @@ Revision history for Perl extension CSS::SAC. +0.04 Ddd Mmm dd hh:mm:ss yyyy (in progress) + - fixed a bug in Text::Balanced that caused blocks to be + incorrectly extracted when they contained backslashed followed by + a newline. As a result Text::Balanced 1.84 is now required. + - fixed a bug which caused some backslash escapes to fail in IDENT + tokens (thanks to Bjoern Hoehrmann) + - fixed a stupid precedence bug in the RGB regex (thanks to Steffen + Goeldner) + - HTML end comments didn't work properly (Steffen Goeldner) + - @import looked for uri instead of url (Steffen Goeldner) + + 0.03 Mon Apr 23 16:44:16 2001 - switched all to Class::ArrayObjects (which used to be CSS::SAC::Helpers::ArrayObjects) - provide both standard and perlified names for methods Index: Makefile.PL =================================================================== RCS file: /cvsroot/perl-css/CSS-SAC/Makefile.PL,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.PL 2001/08/17 13:32:14 1.1.1.1 +++ Makefile.PL 2001/08/17 17:50:15 1.2 @@ -2,10 +2,10 @@ # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( - 'NAME' => 'CSS::SAC', - 'VERSION_FROM' => 'SAC.pm', # finds $VERSION - 'PREREQ_PM' => { - Text::Balanced => 0, - Class::ArrayObjects => 0.04, - }, # e.g., Module::Name => 1.1 + 'NAME' => 'CSS::SAC', + 'VERSION_FROM' => 'SAC.pm', + 'PREREQ_PM' => { + Text::Balanced => '1.84', + Class::ArrayObjects => '0.04', + }, ); Index: README =================================================================== RCS file: /cvsroot/perl-css/CSS-SAC/README,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- README 2001/08/17 13:32:14 1.1.1.1 +++ README 2001/08/17 17:50:15 1.2 @@ -1,5 +1,5 @@ -### CSS::SAC 0.03 - a SAC parser for Perl +### CSS::SAC 0.04 - a SAC parser for Perl This module implements a SAC interface for Perl. It has a good deal @@ -9,7 +9,14 @@ SAC handlers (which I will document in a spec'ish way soon). If you have any questions don't hesitate to contact me. +While relatively stable, this module still has bugs and is currently +considered early beta quality. The interface is fairly stable, but it +may evolve. Should that happen, a deprecation cycle will happen over +several releases (with warnings on deprecated methods in between). +Currently it is rather slow. Performance is the things we'll start +working on once enough bugs have been ironed out. + Prerequisites ============= @@ -52,6 +59,12 @@ CSS::Parser is officially deprecated. Thanks to all the people that provided patches, and sorry to all those that asked questions while I was away. You may contact me if you need anything. + +This module now has a mailing list part of the perl-css SourceForge +project. The latest CVS version is also always available on SourceForge. + + http://sourceforge.net/projects/perl-css/ + http://lists.sourceforge.net/lists/listinfo/perl-css-devel This module is licensed under the same terms as Perl itself. Index: SAC.pm =================================================================== RCS file: /cvsroot/perl-css/CSS-SAC/SAC.pm,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- SAC.pm 2001/08/17 13:32:14 1.1.1.1 +++ SAC.pm 2001/08/17 17:50:15 1.2 @@ -29,7 +29,7 @@ use Text::Balanced qw(); - +use constant DEBUG => 0; #---------------------------------------------------------------------# # build a few useful regexen and maps @@ -37,18 +37,18 @@ # matches a quoted string $RE_STRING = Text::Balanced::gen_delimited_pat(q{'"}); #" -$RE_STRING = qr/$RE_STRING/; +$RE_STRING = qr/$RE_STRING/s; # matches a name token $RE_NAME = qr/ (?:(?:\\(?:(?:[a-fA-F0-9]{1,6}[\t\x20])|[\x32-\xff]))|[a-zA-Z\x80-\xff0-9-])+ - /x; + /xs; # matches a valid CSS ident (this may be wrong, needs testing) -$RE_IDENT = qr/ - (?:(?:\\(?:(?:[a-fA-F0-9]{1,6}[\t\x20])|[\x32-\xff]))|[a-zA-Z\x80-\xff]) - (?:(?:\\(?:(?:[a-fA-F0-9]{1,6}[\t\x20])|[\x32-\xff]))|[a-zA-Z\x80-\xff0-9-])* - /x; +my $RE_IDENT = qr/ + (?:(?:\\(?:(?:[a-fA-F0-9]{1,6}[\t\x20])|[ \x32-\xff]))|[a-zA-Z\x80-\xff]) + (?:(?:\\(?:(?:[a-fA-F0-9]{1,6}[\t\x20])|[ \x32-\xff]))|[a-zA-Z\x80-\xff0-9-])* + /xs; # matches a unicode range $RE_RANGE = qr/(?: @@ -66,7 +66,7 @@ (?:\?{0,1}|[0-9a-fA-F]))))))) ) ) - /x; + /xs; # matches a number @@ -315,22 +315,28 @@ #---> Start Parsing <---------------------------------------------# # start doc + warn "[SAC] start parsing\n" if DEBUG; $sac->[_dh_]->start_document if $sac->[_dh_can_]->{start_document}; # before anything else occurs there can be a charset + warn "[SAC] parsing charset\n" if DEBUG; $sac->parse_charset(\$css); $sac->[_allow_charset_] = 0; # remove an eventual HTML open comment (not reported to handler) + warn "[SAC] removing HTML comments\n" if DEBUG; $css =~ s/^\s*<!--//; # parse some possible comments + warn "[SAC] parsing comments\n" if DEBUG; $sac->parse_comments(\$css); # parse some possible imports + warn "[SAC] parsing imports\n" if DEBUG; $sac->parse_imports(\$css); # parse some possible ns declarations + warn "[SAC] parsing ns decl\n" if DEBUG; $sac->parse_namespace_declarations(\$css); # enter the main parsing loop @@ -338,10 +344,12 @@ while (length($css)) { # parse some possible comments + warn "[SAC] parsing comments\n" if DEBUG; $sac->parse_comments(\$css); # if we've got a closing block, it's a closing @media if ($css =~ s/^\s*\}//) { + warn "[SAC] closing media rule\n" if DEBUG; $sac->[_dh_]->end_media($sac->[_tmp_media_]) if $sac->[_dh_can_]->{end_media}; $sac->[_tmp_media_] = undef; } @@ -351,6 +359,7 @@ # @media if ($css =~ s/^\s*\@media\s+//i) { + warn "[SAC] parsing media\n" if DEBUG; my $medialist = $sac->parse_medialist(\$css); $sac->[_tmp_media_] = $medialist; $sac->[_dh_]->start_media($medialist) if $sac->[_dh_can_]->{start_media}; @@ -359,6 +368,7 @@ # @font-face elsif ($css =~ s/^\s*\@font-face\s+//i) { + warn "[SAC] parsing font-face\n" if DEBUG; # parse the block my $rule; ($rule,$css,undef) = Text::Balanced::extract_bracketed($css,q/{}'"/,qr/\s*/); #" @@ -369,6 +379,7 @@ # @page elsif ($css =~ s/^\s*\@page\s+//i) { + warn "[SAC] parsing page\n" if DEBUG; # grab the name and pseudo-page if they're there $css =~ s/^($RE_IDENT)?\s*(?::($RE_IDENT))//; my ($name,$pseudo) = ($1,$2); @@ -386,6 +397,7 @@ # at rules that we know nothing about will be like else { my $at_rule; + warn "[SAC] parsing unknown at rule\n" if DEBUG; # take off the @rule first $css =~ s/^\s*(\@$RE_IDENT\s*)//; @@ -408,14 +420,22 @@ } } + # html end comment + elsif ($css =~ s/^\s*-->\s*//) { + # we don't do anything with those presently + warn "[SAC] removing HTML comments\n" if DEBUG; + } + # we have selectors elsif (my $sel_list = $sac->parse_selector_list(\$css)) { + warn "[SAC] parsed selectors\n" if DEBUG; next unless @$sel_list; # callbacks $sac->[_dh_]->start_selector($sel_list) if $sac->[_dh_can_]->{start_selector}; # parse the rule my $rule; + warn "[SAC] parsing rule\n" if DEBUG; ($rule,$css,undef) = Text::Balanced::extract_bracketed($css,q/{}'"/,qr/\s*/); #" $sac->parse_rule(\$rule); @@ -423,24 +443,21 @@ $sac->[_dh_]->end_selector($sel_list) if $sac->[_dh_can_]->{end_selector}; } - # html end comment - elsif ($css =~ s/^\s*-->\s*//) { - # we don't do anything with those presently - } - # trailing whitespace, should only happen at the very end elsif ($css =~ s/^\s+//) { # do nothing + warn "[SAC] just whitespace\n" if DEBUG; } # error else { - $sac->[_eh_]->warning('Unknown trailing tokens in style sheet'); + $sac->[_eh_]->fatal_error('Unknown trailing tokens in style sheet'); last; } } # end doc + warn "[SAC] end of document\n" if DEBUG; $sac->[_dh_]->end_document if $sac->[_dh_can_]->{end_document}; #---> Finish Parsing <--------------------------------------------# @@ -470,8 +487,12 @@ $sac->[_dh_]->charset($charset) if $sac->[_dh_can_]->{charset}; } else { - $$css =~ s/[^;]*;//; - $sac->[_eh_]->warning('Unknown token in charset declaration'); + if ($$css =~ s/[^;]*;//;) { + $sac->[_eh_]->warning('Unknown token in charset declaration'); + } + else { + $sac->[_eh_]->fatal_error('Unknown token in charset declaration'); + } } } #---------------------------------------------------------------------# @@ -490,7 +511,7 @@ while ($$css =~ s/^\s*\@import\s+//i) { # first get the uri my $uri; - if ($$css =~ s/^uri\(//) { + if ($$css =~ s/^url\(//) { $$css =~ s/^((?:$RE_STRING)|([^\)]*))\s*//; $uri = $1; $uri =~ s/^(?:'|")//; # " @@ -512,8 +533,12 @@ $sac->[_dh_]->import_style($uri,$medialist) if $sac->[_dh_can_]->{import_style}; } else { - $$css =~ s/[^;]*;//; - $sac->[_eh_]->warning('Unknown token in import rule'); + if ($$css =~ s/[^;]*;//) { + $sac->[_eh_]->warning('Unknown token in import rule'); + } + else { + $sac->[_eh_]->fatal_error('Unknown token in import rule'); + } } # remove comments and run again @@ -566,8 +591,12 @@ $sac->[_dh_]->namespace_declaration($prefix,$uri) if $sac->[_dh_can_]->{namespace_declaration}; } else { - $$css =~ s/[^;]*;//; - $sac->[_eh_]->warning('Unknown token in namespace declaration'); + if ($$css =~ s/[^;]*;//) { + $sac->[_eh_]->warning('Unknown token in namespace declaration'); + } + else { + $sac->[_eh_]->fatal_error('Unknown token in namespace declaration'); + } } # remove comments and run again @@ -610,6 +639,12 @@ } else { $sac->[_eh_]->warning('Unterminated comment'); + if ($$css =~ s/[^;]*;//) { + $sac->[_eh_]->warning('Unknown token in import rule'); + } + else { + $sac->[_eh_]->fatal_error('Unknown token in import rule'); + } } } @@ -656,6 +691,12 @@ $$css =~ s/^[^{]*//; $sac->[_eh_]->warning('Unknown token in selector list'); last; + if ($$css =~ s/[^;]*;//) { + $sac->[_eh_]->warning('Unknown token in import rule'); + } + else { + $sac->[_eh_]->fatal_error('Unknown token in import rule'); + } } } @@ -766,6 +807,12 @@ } else { $sac->[_eh_]->warning('Unknown token in attribute condition'); + if ($$css =~ s/[^;]*;//) { + $sac->[_eh_]->warning('Unknown token in import rule'); + } + else { + $sac->[_eh_]->fatal_error('Unknown token in import rule'); + } } } @@ -920,6 +967,12 @@ $$css =~ s/^.*?(,|{)/$1/; $sac->[_eh_]->warning('Unknown token in simple selector'); last; + if ($$css =~ s/[^;]*;//) { + $sac->[_eh_]->warning('Unknown token in import rule'); + } + else { + $sac->[_eh_]->fatal_error('Unknown token in import rule'); + } } } @@ -941,6 +994,19 @@ $sac->[_eh_]->fatal_error('Really weird input in simple selector'); } +# here we need to check whether the next token is also a selector +# if it is, we need to make an AND_CONDITION containing the two selectors +# and to attach it to a universal selector +# then we'll have to mix it into the $cond below. + if (@tokens) { + eval { $tokens[0]->SelectorType }; + if (!$@) { + my $and_cond = $sac->[_cf_]->create_and_condition($selector,shift @tokens); + $selector = $sac->[_sf_]->create_element_selector(undef,undef); + } + } + + # create a conditional selector with all conditions my $cond = $sac->build_condition(\@tokens); if ($cond) { @@ -1009,10 +1075,10 @@ # get all conditions my @conditions; while (@$tokens) { - eval { $tokens->[0]->SelectorType }; - if (not $@) { - $sac->[_eh_]->fatal_error('Really weird input in simple selector'); - } +# eval { $tokens->[0]->SelectorType }; +# if (not $@) { +# $sac->[_eh_]->fatal_error('Really weird input in simple selector'); +# } last if ! ref $tokens->[0]; push @conditions, shift @$tokens; } @@ -1043,6 +1109,7 @@ # remove { and }, and parse the content $$css =~ s/^\s*{//; $$css =~ s/}\s*$//; + warn "[SAC] removed curlies\n" if DEBUG; $sac->parse_style_declaration($css); } #---------------------------------------------------------------------# @@ -1073,8 +1140,15 @@ # the value my $lu = $sac->parse_property_value($css); if (!@$lu) { +print "pvcss: $$css\n"; $$css =~ s/^.*?;?\s*//; $sac->[_eh_]->warning('Unknown token in property value'); + if ($$css =~ s/[^;]*;//) { + $sac->[_eh_]->warning('Unknown token in import rule'); + } + else { + $sac->[_eh_]->fatal_error('Unknown token in import rule'); + } next; } $sac->parse_comments($css); @@ -1181,7 +1255,7 @@ } # hex rgb - elsif ($$css =~ s/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})//) { + elsif ($$css =~ s/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})//) { $value = $1; $text = '#'; $type = RGBCOLOR; @@ -1589,31 +1663,40 @@ =head1 BUGS -None that I know of but this is early beta software and should be -treated as such. + - the problem with attaching pseudo-elements to elements as + coselectors. I'm not sure which is the right representation. Don't + forget to update CSS::SAC::Writer too so that it writes it out + properly. + + - see Bjoern's list =head1 ACKNOWLEDGEMENTS - Bjoern Hoehrmann for his immediate reaction and much valuable feedback and suggestions. It's certainly much harder to type with all those fingers that all those Mafia padres have cut off, but at least - I get work done much faster than before. + I get work done much faster than before. And also those nasty bugs he + kindly uncovered. - - Simon St.Laurent for posting this on xmlhack.com and thus pointing a - lot of people to this module (as seen in my referer logs). + - Steffen Goeldner for spotting bugs and providing patches. + - Ian Hickson for very very very kind testing support, and all sorts + of niceties. + - Manos Batsis for starting a very long discussion on this that eventually deviated into other very interesting topics, and for giving me some really weird style sheets to feed into this module. - - Ian Hickson for very very very kind testing support, and all sorts - of niceties. + - Simon St.Laurent for posting this on xmlhack.com and thus pointing a + lot of people to this module (as seen in my referer logs). And of course all the other people that have sent encouragement notes and feature requests. =head1 TODO + - add a pointer to the SAC W3 page + - create the Exception classes - update PositionalCondition to include logic that can normalize the @@ -1628,6 +1711,10 @@ - add docs on how to write a {Document,Error}Handler, right now there is example code in Writer, but it isn't all clearly explained. + + - add an iterator that tracks loops and exits them with an error + whenever it reaches a certain (configurable) count. We need to + reliably jump out of infinite loops whenever it is needed. =head1 AUTHOR |