Skip to content

Commit

Permalink
style: collapse whitespace in css/parser.y
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jan 12, 2022
1 parent b5a50f8 commit 855a812
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 81 deletions.
48 changes: 12 additions & 36 deletions lib/nokogiri/css/parser.rb
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
57 changes: 12 additions & 45 deletions lib/nokogiri/css/parser.y
Expand Up @@ -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
;

Expand All @@ -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])
Expand All @@ -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
;

Expand Down

0 comments on commit 855a812

Please sign in to comment.