123456789_123456789_123456789_123456789_123456789_

Class: Nokogiri::CSS::Parser

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Racc::Parser
Instance Chain:
self, Racc::Parser
Inherits: Racc::Parser
  • ::Object
Defined in: lib/nokogiri/css/parser.rb,
lib/nokogiri/css/parser.rb,
lib/nokogiri/css/parser_extras.rb

Constant Summary

  • Racc_arg =
    # File 'lib/nokogiri/css/parser.rb', line 279
    [
    racc_action_table,
    racc_action_check,
    racc_action_default,
    racc_action_pointer,
    racc_goto_table,
    racc_goto_check,
    racc_goto_default,
    racc_goto_pointer,
    racc_nt_base,
    racc_reduce_table,
    racc_token_table,
    racc_shift_n,
    racc_reduce_n,
    racc_use_result_var ]
  • Racc_debug_parser =
    # File 'lib/nokogiri/css/parser.rb', line 357
    false
  • Racc_token_to_s_table =
    # File 'lib/nokogiri/css/parser.rb', line 296
    [
    "$end",
    "error",
    "FUNCTION",
    "INCLUDES",
    "DASHMATCH",
    "LBRACE",
    "HASH",
    "PLUS",
    "GREATER",
    "S",
    "STRING",
    "IDENT",
    "COMMA",
    "NUMBER",
    "PREFIXMATCH",
    "SUFFIXMATCH",
    "SUBSTRINGMATCH",
    "TILDE",
    "NOT_EQUAL",
    "SLASH",
    "DOUBLESLASH",
    "NOT",
    "EQUAL",
    "RPAREN",
    "LSQUARE",
    "RSQUARE",
    "HAS",
    "\"@\"",
    "\".\"",
    "\"*\"",
    "\"|\"",
    "\":\"",
    "$start",
    "selector",
    "simple_selector_1toN",
    "prefixless_combinator_selector",
    "optional_S",
    "combinator",
    "xpath_attribute_name",
    "xpath_attribute",
    "simple_selector",
    "element_name",
    "hcap_0toN",
    "function",
    "pseudo",
    "attrib",
    "hcap_1toN",
    "class",
    "namespaced_ident",
    "namespace",
    "attrib_name",
    "attrib_val_0or1",
    "expr",
    "nth",
    "attribute_id",
    "negation",
    "eql_incl_dash",
    "negation_arg" ]

Class Method Summary

Instance Method Summary

Constructor Details

.newParser

[ GitHub ]

  
# File 'lib/nokogiri/css/parser_extras.rb', line 8

def initialize
  @tokenizer = Tokenizer.new
  super
end

Instance Method Details

#_reduce_1(val, _values, result)

reduce 0 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 363

def _reduce_1(val, _values, result)
      result = [val[0], val[2]].flatten

    result
end

#_reduce_10(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 409

def _reduce_10(val, _values, result)
 result = Node.new(:ATTRIB_NAME, [val[0]])
    result
end

#_reduce_11(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 414

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

#_reduce_13(val, _values, result)

reduce 12 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 426

def _reduce_13(val, _values, result)
 result = Node.new(:CONDITIONAL_SELECTOR, val)
    result
end

#_reduce_14(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 431

def _reduce_14(val, _values, result)
 result = Node.new(:CONDITIONAL_SELECTOR, val)
    result
end

#_reduce_15(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 436

def _reduce_15(val, _values, result)
 result = Node.new(:CONDITIONAL_SELECTOR, [Node.new(:ELEMENT_NAME, ['*']), val[0]])
    result
end

#_reduce_17(val, _values, result)

reduce 16 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 443

def _reduce_17(val, _values, result)
 result = Node.new(val[0], [nil, val[1]])
    result
end

#_reduce_18(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 448

def _reduce_18(val, _values, result)
 result = Node.new(val[1], [val[0], val[2]])
    result
end

#_reduce_19(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 453

def _reduce_19(val, _values, result)
 result = Node.new(:DESCENDANT_SELECTOR, [val[0], val[2]])
    result
end

