class Nokogiri::CSS::Parser
:nodoc: all
def [](string)
def [](string) return unless cache_on? @mutex.synchronize { @cache[string] } end
def []=(string, value)
def []=(string, value) return value unless cache_on? @mutex.synchronize { @cache[string] = value } end
def _reduce_1(val, _values, result)
def _reduce_1(val, _values, result) result = [val[0], val[2]].flatten result end
def _reduce_10(val, _values, result)
def _reduce_10(val, _values, result) result = Node.new(:ATTRIB_NAME, [val[0]]) result end
def _reduce_11(val, _values, result)
def _reduce_11(val, _values, result) result = if val[1].nil? val[0] else Node.new(:CONDITIONAL_SELECTOR, [val[0], val[1]]) end result end
def _reduce_13(val, _values, result)
def _reduce_13(val, _values, result) result = Node.new(:CONDITIONAL_SELECTOR, val) result end
def _reduce_14(val, _values, result)
def _reduce_14(val, _values, result) result = Node.new(:CONDITIONAL_SELECTOR, val) result end
def _reduce_15(val, _values, result)
def _reduce_15(val, _values, result) result = Node.new(:CONDITIONAL_SELECTOR, [Node.new(:ELEMENT_NAME, ['*']), val[0]]) result end
def _reduce_17(val, _values, result)
def _reduce_17(val, _values, result) result = Node.new(val[0], [nil, val[1]]) result end
def _reduce_18(val, _values, result)
def _reduce_18(val, _values, result) result = Node.new(val[1], [val[0], val[2]]) result end
def _reduce_19(val, _values, result)
def _reduce_19(val, _values, result) result = Node.new(:DESCENDANT_SELECTOR, [val[0], val[2]]) result end
def _reduce_2(val, _values, result)
def _reduce_2(val, _values, result) result = val.flatten result end
def _reduce_21(val, _values, result)
def _reduce_21(val, _values, result) result = Node.new(:CLASS_CONDITION, [unescape_css_identifier(val[1])]) result end
def _reduce_23(val, _values, result)
def _reduce_23(val, _values, result) result = Node.new(:ELEMENT_NAME, val) result end
def _reduce_24(val, _values, result)
def _reduce_24(val, _values, result) result = Node.new(:ELEMENT_NAME, [[val[0], val[2]].compact.join(':')]) result end
def _reduce_25(val, _values, result)
def _reduce_25(val, _values, result) name = @namespaces.key?('xmlns') ? "xmlns:#{val[0]}" : val[0] result = Node.new(:ELEMENT_NAME, [name]) result end
def _reduce_26(val, _values, result)
def _reduce_26(val, _values, result) result = val[0] result end
def _reduce_28(val, _values, result)
def _reduce_28(val, _values, result) result = Node.new(:ATTRIBUTE_CONDITION, [val[1]] + (val[2] || [])) result end
def _reduce_29(val, _values, result)
def _reduce_29(val, _values, result) result = Node.new(:ATTRIBUTE_CONDITION, [val[1]] + (val[2] || [])) result end
def _reduce_3(val, _values, result)
def _reduce_3(val, _values, result) result = [val[1]].flatten result end
def _reduce_30(val, _values, result)
def _reduce_30(val, _values, result) result = Node.new(:PSEUDO_CLASS, [Node.new(:FUNCTION, ['nth-child(', val[1]])]) result end
def _reduce_31(val, _values, result)
def _reduce_31(val, _values, result) result = Node.new(:ATTRIB_NAME, [[val[0], val[2]].compact.join(':')]) result end
def _reduce_32(val, _values, result)
def _reduce_32(val, _values, result) result = Node.new(:ATTRIB_NAME, [val[0]]) result end
def _reduce_34(val, _values, result)
def _reduce_34(val, _values, result) result = Node.new(:FUNCTION, [val[0].strip]) result end
def _reduce_35(val, _values, result)
def _reduce_35(val, _values, result) result = Node.new(:FUNCTION, [val[0].strip, val[1]].flatten) result end
def _reduce_36(val, _values, result)
def _reduce_36(val, _values, result) result = Node.new(:FUNCTION, [val[0].strip, val[1]].flatten) result end
def _reduce_37(val, _values, result)
def _reduce_37(val, _values, result) result = Node.new(:FUNCTION, [val[0].strip, val[1]].flatten) result end
def _reduce_38(val, _values, result)
def _reduce_38(val, _values, result) result = Node.new(:FUNCTION, [val[0].strip, val[1]].flatten) result end
def _reduce_39(val, _values, result)
def _reduce_39(val, _values, result) result = [val[0], val[2]] result end
def _reduce_4(val, _values, result)
def _reduce_4(val, _values, result) result = :DIRECT_ADJACENT_SELECTOR result end
def _reduce_40(val, _values, result)
def _reduce_40(val, _values, result) result = [val[0], val[2]] result end
def _reduce_41(val, _values, result)
def _reduce_41(val, _values, result) result = [val[0], val[2]] result end
def _reduce_42(val, _values, result)
def _reduce_42(val, _values, result) result = [val[0], val[2]] result end
def _reduce_45(val, _values, result)
def _reduce_45(val, _values, result) case val[0] when 'even' result = Node.new(:NTH, ['2','n','+','0']) when 'odd' result = Node.new(:NTH, ['2','n','+','1']) when 'n' result = Node.new(:NTH, ['1','n','+','0']) else result = val end result end
def _reduce_47(val, _values, result)
def _reduce_47(val, _values, result) if val[1] == 'n' result = Node.new(:NTH, val) else raise Racc::ParseError, "parse error on IDENT '#{val[1]}'" end result end
def _reduce_48(val, _values, result)
def _reduce_48(val, _values, result) # n+3, -n+3 if val[0] == 'n' val.unshift("1") result = Node.new(:NTH, val) elsif val[0] == '-n' val[0] = 'n' val.unshift("-1") result = Node.new(:NTH, val) else raise Racc::ParseError, "parse error on IDENT '#{val[1]}'" end result end
def _reduce_49(val, _values, result)
def _reduce_49(val, _values, result) # 5n, -5n, 10n-1 n = val[1] if n[0, 2] == 'n-' val[1] = 'n' val << "-" # b is contained in n as n is the string "n-b" val << n[2, n.size] result = Node.new(:NTH, val) elsif n == 'n' val << "+" val << "0" result = Node.new(:NTH, val) else raise Racc::ParseError, "parse error on IDENT '#{val[1]}'" end result end
def _reduce_5(val, _values, result)
def _reduce_5(val, _values, result) result = :CHILD_SELECTOR result end
def _reduce_50(val, _values, result)
def _reduce_50(val, _values, result) result = Node.new(:PSEUDO_CLASS, [val[1]]) result end
def _reduce_51(val, _values, result)
def _reduce_51(val, _values, result) result = Node.new(:PSEUDO_CLASS, [val[1]]) result end
def _reduce_54(val, _values, result)
def _reduce_54(val, _values, result) result = Node.new(:COMBINATOR, val) result end
def _reduce_55(val, _values, result)
def _reduce_55(val, _values, result) result = Node.new(:COMBINATOR, val) result end
def _reduce_56(val, _values, result)
def _reduce_56(val, _values, result) result = Node.new(:COMBINATOR, val) result end
def _reduce_57(val, _values, result)
def _reduce_57(val, _values, result) result = Node.new(:COMBINATOR, val) result end
def _reduce_58(val, _values, result)
def _reduce_58(val, _values, result) result = Node.new(:COMBINATOR, val) result end
def _reduce_6(val, _values, result)
def _reduce_6(val, _values, result) result = :FOLLOWING_SELECTOR result end
def _reduce_64(val, _values, result)
def _reduce_64(val, _values, result) result = Node.new(:ID, [unescape_css_identifier(val[0])]) result end
def _reduce_65(val, _values, result)
def _reduce_65(val, _values, result) result = [val[0], unescape_css_identifier(val[1])] result end
def _reduce_66(val, _values, result)
def _reduce_66(val, _values, result) result = [val[0], unescape_css_string(val[1])] result end
def _reduce_67(val, _values, result)
def _reduce_67(val, _values, result) result = [val[0], val[1]] result end
def _reduce_69(val, _values, result)
def _reduce_69(val, _values, result) result = :equal result end
def _reduce_7(val, _values, result)
def _reduce_7(val, _values, result) result = :DESCENDANT_SELECTOR result end
def _reduce_70(val, _values, result)
def _reduce_70(val, _values, result) result = :prefix_match result end
def _reduce_71(val, _values, result)
def _reduce_71(val, _values, result) result = :suffix_match result end
def _reduce_72(val, _values, result)
def _reduce_72(val, _values, result) result = :substring_match result end
def _reduce_73(val, _values, result)
def _reduce_73(val, _values, result) result = :not_equal result end
def _reduce_74(val, _values, result)
def _reduce_74(val, _values, result) result = :includes result end
def _reduce_75(val, _values, result)
def _reduce_75(val, _values, result) result = :dash_match result end
def _reduce_76(val, _values, result)
def _reduce_76(val, _values, result) result = Node.new(:NOT, [val[1]]) result end
def _reduce_8(val, _values, result)
def _reduce_8(val, _values, result) result = :CHILD_SELECTOR result end
def _reduce_9(val, _values, result)
def _reduce_9(val, _values, result) result = val[1] result end
def _reduce_none(val, _values, result)
def _reduce_none(val, _values, result) val[0] end
def cache_key(query, prefix, visitor)
def cache_key(query, prefix, visitor) if self.class.cache_on? [query, prefix, @namespaces, visitor.config] end end
def cache_on?
def cache_on? !Thread.current[CACHE_SWITCH_NAME] end
def clear_cache(create_new_object = false)
def clear_cache(create_new_object = false) @mutex.synchronize do if create_new_object @cache = {} else @cache.clear end end end
def initialize(namespaces = {})
def initialize(namespaces = {}) @tokenizer = Tokenizer.new @namespaces = namespaces super() end
def next_token
def next_token @tokenizer.next_token end
def on_error(error_token_id, error_value, value_stack)
def on_error(error_token_id, error_value, value_stack) after = value_stack.compact.last raise SyntaxError, "unexpected '#{error_value}' after '#{after}'" end
def parse(string)
def parse(string) @tokenizer.scan_setup(string) do_parse end
def set_cache(value) # rubocop:disable Naming/AccessorMethodName
Set a thread-local boolean to turn cacheing on and off. Truthy values turn the cache on, falsey values turn the cache off.
def set_cache(value) # rubocop:disable Naming/AccessorMethodName Thread.current[CACHE_SWITCH_NAME] = !value end
def unescape_css_identifier(identifier)
def unescape_css_identifier(identifier) identifier.gsub(/\\(?:([^0-9a-fA-F])|([0-9a-fA-F]{1,6})\s?)/){ |m| $1 || [$2.hex].pack('U') } end
def unescape_css_string(str)
def unescape_css_string(str) str.gsub(/\\(?:([^0-9a-fA-F])|([0-9a-fA-F]{1,6})\s?)/) do |m| if $1=="\n" '' else $1 || [$2.hex].pack('U') end end end
def without_cache(&block)
def without_cache(&block) original_cache_setting = cache_on? set_cache(false) yield ensure set_cache(original_cache_setting) end
def xpath_for(string, prefix, visitor)
def xpath_for(string, prefix, visitor) key = cache_key(string, prefix, visitor) self.class[key] ||= parse(string).map do |ast| ast.to_xpath(prefix, visitor) end end