diff --git a/lib/nokogiri/css/parser.rb b/lib/nokogiri/css/parser.rb index ffc6e96178..2299092a70 100644 --- a/lib/nokogiri/css/parser.rb +++ b/lib/nokogiri/css/parser.rb @@ -422,42 +422,34 @@ def _reduce_11(val, _values, result) # reduce 12 omitted def _reduce_13(val, _values, result) - result = Node.new(:CONDITIONAL_SELECTOR, val) - + result = Node.new(:CONDITIONAL_SELECTOR, val) result end def _reduce_14(val, _values, result) - result = Node.new(:CONDITIONAL_SELECTOR, val) - + result = Node.new(:CONDITIONAL_SELECTOR, val) result end def _reduce_15(val, _values, result) - result = Node.new(:CONDITIONAL_SELECTOR, - [Node.new(:ELEMENT_NAME, ['*']), val[0]] - ) - + result = Node.new(:CONDITIONAL_SELECTOR, [Node.new(:ELEMENT_NAME, ['*']), val[0]]) result end # reduce 16 omitted def _reduce_17(val, _values, result) - result = Node.new(val[0], [nil, val[1]]) - + result = Node.new(val[0], [nil, val[1]]) result end def _reduce_18(val, _values, result) - result = Node.new(val[1], [val[0], val[2]]) - + result = Node.new(val[1], [val[0], val[2]]) result end def _reduce_19(val, _values, result) - result = Node.new(:DESCENDANT_SELECTOR, [val[0], val[2]]) - + result = Node.new(:DESCENDANT_SELECTOR, [val[0], val[2]]) result end @@ -476,10 +468,7 @@ def _reduce_23(val, _values, result) end def _reduce_24(val, _values, result) - result = Node.new(:ELEMENT_NAME, - [[val[0], val[2]].compact.join(':')] - ) - + result = Node.new(:ELEMENT_NAME, [[val[0], val[2]].compact.join(':')]) result end @@ -498,43 +487,30 @@ def _reduce_26(val, _values, result) # reduce 27 omitted def _reduce_28(val, _values, result) - result = Node.new(:ATTRIBUTE_CONDITION, - [val[1]] + (val[2] || []) - ) + result = Node.new(:ATTRIBUTE_CONDITION, [val[1]] + (val[2] || [])) result end def _reduce_29(val, _values, result) - result = Node.new(:ATTRIBUTE_CONDITION, - [val[1]] + (val[2] || []) - ) + result = Node.new(:ATTRIBUTE_CONDITION, [val[1]] + (val[2] || [])) result end def _reduce_30(val, _values, result) - # non-standard, from hpricot - result = Node.new(:PSEUDO_CLASS, - [Node.new(:FUNCTION, ['nth-child(', val[1]])] - ) + result = Node.new(:PSEUDO_CLASS, [Node.new(:FUNCTION, ['nth-child(', val[1]])]) result end def _reduce_31(val, _values, result) - result = Node.new(:ATTRIB_NAME, - [[val[0], val[2]].compact.join(':')] - ) - + result = Node.new(:ATTRIB_NAME, [[val[0], val[2]].compact.join(':')]) result end def _reduce_32(val, _values, result) - # Default namespace is not applied to attributes. - # So we don't add prefix "xmlns:" as in namespaced_ident. - result = Node.new(:ATTRIB_NAME, [val[0]]) - + result = Node.new(:ATTRIB_NAME, [val[0]]) result end diff --git a/lib/nokogiri/css/parser.y b/lib/nokogiri/css/parser.y index af1ba6bad3..0431a479e8 100644 --- a/lib/nokogiri/css/parser.y +++ b/lib/nokogiri/css/parser.y @@ -38,33 +38,19 @@ rule end } | function - | function pseudo { - result = Node.new(:CONDITIONAL_SELECTOR, val) - } - | function attrib { - result = Node.new(:CONDITIONAL_SELECTOR, val) - } - | hcap_1toN { - result = Node.new(:CONDITIONAL_SELECTOR, - [Node.new(:ELEMENT_NAME, ['*']), val[0]] - ) - } + | function pseudo { result = Node.new(:CONDITIONAL_SELECTOR, val) } + | function attrib { result = Node.new(:CONDITIONAL_SELECTOR, val) } + | hcap_1toN { result = Node.new(:CONDITIONAL_SELECTOR, [Node.new(:ELEMENT_NAME, ['*']), val[0]]) } | xpath_attribute ; prefixless_combinator_selector: - combinator simple_selector_1toN { - result = Node.new(val[0], [nil, val[1]]) - } + combinator simple_selector_1toN { result = Node.new(val[0], [nil, val[1]]) } ; simple_selector_1toN: - simple_selector combinator simple_selector_1toN { - result = Node.new(val[1], [val[0], val[2]]) - } - | simple_selector S simple_selector_1toN { - result = Node.new(:DESCENDANT_SELECTOR, [val[0], val[2]]) - } + simple_selector combinator simple_selector_1toN { result = Node.new(val[1], [val[0], val[2]]) } + | simple_selector S simple_selector_1toN { result = Node.new(:DESCENDANT_SELECTOR, [val[0], val[2]]) } | simple_selector ; @@ -78,11 +64,7 @@ rule ; namespaced_ident: - namespace '|' IDENT { - result = Node.new(:ELEMENT_NAME, - [[val[0], val[2]].compact.join(':')] - ) - } + namespace '|' IDENT { result = Node.new(:ELEMENT_NAME, [[val[0], val[2]].compact.join(':')]) } | IDENT { name = @namespaces.key?('xmlns') ? "xmlns:#{val[0]}" : val[0] result = Node.new(:ELEMENT_NAME, [name]) @@ -96,34 +78,19 @@ rule attrib: LSQUARE attrib_name attrib_val_0or1 RSQUARE { - result = Node.new(:ATTRIBUTE_CONDITION, - [val[1]] + (val[2] || []) - ) + result = Node.new(:ATTRIBUTE_CONDITION, [val[1]] + (val[2] || [])) } | LSQUARE function attrib_val_0or1 RSQUARE { - result = Node.new(:ATTRIBUTE_CONDITION, - [val[1]] + (val[2] || []) - ) + result = Node.new(:ATTRIBUTE_CONDITION, [val[1]] + (val[2] || [])) } | LSQUARE NUMBER RSQUARE { - # non-standard, from hpricot - result = Node.new(:PSEUDO_CLASS, - [Node.new(:FUNCTION, ['nth-child(', val[1]])] - ) + result = Node.new(:PSEUDO_CLASS, [Node.new(:FUNCTION, ['nth-child(', val[1]])]) } ; attrib_name: - namespace '|' IDENT { - result = Node.new(:ATTRIB_NAME, - [[val[0], val[2]].compact.join(':')] - ) - } - | IDENT { - # Default namespace is not applied to attributes. - # So we don't add prefix "xmlns:" as in namespaced_ident. - result = Node.new(:ATTRIB_NAME, [val[0]]) - } + namespace '|' IDENT { result = Node.new(:ATTRIB_NAME, [[val[0], val[2]].compact.join(':')]) } + | IDENT { result = Node.new(:ATTRIB_NAME, [val[0]]) } | xpath_attribute ;