#_reduce_2(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 369

def _reduce_2(val, _values, result)
 result = val.flatten
    result
end

#_reduce_21(val, _values, result)

reduce 20 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 460

def _reduce_21(val, _values, result)
 result = Node.new(:CLASS_CONDITION, [unescape_css_identifier(val[1])])
    result
end

#_reduce_23(val, _values, result)

reduce 22 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 467

def _reduce_23(val, _values, result)
 result = Node.new(:ELEMENT_NAME, val)
    result
end

#_reduce_24(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 472

def _reduce_24(val, _values, result)
 result = Node.new(:ELEMENT_NAME, [val[0], val[2]])
    result
end

#_reduce_25(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 477

def _reduce_25(val, _values, result)
      name = val[0]
      result = Node.new(:ELEMENT_NAME, [name])

    result
end

#_reduce_26(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 484

def _reduce_26(val, _values, result)
 result = val[0]
    result
end

#_reduce_28(val, _values, result)

reduce 27 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 491

def _reduce_28(val, _values, result)
      result = Node.new(:ATTRIBUTE_CONDITION, [val[1]] + (val[2] || []))

    result
end

#_reduce_29(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 497

def _reduce_29(val, _values, result)
      result = Node.new(:ATTRIBUTE_CONDITION, [val[1]] + (val[2] || []))

    result
end

#_reduce_3(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 374

def _reduce_3(val, _values, result)
 result = [val[1]].flatten
    result
end

#_reduce_30(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 503

def _reduce_30(val, _values, result)
      result = Node.new(:PSEUDO_CLASS, [Node.new(:FUNCTION, ['nth-child(', val[1]])])

    result
end

#_reduce_31(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 509

def _reduce_31(val, _values, result)
 result = Node.new(:ATTRIB_NAME, [[val[0], val[2]].compact.join(':')])
    result
end

#_reduce_32(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 514

def _reduce_32(val, _values, result)
 result = Node.new(:ATTRIB_NAME, [val[0]])
    result
end

#_reduce_34(val, _values, result)

reduce 33 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 521

def _reduce_34(val, _values, result)
      result = Node.new(:FUNCTION, [val[0].strip])

    result
end

#_reduce_35(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 527

def _reduce_35(val, _values, result)
      result = Node.new(:FUNCTION, [val[0].strip, val[1]].flatten)

    result
end

#_reduce_36(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 533

def _reduce_36(val, _values, result)
      result = Node.new(:FUNCTION, [val[0].strip, val[1]].flatten)

    result
end

#_reduce_37(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 539

def _reduce_37(val, _values, result)
      result = Node.new(:FUNCTION, [val[0].strip, val[1]].flatten)

    result
end

#_reduce_38(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 545

def _reduce_38(val, _values, result)
      result = Node.new(:FUNCTION, [val[0].strip, val[1]].flatten)

    result
end

#_reduce_39(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 551

def _reduce_39(val, _values, result)
 result = [val[0], val[2]]
    result
end

#_reduce_4(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 379

def _reduce_4(val, _values, result)
 result = :DIRECT_ADJACENT_SELECTOR
    result
end

#_reduce_40(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 556

def _reduce_40(val, _values, result)
 result = [val[0], val[2]]
    result
end

#_reduce_41(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 561

def _reduce_41(val, _values, result)
 result = [val[0], val[2]]
    result
end

#_reduce_42(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 566

def _reduce_42(val, _values, result)
 result = [val[0], val[2]]
    result
end

#_reduce_45(val, _values, result)

reduce 44 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 575

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

#_reduce_47(val, _values, result)

reduce 46 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 592

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

#_reduce_48(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 602

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

#_reduce_49(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 618

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

#_reduce_5(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 384

def _reduce_5(val, _values, result)
 result = :CHILD_SELECTOR
    result
end

#_reduce_50(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 638

def _reduce_50(val, _values, result)
      result = Node.new(:PSEUDO_CLASS, [val[1]])

    result
end

#_reduce_51(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 644

