4 use Data::Dump::Streamer;
6 #############################################################################
8 # This thing is an array of hashes with these keys
10 # simple - a CSS simple selector
11 # slide - whether to slide the whole thing down to descendents
12 # match - where to pass the chain on match
14 #############################################################################
18 # first split by aggregator
21 my @selectors = split /\s*,\s*/, $string;
22 for my $selector (@selectors){
23 push @$chains, parse_selector($selector);
28 # the universal selector is deliberately ignored, in Rezoom it is only
29 # supported in its implied form
34 # split on combinators
35 for my $match (split(/\s*([ >+~])\s*/, $string)){
37 # split on simple selector modifiers
38 push(@tokens, split(/([.#\[:])/, $match));
40 # now we got all selector modifiers, combinators and values separated
41 # convert them into our selector hashes
42 @tokens = grep !/\A\Z/, @tokens;
44 unshift @tokens, ' '; #add default combinator
47 my $combinator = shift @tokens;
49 if($combinator eq ' '){
52 elsif($combinator =~ /[+~>]/){
57 unshift @tokens, $combinator;
60 my $simple = shift @tokens;
62 # glue together selector modifiers with their values
63 if($simple =~ m/[.\:\[#]/){
64 $simple .= shift @tokens;
67 $selector{simple} = $simple;
71 if($tokens[0] =~ /[ >]/){
72 $selector{match} = 'children';
74 elsif($tokens[0] eq '+'){
75 $selector{match} = 'nextsibling';
77 elsif($tokens[0] eq '~'){
78 $selector{match} = 'siblings';
81 $selector{match} = 'self';
84 push @chain, \%selector;