lib/nokogiri/css/parser.y in nokogiri-maglev--1.5.2 vs lib/nokogiri/css/parser.y in nokogiri-maglev--1.5.3

- old
+ new

@@ -7,16 +7,17 @@ rule selector : selector COMMA simple_selector_1toN { result = [val.first, val.last].flatten } + | prefixless_combinator_selector { result = val.flatten } | simple_selector_1toN { result = val.flatten } ; combinator : PLUS { result = :DIRECT_ADJACENT_SELECTOR } | GREATER { result = :CHILD_SELECTOR } - | TILDE { result = :PRECEDING_SELECTOR } + | TILDE { result = :FOLLOWING_SELECTOR } | S { result = :DESCENDANT_SELECTOR } | DOUBLESLASH { result = :DESCENDANT_SELECTOR } | SLASH { result = :CHILD_SELECTOR } ; simple_selector @@ -57,10 +58,15 @@ result = Node.new(:CONDITIONAL_SELECTOR, [Node.new(:ELEMENT_NAME, ['*']), val.first] ) } ; + prefixless_combinator_selector + : combinator simple_selector_1toN { + result = Node.new(val.first, [nil, val.last]) + } + ; simple_selector_1toN : simple_selector combinator simple_selector_1toN { result = Node.new(val[1], [val.first, val.last]) } | simple_selector @@ -86,11 +92,11 @@ namespace : IDENT { result = val[0] } | ; attrib - : LSQUARE namespaced_ident attrib_val_0or1 RSQUARE { + : LSQUARE attrib_name attrib_val_0or1 RSQUARE { result = Node.new(:ATTRIBUTE_CONDITION, [val[1]] + (val[2] || []) ) } | LSQUARE function attrib_val_0or1 RSQUARE { @@ -101,9 +107,21 @@ | LSQUARE NUMBER RSQUARE { # Non standard, but hpricot supports it. result = Node.new(:PSEUDO_CLASS, [Node.new(:FUNCTION, ['nth-child(', val[1]])] ) + } + ; + attrib_name + : namespace '|' IDENT { + result = Node.new(:ELEMENT_NAME, + [[val.first, val.last].compact.join(':')] + ) + } + | IDENT { + # Default namespace is not applied to attributes. + # So we don't add prefix "xmlns:" as in namespaced_ident. + result = Node.new(:ELEMENT_NAME, [val.first]) } ; function : FUNCTION RPAREN { result = Node.new(:FUNCTION, [val.first.strip])