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
|
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 357false
-
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
- .new ⇒ Parser constructor
Instance Method Summary
-
#_reduce_1(val, _values, result)
reduce 0 omitted.
- #_reduce_10(val, _values, result)
- #_reduce_11(val, _values, result)
-
#_reduce_13(val, _values, result)
reduce 12 omitted.
- #_reduce_14(val, _values, result)
- #_reduce_15(val, _values, result)
-
#_reduce_17(val, _values, result)
reduce 16 omitted.
- #_reduce_18(val, _values, result)
- #_reduce_19(val, _values, result)
- #_reduce_2(val, _values, result)
-
#_reduce_21(val, _values, result)
reduce 20 omitted.
-
#_reduce_23(val, _values, result)
reduce 22 omitted.
- #_reduce_24(val, _values, result)
- #_reduce_25(val, _values, result)
- #_reduce_26(val, _values, result)
-
#_reduce_28(val, _values, result)
reduce 27 omitted.
- #_reduce_29(val, _values, result)
- #_reduce_3(val, _values, result)
- #_reduce_30(val, _values, result)
- #_reduce_31(val, _values, result)
- #_reduce_32(val, _values, result)
-
#_reduce_34(val, _values, result)
reduce 33 omitted.
- #_reduce_35(val, _values, result)
- #_reduce_36(val, _values, result)
- #_reduce_37(val, _values, result)
- #_reduce_38(val, _values, result)
- #_reduce_39(val, _values, result)
- #_reduce_4(val, _values, result)
- #_reduce_40(val, _values, result)
- #_reduce_41(val, _values, result)
- #_reduce_42(val, _values, result)
-
#_reduce_45(val, _values, result)
reduce 44 omitted.
-
#_reduce_47(val, _values, result)
reduce 46 omitted.
- #_reduce_48(val, _values, result)
- #_reduce_49(val, _values, result)
- #_reduce_5(val, _values, result)
- #_reduce_50(val, _values, result)
- #_reduce_51(val, _values, result)
-
#_reduce_54(val, _values, result)
reduce 53 omitted.
- #_reduce_55(val, _values, result)
- #_reduce_56(val, _values, result)
- #_reduce_57(val, _values, result)
- #_reduce_58(val, _values, result)
- #_reduce_6(val, _values, result)
-
#_reduce_64(val, _values, result)
reduce 63 omitted.
- #_reduce_65(val, _values, result)
- #_reduce_66(val, _values, result)
- #_reduce_67(val, _values, result)
-
#_reduce_69(val, _values, result)
reduce 68 omitted.
- #_reduce_7(val, _values, result)
- #_reduce_70(val, _values, result)
- #_reduce_71(val, _values, result)
- #_reduce_72(val, _values, result)
- #_reduce_73(val, _values, result)
- #_reduce_74(val, _values, result)
- #_reduce_75(val, _values, result)
- #_reduce_76(val, _values, result)
- #_reduce_8(val, _values, result)
- #_reduce_9(val, _values, result)
-
#_reduce_none(val, _values, result)
reduce 81 omitted.
- #next_token
-
#on_error(error_token_id, error_value, value_stack)
On CSS parser error, raise an exception.
- #parse(string)
- #unescape_css_identifier(identifier)
- #unescape_css_string(str)
-
#xpath_for(selector, visitor)
Get the xpath for
selector
usingvisitor
Constructor Details
.new ⇒ Parser
# 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
# 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 ]#_reduce_11(val, _values, result)
[ GitHub ]#_reduce_13(val, _values, result)
reduce 12 omitted
#_reduce_14(val, _values, result)
[ GitHub ]#_reduce_15(val, _values, result)
[ GitHub ]#_reduce_17(val, _values, result)
reduce 16 omitted
#_reduce_18(val, _values, result)
[ GitHub ]#_reduce_19(val, _values, result)
[ GitHub ]#_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
# 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
#_reduce_24(val, _values, result)
[ GitHub ]#_reduce_25(val, _values, result)
[ GitHub ]#_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
#_reduce_29(val, _values, result)
[ GitHub ]#_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 ]#_reduce_31(val, _values, result)
[ GitHub ]#_reduce_32(val, _values, result)
[ GitHub ]#_reduce_34(val, _values, result)
reduce 33 omitted
#_reduce_35(val, _values, result)
[ GitHub ]#_reduce_36(val, _values, result)
[ GitHub ]#_reduce_37(val, _values, result)
[ GitHub ]#_reduce_38(val, _values, result)
[ GitHub ]#_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
#_reduce_47(val, _values, result)
reduce 46 omitted
#_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 ]#_reduce_51(val, _values, result)
[ GitHub ]#_reduce_54(val, _values, result)
reduce 53 omitted
#_reduce_55(val, _values, result)
[ GitHub ]#_reduce_56(val, _values, result)
[ GitHub ]#_reduce_57(val, _values, result)
[ GitHub ]#_reduce_58(val, _values, result)
[ GitHub ]#_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
# 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
# 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 ]#_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
# 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
# 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
# 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