def _reduce_51(val, _values, result)
 result = Node.new(:PSEUDO_CLASS, [val[1]])
    result
end

#_reduce_54(val, _values, result)

reduce 53 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 653

def _reduce_54(val, _values, result)
      result = Node.new(:COMBINATOR, val)

    result
end

#_reduce_55(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 659

def _reduce_55(val, _values, result)
      result = Node.new(:COMBINATOR, val)

    result
end

#_reduce_56(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 665

def _reduce_56(val, _values, result)
      result = Node.new(:COMBINATOR, val)

    result
end

#_reduce_57(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 671

def _reduce_57(val, _values, result)
      result = Node.new(:COMBINATOR, val)

    result
end

#_reduce_58(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 677

def _reduce_58(val, _values, result)
      result = Node.new(:COMBINATOR, val)

    result
end

#_reduce_6(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 389

def _reduce_6(val, _values, result)
 result = :FOLLOWING_SELECTOR
    result
end

#_reduce_64(val, _values, result)

reduce 63 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 693

def _reduce_64(val, _values, result)
 result = Node.new(:ID, [unescape_css_identifier(val[0])])
    result
end

#_reduce_65(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 698

def _reduce_65(val, _values, result)
 result = [val[0], unescape_css_identifier(val[1])]
    result
end

#_reduce_66(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 703

def _reduce_66(val, _values, result)
 result = [val[0], unescape_css_string(val[1])]
    result
end

#_reduce_67(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 708

def _reduce_67(val, _values, result)
 result = [val[0], val[1]]
    result
end

#_reduce_69(val, _values, result)

reduce 68 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 715

def _reduce_69(val, _values, result)
 result = :equal
    result
end

#_reduce_7(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 394

def _reduce_7(val, _values, result)
 result = :DESCENDANT_SELECTOR
    result
end

#_reduce_70(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 720

def _reduce_70(val, _values, result)
 result = :prefix_match
    result
end

#_reduce_71(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 725

def _reduce_71(val, _values, result)
 result = :suffix_match
    result
end

#_reduce_72(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 730

def _reduce_72(val, _values, result)
 result = :substring_match
    result
end

#_reduce_73(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 735

def _reduce_73(val, _values, result)
 result = :not_equal
    result
end

#_reduce_74(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 740

def _reduce_74(val, _values, result)
 result = :includes
    result
end

#_reduce_75(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 745

def _reduce_75(val, _values, result)
 result = :dash_match
    result
end

#_reduce_76(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 750

def _reduce_76(val, _values, result)
      result = Node.new(:NOT, [val[1]])

    result
end

#_reduce_8(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 399

def _reduce_8(val, _values, result)
 result = :CHILD_SELECTOR
    result
end

#_reduce_9(val, _values, result)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 404

def _reduce_9(val, _values, result)
 result = val[1]
    result
end

#_reduce_none(val, _values, result)

reduce 81 omitted

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 766

def _reduce_none(val, _values, result)
  val[0]
end

#next_token

[ GitHub ]

  
# File 'lib/nokogiri/css/parser_extras.rb', line 18

def next_token
  @tokenizer.next_token
end

#on_error(error_token_id, error_value, value_stack)

On CSS parser error, raise an exception

Raises:

[ GitHub ]

  
# File 'lib/nokogiri/css/parser_extras.rb', line 30

def on_error(error_token_id, error_value, value_stack)
  after = value_stack.compact.last
  raise SyntaxError, "unexpected '#{error_value}' after '#{after}'"
end

#parse(string)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser_extras.rb', line 13

def parse(string)
  @tokenizer.scan_setup(string)
  do_parse
end

#unescape_css_identifier(identifier)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 26

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

#unescape_css_string(str)

[ GitHub ]

  
# File 'lib/nokogiri/css/parser.rb', line 30

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

#xpath_for(selector, visitor)

Get the xpath for selector using visitor

[ GitHub ]

  
# File 'lib/nokogiri/css/parser_extras.rb', line 23

def xpath_for(selector, visitor)
  parse(selector).map do |ast|
    ast.to_xpath(visitor)
  end
end