Class: Nokogiri::CSS::GeneratedParser

Inherits:
Racc::Parser
  • Object
show all
Defined in:
lib/nokogiri/css/generated_parser.rb

Direct Known Subclasses

GeneratedTokenizer

Constant Summary collapse

Racc_arg =
[
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_token_to_s_table =
[
"$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",
"combinator",
"simple_selector",
"element_name",
"hcap_0toN",
"hcap_1toN",
"negation",
"function",
"attrib",
"class",
"namespace",
"attrib_val_0or1",
"expr",
"an_plus_b",
"pseudo",
"attribute_id",
"eql_incl_dash",
"negation_arg" ]
Racc_debug_parser =
false

Instance Method Summary collapse

Instance Method Details

#_reduce_1(val, _values, result) ⇒ Object

reduce 0 omitted



281
282
283
284
285
# File 'lib/nokogiri/css/generated_parser.rb', line 281

def _reduce_1(val, _values, result)
        result = [val.first, val.last].flatten
      
    result
end

#_reduce_10(val, _values, result) ⇒ Object



332
333
334
335
336
337
338
339
340
341
# File 'lib/nokogiri/css/generated_parser.rb', line 332

def _reduce_10(val, _values, result)
        result = Node.new(:CONDITIONAL_SELECTOR,
          [
            val.first,
            Node.new(:COMBINATOR, [val[1], val.last])
          ]
        )
      
    result
end

#_reduce_11(val, _values, result) ⇒ Object



343
344
345
346
347
# File 'lib/nokogiri/css/generated_parser.rb', line 343

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

#_reduce_13(val, _values, result) ⇒ Object

reduce 12 omitted



351
352
353
354
355
# File 'lib/nokogiri/css/generated_parser.rb', line 351

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

#_reduce_14(val, _values, result) ⇒ Object



357
358
359
360
361
362
363
364
365
366
# File 'lib/nokogiri/css/generated_parser.rb', line 357

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

#_reduce_15(val, _values, result) ⇒ Object



368
369
370
371
372
373
374
# File 'lib/nokogiri/css/generated_parser.rb', line 368

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

#_reduce_16(val, _values, result) ⇒ Object



376
377
378
379
380
# File 'lib/nokogiri/css/generated_parser.rb', line 376

def _reduce_16(val, _values, result)
        result = Node.new(val[1], [val.first, val.last])
      
    result
end

#_reduce_18(val, _values, result) ⇒ Object

reduce 17 omitted



384
385
386
387
# File 'lib/nokogiri/css/generated_parser.rb', line 384

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

#_reduce_19(val, _values, result) ⇒ Object



389
390
391
392
393
394
395
# File 'lib/nokogiri/css/generated_parser.rb', line 389

def _reduce_19(val, _values, result)
        result = Node.new(:ELEMENT_NAME,
          [[val.first, val.last].compact.join(':')]
        )
      
    result
end

#_reduce_2(val, _values, result) ⇒ Object



287
288
289
290
# File 'lib/nokogiri/css/generated_parser.rb', line 287

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

#_reduce_20(val, _values, result) ⇒ Object



397
398
399
400
401
402
# File 'lib/nokogiri/css/generated_parser.rb', line 397

def _reduce_20(val, _values, result)
        name = @namespaces.key?('xmlns') ? "xmlns:#{val.first}" : val.first
        result = Node.new(:ELEMENT_NAME, [name])
      
    result
end

#_reduce_21(val, _values, result) ⇒ Object



404
405
406
407
# File 'lib/nokogiri/css/generated_parser.rb', line 404

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

#_reduce_22(val, _values, result) ⇒ Object



409
410
411
412
# File 'lib/nokogiri/css/generated_parser.rb', line 409

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

#_reduce_24(val, _values, result) ⇒ Object

reduce 23 omitted



416
417
418
419
420
421
422
# File 'lib/nokogiri/css/generated_parser.rb', line 416

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

#_reduce_25(val, _values, result) ⇒ Object



424
425
426
427
428
429
430
# File 'lib/nokogiri/css/generated_parser.rb', line 424

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

#_reduce_26(val, _values, result) ⇒ Object



432
433
434
435
436
437
438
439
# File 'lib/nokogiri/css/generated_parser.rb', line 432

def _reduce_26(val, _values, result)
        # Non standard, but hpricot supports it.
        result = Node.new(:PSEUDO_CLASS,
          [Node.new(:FUNCTION, ['nth-child(', val[1]])]
        )
      
    result
end

#_reduce_27(val, _values, result) ⇒ Object



441
442
443
444
445
# File 'lib/nokogiri/css/generated_parser.rb', line 441

def _reduce_27(val, _values, result)
        result = Node.new(:FUNCTION, [val.first.strip])
      
    result
end

#_reduce_28(val, _values, result) ⇒ Object



447
448
449
450
451
# File 'lib/nokogiri/css/generated_parser.rb', line 447

def _reduce_28(val, _values, result)
        result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
      
    result
end

#_reduce_29(val, _values, result) ⇒ Object



453
454
455
456
457
# File 'lib/nokogiri/css/generated_parser.rb', line 453

def _reduce_29(val, _values, result)
        result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
      
    result
end

#_reduce_3(val, _values, result) ⇒ Object



292
293
294
295
# File 'lib/nokogiri/css/generated_parser.rb', line 292

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

#_reduce_30(val, _values, result) ⇒ Object



459
460
461
462
463
# File 'lib/nokogiri/css/generated_parser.rb', line 459

def _reduce_30(val, _values, result)
        result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
      
    result
end

#_reduce_31(val, _values, result) ⇒ Object



465
466
467
468
469
# File 'lib/nokogiri/css/generated_parser.rb', line 465

def _reduce_31(val, _values, result)
        result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
      
    result
end

#_reduce_32(val, _values, result) ⇒ Object



471
472
473
474
# File 'lib/nokogiri/css/generated_parser.rb', line 471

def _reduce_32(val, _values, result)
 result = [val.first, val.last] 
    result
end

#_reduce_33(val, _values, result) ⇒ Object



476
477
478
479
# File 'lib/nokogiri/css/generated_parser.rb', line 476

def _reduce_33(val, _values, result)
 result = [val.first, val.last] 
    result
end

#_reduce_34(val, _values, result) ⇒ Object



481
482
483
484
# File 'lib/nokogiri/css/generated_parser.rb', line 481

def _reduce_34(val, _values, result)
 result = [val.first, val.last] 
    result
end

#_reduce_37(val, _values, result) ⇒ Object

reduce 36 omitted



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/nokogiri/css/generated_parser.rb', line 490

def _reduce_37(val, _values, result)
        if val[0] == 'even'
          val = ["2","n","+","0"]
          result = Node.new(:AN_PLUS_B, val)
        elsif val[0] == 'odd'
          val = ["2","n","+","1"]
          result = Node.new(:AN_PLUS_B, val)
        else
          # This is not CSS standard.  It allows us to support this:
          # assert_xpath("//a[foo(., @href)]", @parser.parse('a:foo(@href)'))
          # assert_xpath("//a[foo(., @a, b)]", @parser.parse('a:foo(@a, b)'))
          # assert_xpath("//a[foo(., a, 10)]", @parser.parse('a:foo(a, 10)'))
          result = val
        end
      
    result
end

#_reduce_38(val, _values, result) ⇒ Object



508
509
510
511
512
513
514
515
516
# File 'lib/nokogiri/css/generated_parser.rb', line 508

def _reduce_38(val, _values, result)
        if val[1] == 'n'
          result = Node.new(:AN_PLUS_B, val)
        else
          raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
        end
      
    result
end

#_reduce_39(val, _values, result) ⇒ Object



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/nokogiri/css/generated_parser.rb', line 518

def _reduce_39(val, _values, result)
               # n+3, -n+3
        if val[0] == 'n'
          val.unshift("1")
          result = Node.new(:AN_PLUS_B, val)
        elsif val[0] == '-n'
          val[0] = 'n'
          val.unshift("-1")
          result = Node.new(:AN_PLUS_B, val)
        else
          raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
        end
      
    result
end

#_reduce_4(val, _values, result) ⇒ Object



297
298
299
300
# File 'lib/nokogiri/css/generated_parser.rb', line 297

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

#_reduce_40(val, _values, result) ⇒ Object



534
535
536
537
538
539
540
541
542
543
544
# File 'lib/nokogiri/css/generated_parser.rb', line 534

def _reduce_40(val, _values, result)
        if val[1] == 'n'
          val << "+"
          val << "0"
          result = Node.new(:AN_PLUS_B, val)
        else
          raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
        end
      
    result
end

#_reduce_41(val, _values, result) ⇒ Object



546
547
548
549
550
# File 'lib/nokogiri/css/generated_parser.rb', line 546

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

#_reduce_42(val, _values, result) ⇒ Object



552
553
554
555
# File 'lib/nokogiri/css/generated_parser.rb', line 552

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

#_reduce_45(val, _values, result) ⇒ Object

reduce 44 omitted



561
562
563
564
565
# File 'lib/nokogiri/css/generated_parser.rb', line 561

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

#_reduce_46(val, _values, result) ⇒ Object



567
568
569
570
571
# File 'lib/nokogiri/css/generated_parser.rb', line 567

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

#_reduce_47(val, _values, result) ⇒ Object



573
574
575
576
577
# File 'lib/nokogiri/css/generated_parser.rb', line 573

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

#_reduce_48(val, _values, result) ⇒ Object



579
580
581
582
583
# File 'lib/nokogiri/css/generated_parser.rb', line 579

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

#_reduce_5(val, _values, result) ⇒ Object



302
303
304
305
# File 'lib/nokogiri/css/generated_parser.rb', line 302

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

#_reduce_53(val, _values, result) ⇒ Object

reduce 52 omitted



593
594
595
596
# File 'lib/nokogiri/css/generated_parser.rb', line 593

def _reduce_53(val, _values, result)
 result = Node.new(:ID, val) 
    result
end

#_reduce_54(val, _values, result) ⇒ Object



598
599
600
601
# File 'lib/nokogiri/css/generated_parser.rb', line 598

def _reduce_54(val, _values, result)
 result = [val.first, val[1]] 
    result
end

#_reduce_55(val, _values, result) ⇒ Object



603
604
605
606
# File 'lib/nokogiri/css/generated_parser.rb', line 603

def _reduce_55(val, _values, result)
 result = [val.first, val[1]] 
    result
end

#_reduce_57(val, _values, result) ⇒ Object

reduce 56 omitted



610
611
612
613
# File 'lib/nokogiri/css/generated_parser.rb', line 610

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

#_reduce_58(val, _values, result) ⇒ Object



615
616
617
618
# File 'lib/nokogiri/css/generated_parser.rb', line 615

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

#_reduce_59(val, _values, result) ⇒ Object



620
621
622
623
# File 'lib/nokogiri/css/generated_parser.rb', line 620

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

#_reduce_6(val, _values, result) ⇒ Object



307
308
309
310
# File 'lib/nokogiri/css/generated_parser.rb', line 307

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

#_reduce_60(val, _values, result) ⇒ Object



625
626
627
628
# File 'lib/nokogiri/css/generated_parser.rb', line 625

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

#_reduce_61(val, _values, result) ⇒ Object



630
631
632
633
# File 'lib/nokogiri/css/generated_parser.rb', line 630

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

#_reduce_62(val, _values, result) ⇒ Object



635
636
637
638
# File 'lib/nokogiri/css/generated_parser.rb', line 635

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

#_reduce_63(val, _values, result) ⇒ Object



640
641
642
643
# File 'lib/nokogiri/css/generated_parser.rb', line 640

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

#_reduce_64(val, _values, result) ⇒ Object



645
646
647
648
649
# File 'lib/nokogiri/css/generated_parser.rb', line 645

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

#_reduce_7(val, _values, result) ⇒ Object



312
313
314
315
# File 'lib/nokogiri/css/generated_parser.rb', line 312

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

#_reduce_8(val, _values, result) ⇒ Object



317
318
319
320
# File 'lib/nokogiri/css/generated_parser.rb', line 317

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

#_reduce_9(val, _values, result) ⇒ Object



322
323
324
325
326
327
328
329
330
# File 'lib/nokogiri/css/generated_parser.rb', line 322

def _reduce_9(val, _values, result)
        result =  if val[1].nil?
                    val.first
                  else
                    Node.new(:CONDITIONAL_SELECTOR, [val.first, val[1]])
                  end
      
    result
end

#_reduce_none(val, _values, result) ⇒ Object

reduce 65 omitted



653
654
655
# File 'lib/nokogiri/css/generated_parser.rb', line 653

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