RbYAML 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. data/lib/rbyaml.rb +14 -256
  2. data/lib/rbyaml.rb.~1.2.~ +383 -0
  3. data/lib/rbyaml/composer.rb +9 -11
  4. data/lib/rbyaml/{composer.rb.~1.2.~ → composer.rb.~1.3.~} +28 -25
  5. data/lib/rbyaml/constants.rb +95 -0
  6. data/lib/rbyaml/constructor.rb +180 -89
  7. data/lib/rbyaml/{constructor.rb.~1.2.~ → constructor.rb.~1.9.~} +137 -95
  8. data/lib/rbyaml/dumper.rb +12 -9
  9. data/lib/rbyaml/dumper.rb.~1.3.~ +36 -0
  10. data/lib/rbyaml/emitter.rb +14 -28
  11. data/lib/rbyaml/{emitter.rb.~1.2.~ → emitter.rb.~1.6.~} +22 -33
  12. data/lib/rbyaml/error.rb +4 -57
  13. data/lib/rbyaml/error.rb.~1.2.~ +75 -0
  14. data/lib/rbyaml/events.rb +8 -14
  15. data/lib/rbyaml/{events.rb.~1.2.~ → events.rb.~1.4.~} +29 -6
  16. data/lib/rbyaml/nodes.rb +5 -5
  17. data/lib/rbyaml/{nodes.rb.~1.2.~ → nodes.rb.~1.3.~} +13 -9
  18. data/lib/rbyaml/parser.rb +70 -108
  19. data/lib/rbyaml/parser.rb.~1.4.~ +632 -0
  20. data/lib/rbyaml/representer.rb +19 -157
  21. data/lib/rbyaml/representer.rb.old +317 -0
  22. data/lib/rbyaml/{representer.rb.~1.2.~ → representer.rb.~1.5.~} +60 -26
  23. data/lib/rbyaml/resolver.rb +6 -6
  24. data/lib/rbyaml/{resolver.rb.~1.1.~ → resolver.rb.~1.6.~} +20 -20
  25. data/lib/rbyaml/rubytypes.rb +391 -0
  26. data/lib/rbyaml/scanner.rb +123 -225
  27. data/lib/rbyaml/{scanner.rb.~1.2.~ → scanner.rb.~1.5.~} +466 -378
  28. data/lib/rbyaml/serializer.rb +9 -9
  29. data/lib/rbyaml/{serializer.rb.~1.2.~ → serializer.rb.~1.4.~} +19 -17
  30. data/lib/rbyaml/stream.rb +48 -0
  31. data/lib/rbyaml/tag.rb +72 -0
  32. data/lib/rbyaml/tokens.rb +22 -16
  33. data/lib/rbyaml/{tokens.rb.~1.2.~ → tokens.rb.~1.3.~} +44 -4
  34. data/lib/rbyaml/types.rb +146 -0
  35. data/lib/rbyaml/util.rb.~1.3.~ +38 -0
  36. data/lib/rbyaml/yaml.rb +22 -32
  37. data/lib/rbyaml/{yaml.rb.~1.2.~ → yaml.rb.~1.5.~} +17 -17
  38. data/test/load_one.rb +6 -0
  39. data/test/load_one_yaml.rb +6 -0
  40. data/test/output_events.rb +9 -0
  41. data/test/test_add_ctor.rb +51 -0
  42. data/test/test_add_ctor.rb.~1.1.~ +30 -0
  43. data/test/test_bm.rb +2 -2
  44. data/test/test_bm.rb.~1.1.~ +28 -0
  45. data/test/test_gems.rb +10 -0
  46. data/test/test_one.rb.~1.1.~ +5 -0
  47. data/test/test_one_syck.rb +5 -0
  48. data/test/test_rbyaml.rb +63 -32
  49. data/test/test_rbyaml.rb.~1.6.~ +59 -0
  50. data/test/{test_rbyaml.rb.~1.2.~ → test_rbyaml_old.rb} +13 -4
  51. data/test/test_time_events.rb +24 -0
  52. data/test/test_time_nodes.rb +24 -0
  53. data/test/test_time_tokens.rb +24 -0
  54. data/test/yaml/gems_new.yml +147456 -0
  55. data/test/yaml/test1.rb +8 -0
  56. data/test/yaml/test10.rb +14 -0
  57. data/test/yaml/test11.rb +13 -0
  58. data/test/yaml/test12.rb +9 -0
  59. data/test/yaml/test13.rb +9 -0
  60. data/test/yaml/test14.rb +13 -0
  61. data/test/yaml/test15.rb +12 -0
  62. data/test/yaml/test16.rb +11 -0
  63. data/test/yaml/test16.rb.~1.1.~ +11 -0
  64. data/test/yaml/test17.rb +10 -0
  65. data/test/yaml/test18.rb +13 -0
  66. data/test/yaml/test19.rb +9 -0
  67. data/test/yaml/test19.yml +1 -1
  68. data/test/yaml/test2.rb +8 -0
  69. data/test/yaml/test20.rb +11 -0
  70. data/test/yaml/test20.rb.~1.1.~ +9 -0
  71. data/test/yaml/test20.yml +1 -1
  72. data/test/yaml/test3.rb +13 -0
  73. data/test/yaml/test4.rb +13 -0
  74. data/test/yaml/test5.rb +8 -0
  75. data/test/yaml/test6.rb +10 -0
  76. data/test/yaml/test7.rb +15 -0
  77. data/test/yaml/test8.rb +15 -0
  78. data/test/yaml/test9.rb +13 -0
  79. metadata +61 -16
  80. data/lib/rbyaml/dumper.rb.~1.2.~ +0 -43
  81. data/lib/rbyaml/parser.rb.~1.2.~ +0 -494
@@ -26,9 +26,10 @@
26
26
  require 'rbyaml/util'
27
27
  require 'rbyaml/error'
28
28
  require 'rbyaml/tokens'
29
+ require 'rbyaml/constants'
29
30
 
30
31
  module RbYAML
31
- class ScannerError < MarkedYAMLError
32
+ class ScannerError < YAMLError
32
33
  end
33
34
  class ReaderError < YAMLError
34
35
  def initialize(name, position, character, encoding, reason)
@@ -48,10 +49,10 @@ module RbYAML
48
49
  end
49
50
  end
50
51
 
51
- SimpleKey = Struct.new(:token_number, :required, :index, :line, :column, :mark)
52
+ SimpleKey = Struct.new(:token_number, :required, :column)
52
53
 
53
54
  class Scanner
54
- attr_reader :column, :stream, :stream_pointer, :eof, :buffer, :pointer, :index, :line
55
+ attr_reader :column, :stream, :stream_pointer, :eof, :buffer, :pointer
55
56
  def initialize(stream)
56
57
  # Had we reached the end of the stream?
57
58
  @done = false
@@ -185,8 +186,6 @@ module RbYAML
185
186
  update(1) unless @pointer1 < @buffer_length
186
187
  end
187
188
 
188
- LINE_BR = "\n\x85"
189
-
190
189
  def forward1
191
190
  update(2) unless @pointer1+1 < @buffer_length
192
191
  buff = @buffer[@pointer...@pointer1+1]
@@ -241,7 +240,6 @@ module RbYAML
241
240
  @pointer1 += 6
242
241
  end
243
242
 
244
- LINE_BR_REG = /[\n\x85]|(?:\r[^\n])/
245
243
  def forwardn(length)
246
244
  update(length + 1) unless @pointer1+length < @buffer_length
247
245
  buff = @buffer[@pointer...@pointer+length]
@@ -251,17 +249,8 @@ module RbYAML
251
249
  @pointer1 += length
252
250
  end
253
251
 
254
- def get_mark
255
- if @stream.nil?
256
- Mark.new(@name,@column,@buffer,@pointer)
257
- else
258
- Mark.new(@name,@column,nil,nil)
259
- end
260
- end
261
-
262
- NON_PRINTABLE = /[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\xFF]/
263
252
  def check_printable(data)
264
- if NON_PRINTABLE =~ data
253
+ if NON_PRINTABLE_RE =~ data
265
254
  position = @buffer.length-@pointer+($~.offset(0)[0])
266
255
  raise ReaderError.new(@name, position, $&,"unicode","special characters are not allowed"),"special characters are not allowed"
267
256
  end
@@ -341,10 +330,6 @@ module RbYAML
341
330
  @tokens.empty? || next_possible_simple_key == @tokens_taken
342
331
  end
343
332
 
344
- ENDING = /^---[\0 \t\r\n\x85]$/
345
- START = /^\.\.\.[\0 \t\r\n\x85]$/
346
- NULL_OR_OTHER = "\0 \t\r\n\x85"
347
- BEG = /^([^\0 \t\r\n\x85\-?:,\[\]{}#&*!|>'"%@`]|([\-?:][^\0 \t\r\n\x85]))/
348
333
  def fetch_more_tokens
349
334
  # Eat whitespaces and comments until we reach the next token.
350
335
  scan_to_next_token
@@ -381,7 +366,7 @@ module RbYAML
381
366
  when ?>: if @flow_zero: return fetch_folded end
382
367
  end
383
368
  return fetch_plain if BEG =~ prefix(2)
384
- raise ScannerError.new("while scanning for the next token", nil,"found character #{ch.chr}(#{ch}) that cannot start any token",get_mark)
369
+ raise ScannerError.new("while scanning for the next token","found character #{ch.chr}(#{ch}) that cannot start any token")
385
370
  end
386
371
 
387
372
  # Simple keys treatment.
@@ -399,7 +384,7 @@ module RbYAML
399
384
  # ALIAS, ANCHOR, TAG, SCALAR(flow), '[', and '{'.
400
385
  # The next token might be a simple key. Let's save it's number and
401
386
  # position.
402
- @possible_simple_keys[@flow_level] = SimpleKey.new(@tokens_taken+@tokens.length, @flow_zero && @indent == @column,index,line,column,get_mark) if @allow_simple_key
387
+ @possible_simple_keys[@flow_level] = SimpleKey.new(@tokens_taken+@tokens.length, @flow_zero && @indent == @column,column) if @allow_simple_key
403
388
  end
404
389
 
405
390
  # Indentation functions.
@@ -421,17 +406,16 @@ module RbYAML
421
406
  return nil if !@flow_zero
422
407
  # In block context, we may need to issue the BLOCK-END tokens.
423
408
  while @indent > col
424
- mark = get_mark
425
409
  @indent = @indents.pop
426
- @tokens << BlockEndToken.new(mark, mark)
410
+ @tokens << BLOCK_END
427
411
  end
428
412
  end
429
413
 
430
- def add_indent(column)
414
+ def add_indent(col)
431
415
  # Check if we need to increase indentation.
432
- if @indent < column
416
+ if @indent < col
433
417
  @indents << @indent
434
- @indent = column
418
+ @indent = col
435
419
  return true
436
420
  end
437
421
  return false
@@ -443,9 +427,8 @@ module RbYAML
443
427
  # We always add STREAM-START as the first token and STREAM-END as the
444
428
  # last token.
445
429
  # Read the token.
446
- mark = get_mark
447
430
  # Add STREAM-START.
448
- @tokens << StreamStartToken.new(mark, mark, @encoding)
431
+ @tokens << STREAM_START
449
432
  end
450
433
 
451
434
 
@@ -456,9 +439,8 @@ module RbYAML
456
439
  @allow_simple_key = false
457
440
  @possible_simple_keys = {}
458
441
  # Read the token.
459
- mark = get_mark
460
442
  # Add STREAM-END.
461
- @tokens << StreamEndToken.new(mark, mark)
443
+ @tokens << STREAM_END
462
444
  # The stream is finished.
463
445
  @done = true
464
446
  end
@@ -473,11 +455,11 @@ module RbYAML
473
455
  end
474
456
 
475
457
  def fetch_document_start
476
- fetch_document_indicator(DocumentStartToken)
458
+ fetch_document_indicator(DOCUMENT_START)
477
459
  end
478
460
 
479
461
  def fetch_document_end
480
- fetch_document_indicator(DocumentEndToken)
462
+ fetch_document_indicator(DOCUMENT_END)
481
463
  end
482
464
 
483
465
  def fetch_document_indicator(token)
@@ -487,18 +469,16 @@ module RbYAML
487
469
  # after '---'.
488
470
  @allow_simple_key = false
489
471
  # Add DOCUMENT-START or DOCUMENT-END.
490
- start_mark = get_mark
491
472
  forward3
492
- end_mark = get_mark
493
- @tokens << token.new(start_mark, end_mark)
473
+ @tokens << token
494
474
  end
495
475
 
496
476
  def fetch_flow_sequence_start
497
- fetch_flow_collection_start(FlowSequenceStartToken)
477
+ fetch_flow_collection_start(FLOW_SEQUENCE_START)
498
478
  end
499
479
 
500
480
  def fetch_flow_mapping_start
501
- fetch_flow_collection_start(FlowMappingStartToken)
481
+ fetch_flow_collection_start(FLOW_MAPPING_START)
502
482
  end
503
483
 
504
484
  def fetch_flow_collection_start(token)
@@ -510,18 +490,16 @@ module RbYAML
510
490
  # Simple keys are allowed after '[' and '{'.
511
491
  @allow_simple_key = true
512
492
  # Add FLOW-SEQUENCE-START or FLOW-MAPPING-START.
513
- start_mark = get_mark
514
493
  forward1
515
- end_mark = get_mark
516
- @tokens << token.new(start_mark, end_mark)
494
+ @tokens << token
517
495
  end
518
496
 
519
497
  def fetch_flow_sequence_end
520
- fetch_flow_collection_end(FlowSequenceEndToken)
498
+ fetch_flow_collection_end(FLOW_SEQUENCE_END)
521
499
  end
522
500
 
523
501
  def fetch_flow_mapping_end
524
- fetch_flow_collection_end(FlowMappingEndToken)
502
+ fetch_flow_collection_end(FLOW_MAPPING_END)
525
503
  end
526
504
 
527
505
  def fetch_flow_collection_end(token)
@@ -533,30 +511,25 @@ module RbYAML
533
511
  # No simple keys after ']' or '}'.
534
512
  @allow_simple_key = false
535
513
  # Add FLOW-SEQUENCE-END or FLOW-MAPPING-END.
536
- start_mark = get_mark
537
514
  forward1
538
- end_mark = get_mark
539
- @tokens << token.new(start_mark, end_mark)
515
+ @tokens << token
540
516
  end
541
517
 
542
518
  def fetch_flow_entry
543
519
  # Simple keys are allowed after ','.
544
520
  @allow_simple_key = true
545
521
  # Add FLOW-ENTRY.
546
- start_mark = get_mark
547
522
  forward1
548
- end_mark = get_mark
549
- @tokens << FlowEntryToken.new(start_mark, end_mark)
523
+ @tokens << FLOW_ENTRY
550
524
  end
551
525
 
552
526
  def fetch_block_entry
553
527
  # Block context needs additional checks.
554
528
  if @flow_zero
555
- raise ScannerError.new(nil,nil,"sequence entries are not allowed here",get_mark) if !@allow_simple_key
529
+ raise ScannerError.new(nil,"sequence entries are not allowed here") if !@allow_simple_key
556
530
  # We may need to add BLOCK-SEQUENCE-START.
557
531
  if add_indent(column)
558
- mark = get_mark
559
- @tokens << BlockSequenceStartToken.new(mark, mark)
532
+ @tokens << BLOCK_SEQUENCE_START
560
533
  end
561
534
  # It's an error for the block entry to occur in the flow context,
562
535
  # but we let the parser detect this.
@@ -564,30 +537,25 @@ module RbYAML
564
537
  # Simple keys are allowed after '-'.
565
538
  @allow_simple_key = true
566
539
  # Add BLOCK-ENTRY.
567
- start_mark = get_mark
568
540
  forward1
569
- end_mark = get_mark
570
- @tokens << BlockEntryToken.new(start_mark, end_mark)
541
+ @tokens << BLOCK_ENTRY
571
542
  end
572
543
 
573
544
  def fetch_key
574
545
  # Block context needs additional checks.
575
546
  if @flow_zero
576
547
  # Are we allowed to start a key (not nessesary a simple)?
577
- raise ScannerError.new(nil,nil,"mapping keys are not allowed here",get_mark) if !@allow_simple_key
548
+ raise ScannerError.new(nil,"mapping keys are not allowed here") if !@allow_simple_key
578
549
  # We may need to add BLOCK-MAPPING-START.
579
550
  if add_indent(column)
580
- mark = get_mark
581
- @tokens << BlockMappingStartToken.new(mark, mark)
551
+ @tokens << BLOCK_MAPPING_START
582
552
  end
583
553
  end
584
554
  # Simple keys are allowed after '?' in the block context.
585
555
  @allow_simple_key = @flow_zero
586
556
  # Add KEY.
587
- start_mark = get_mark
588
557
  forward1
589
- end_mark = get_mark
590
- @tokens << KeyToken.new(start_mark, end_mark)
558
+ @tokens << KEY
591
559
  end
592
560
 
593
561
  def fetch_value
@@ -600,7 +568,7 @@ module RbYAML
600
568
  if @flow_zero
601
569
  # We are allowed to start a complex value if and only if
602
570
  # we can start a simple key.
603
- raise ScannerError.new(nil,nil,"mapping values are not allowed here",get_mark) if !@allow_simple_key
571
+ raise ScannerError.new(nil,"mapping values are not allowed here") if !@allow_simple_key
604
572
  # Simple keys are allowed after ':' in the block context.
605
573
  @allow_simple_key = true
606
574
  end
@@ -610,18 +578,16 @@ module RbYAML
610
578
 
611
579
  # If this key starts a new block mapping, we need to add
612
580
  # BLOCK-MAPPING-START.
613
- se = (@flow_zero && add_indent(key.column)) ? [BlockMappingStartToken.new(key.mark, key.mark)] : []
614
- se << KeyToken.new(key.mark, key.mark)
581
+ se = (@flow_zero && add_indent(key.column)) ? [BLOCK_MAPPING_START] : []
582
+ se << KEY
615
583
  @tokens.insert(key.token_number-@tokens_taken,*se)
616
584
  # There cannot be two simple keys one after another.
617
585
  @allow_simple_key = false
618
586
  # It must be a part of a complex key.
619
587
  end
620
588
  # Add VALUE.
621
- start_mark = get_mark
622
589
  forward1
623
- end_mark = get_mark
624
- @tokens << ValueToken.new(start_mark, end_mark)
590
+ @tokens << VALUE
625
591
  end
626
592
 
627
593
  def fetch_alias
@@ -696,7 +662,6 @@ module RbYAML
696
662
 
697
663
 
698
664
  # Scanners.
699
- NULL_OR_LINEBR = "\0\r\n\x85"
700
665
  def scan_to_next_token
701
666
  # We ignore spaces, line breaks and comments.
702
667
  # If we find a line break in the block context, we set the flag
@@ -713,15 +678,12 @@ module RbYAML
713
678
  # `unwind_indent` before issuing BLOCK-END.
714
679
  # Scanners for block, flow, and plain scalars need to be modified.
715
680
  while true
716
- peek_0 = peek0
717
- while peek_0 == 32
681
+ while peek0 == 32
718
682
  forward1
719
- peek_0 = peek0
720
683
  end
721
- if peek_0 == ?#
684
+ if peek0 == ?#
722
685
  while !NULL_OR_LINEBR.include?(peek0)
723
686
  forward1
724
- peek_0 = peek0
725
687
  end
726
688
  end
727
689
 
@@ -735,60 +697,53 @@ module RbYAML
735
697
 
736
698
  def scan_directive
737
699
  # See the specification for details.
738
- start_mark = get_mark
739
700
  forward1
740
- name = scan_directive_name(start_mark)
701
+ name = scan_directive_name
741
702
  value = nil
742
703
  if name == "YAML"
743
- value = scan_yaml_directive_value(start_mark)
744
- end_mark = get_mark
704
+ value = scan_yaml_directive_value
745
705
  elsif name == "TAG"
746
- value = scan_tag_directive_value(start_mark)
747
- end_mark = get_mark
706
+ value = scan_tag_directive_value
748
707
  else
749
- end_mark = get_mark
750
708
  forward1 while !NULL_OR_LINEBR.include?(peek0)
751
709
  end
752
- scan_directive_ignored_line(start_mark)
753
- DirectiveToken.new(name, value, start_mark, end_mark)
710
+ scan_directive_ignored_line
711
+ DirectiveToken.new(name, value)
754
712
  end
755
713
 
756
- ALPHA_REG = /[-0-9A-Za-z_]/
757
- NULL_BL_LINEBR = "\0 \r\n\x85"
758
- NULL_BL_T_LINEBR = "\0 \t\r\n\x85"
759
- def scan_directive_name(start_mark)
714
+ def scan_directive_name
760
715
  # See the specification for details.
761
716
  length = 0
762
717
  ch = peek(length)
763
- zlen = false
718
+ zlen = true
764
719
  while ALPHA_REG =~ ch.chr
765
- zlen = true
720
+ zlen = false
766
721
  length += 1
767
722
  ch = peek(length)
768
723
  end
769
- raise ScannerError.new("while scanning a directive", start_mark,"expected alphabetic or numeric character, but found #{ch.to_s}",get_mark) if zlen
724
+ raise ScannerError.new("while scanning a directive","expected alphabetic or numeric character, but found #{ch.to_s}") if zlen
770
725
  value = prefix(length)
771
726
  forward(length)
772
727
  ch = peek0
773
- raise ScannerError.new("while scanning a directive", start_mark,"expected alphabetic or numeric character, but found #{ch.to_s}",get_mark) if !NULL_BL_LINEBR.include?(ch)
728
+ raise ScannerError.new("while scanning a directive","expected alphabetic or numeric character, but found #{ch.to_s}") if !NULL_BL_LINEBR.include?(ch)
774
729
  value
775
730
  end
776
731
 
777
- def scan_yaml_directive_value(start_mark)
732
+ def scan_yaml_directive_value
778
733
  # See the specification for details.
779
734
  forward1 while peek0 == 32
780
- major = scan_yaml_directive_number(start_mark)
781
- raise ScannerError.new("while scanning a directive", start_mark,"expected a digit or '.', but found #{peek.to_s}",get_mark) if peek0 != ?.
735
+ major = scan_yaml_directive_number
736
+ raise ScannerError.new("while scanning a directive","expected a digit or '.', but found #{peek.to_s}") if peek0 != ?.
782
737
  forward1
783
- minor = scan_yaml_directive_number(start_mark)
784
- raise ScannerError.new("while scanning a directive", start_mark,"expected a digit or ' ', but found #{peek.to_s}",get_mark) if !NULL_BL_LINEBR.include?(peek0)
738
+ minor = scan_yaml_directive_number
739
+ raise ScannerError.new("while scanning a directive","expected a digit or ' ', but found #{peek.to_s}") if !NULL_BL_LINEBR.include?(peek0)
785
740
  [major, minor]
786
741
  end
787
742
 
788
- def scan_yaml_directive_number(start_mark)
743
+ def scan_yaml_directive_number
789
744
  # See the specification for details.
790
745
  ch = peek0
791
- raise ScannerError.new("while scanning a directive", start_mark,"expected a digit, but found #{ch.to_s}",get_mark) if !(ch.__is_ascii_num)
746
+ raise ScannerError.new("while scanning a directive","expected a digit, but found #{ch.to_s}") if !(ch.__is_ascii_num)
792
747
  length = 0
793
748
  length += 1 while (peek(length).__is_ascii_num)
794
749
  value = prefix(length)
@@ -796,42 +751,40 @@ module RbYAML
796
751
  value
797
752
  end
798
753
 
799
- def scan_tag_directive_value(start_mark)
754
+ def scan_tag_directive_value
800
755
  # See the specification for details.
801
756
  forward1 while peek0 == 32
802
- handle = scan_tag_directive_handle(start_mark)
757
+ handle = scan_tag_directive_handle
803
758
  forward1 while peek0 == 32
804
- prefix = scan_tag_directive_prefix(start_mark)
759
+ prefix = scan_tag_directive_prefix
805
760
  [handle, prefix]
806
761
  end
807
762
 
808
- def scan_tag_directive_handle(start_mark)
763
+ def scan_tag_directive_handle
809
764
  # See the specification for details.
810
- value = scan_tag_handle("directive", start_mark)
811
- raise ScannerError.new("while scanning a directive", start_mark,"expected ' ', but found #{peek0}",get_mark()) if peek0 != 32
765
+ value = scan_tag_handle("directive")
766
+ raise ScannerError.new("while scanning a directive","expected ' ', but found #{peek0}") if peek0 != 32
812
767
  value
813
768
  end
814
769
 
815
- def scan_tag_directive_prefix(start_mark)
770
+ def scan_tag_directive_prefix
816
771
  # See the specification for details.
817
- value = scan_tag_uri("directive", start_mark)
818
- raise ScannerError.new("while scanning a directive", start_mark,"expected ' ', but found #{peek0}",get_mark()) if !NULL_BL_LINEBR.include?(peek0)
772
+ value = scan_tag_uri("directive")
773
+ raise ScannerError.new("while scanning a directive","expected ' ', but found #{peek0}") if !NULL_BL_LINEBR.include?(peek0)
819
774
  value
820
775
  end
821
776
 
822
- def scan_directive_ignored_line(start_mark)
777
+ def scan_directive_ignored_line
823
778
  # See the specification for details.
824
779
  forward1 while peek0 == 32
825
780
  if peek0 == ?#
826
781
  forward1 while !NULL_OR_LINEBR.include?(peek0)
827
782
  end
828
783
  ch = peek0
829
- raise ScannerError.new("while scanning a directive", start_mark,"expected a comment or a line break, but found #{peek0.to_s}",get_mark()) if !NULL_OR_LINEBR.include?(peek0)
784
+ raise ScannerError.new("while scanning a directive","expected a comment or a line break, but found #{peek0.to_s}") if !NULL_OR_LINEBR.include?(peek0)
830
785
  scan_line_break
831
786
  end
832
787
 
833
- NON_ALPHA = /[^-0-9A-Za-z_]/
834
- NON_ALPHA_OR_NUM = "\0 \t\r\n\x85?:,]}%@`"
835
788
  def scan_anchor(token)
836
789
  # The specification does not restrict characters for anchors and
837
790
  # aliases. This may lead to problems, for instance, the document:
@@ -841,9 +794,7 @@ module RbYAML
841
794
  # and
842
795
  # [ *alias , "value" ]
843
796
  # Therefore we restrict aliases to numbers and ASCII letters.
844
- start_mark = get_mark
845
- indicator = peek0
846
- name = (indicator == ?*) ? "alias":"anchor"
797
+ name = (peek0 == ?*) ? "alias":"anchor"
847
798
  forward1
848
799
  length = 0
849
800
  chunk_size = 16
@@ -854,26 +805,23 @@ module RbYAML
854
805
  end
855
806
  chunk_size += 16
856
807
  end
857
- raise ScannerError.new("while scanning an #{name}", start_mark,"expected alphabetic or numeric character, but found something else...",get_mark) if length==0
808
+ raise ScannerError.new("while scanning an #{name}","expected alphabetic or numeric character, but found something else...") if length==0
858
809
  value = prefix(length)
859
810
  forward(length)
860
811
  if !NON_ALPHA_OR_NUM.include?(peek0)
861
- raise ScannerError.new("while scanning an #{name}", start_mark,"expected alphabetic or numeric character, but found #{peek0}",get_mark)
812
+ raise ScannerError.new("while scanning an #{name}","expected alphabetic or numeric character, but found #{peek0}")
862
813
  end
863
- end_mark = get_mark
864
- token.new(value, start_mark, end_mark)
814
+ token.new(value)
865
815
  end
866
816
 
867
- NULL_T_BL_LINEBR = "\0 \t\r\n\x85"
868
817
  def scan_tag
869
818
  # See the specification for details.
870
- start_mark = get_mark
871
819
  ch = peek1
872
820
  if ch == ?<
873
821
  handle = nil
874
822
  forward2
875
- suffix = scan_tag_uri("tag", start_mark)
876
- raise ScannerError.new("while parsing a tag", start_mark,"expected '>', but found #{peek.to_s}",get_mark) if peek0 != ?>
823
+ suffix = scan_tag_uri("tag")
824
+ raise ScannerError.new("while parsing a tag","expected '>', but found #{peek.to_s}") if peek0 != ?>
877
825
  forward1
878
826
  elsif NULL_T_BL_LINEBR.include?(ch)
879
827
  handle = nil
@@ -892,38 +840,35 @@ module RbYAML
892
840
  end
893
841
  handle = "!"
894
842
  if use_handle
895
- handle = scan_tag_handle("tag", start_mark)
843
+ handle = scan_tag_handle("tag")
896
844
  else
897
845
  handle = "!"
898
846
  forward1
899
847
  end
900
- suffix = scan_tag_uri("tag", start_mark)
848
+ suffix = scan_tag_uri("tag")
901
849
  end
902
- raise ScannerError.new("while scanning a tag",start_mark,"expected ' ', but found #{peek0}",get_mark) if !NULL_BL_LINEBR.include?(peek0)
850
+ raise ScannerError.new("while scanning a tag","expected ' ', but found #{peek0}") if !NULL_BL_LINEBR.include?(peek0)
903
851
  value = [handle, suffix]
904
- end_mark = get_mark
905
- TagToken.new(value, start_mark, end_mark)
852
+ TagToken.new(value)
906
853
  end
907
854
 
908
- BLANK_T = " \t"
909
855
  def scan_block_scalar(style)
910
856
  # See the specification for details.
911
857
  folded = style== ?>
912
858
  chunks = []
913
- start_mark = get_mark
914
859
  # Scan the header.
915
860
  forward1
916
- chomping, increment = scan_block_scalar_indicators(start_mark)
917
- scan_block_scalar_ignored_line(start_mark)
861
+ chomping, increment = scan_block_scalar_indicators
862
+ scan_block_scalar_ignored_line
918
863
  # Determine the indentation level and go to the first non-empty line.
919
864
  min_indent = @indent+1
920
865
  min_indent = 1 if min_indent < 1
921
866
  if increment.nil?
922
- breaks, max_indent, end_mark = scan_block_scalar_indentation
867
+ breaks, max_indent = scan_block_scalar_indentation
923
868
  indent = [min_indent, max_indent].max
924
869
  else
925
870
  indent = min_indent+increment-1
926
- breaks, end_mark = scan_block_scalar_breaks(indent)
871
+ breaks = scan_block_scalar_breaks(indent)
927
872
  end
928
873
  line_break = ''
929
874
  # Scan the inner part of the block scalar.
@@ -935,12 +880,12 @@ module RbYAML
935
880
  chunks << prefix(length)
936
881
  forward(length)
937
882
  line_break = scan_line_break
938
- breaks, end_mark = scan_block_scalar_breaks(indent)
883
+ breaks = scan_block_scalar_breaks(indent)
939
884
  if column == indent && peek0 != 0
940
885
  # Unfortunately, folding rules are ambiguous.
941
886
  #
942
887
  # This is the folding according to the specification:
943
- if folded && line_break == ?\n && leading_non_space && !BLANK_T.include?(peek0)
888
+ if folded && line_break == "\n" && leading_non_space && !BLANK_T.include?(peek0)
944
889
  chunks << ' ' if breaks.empty?
945
890
  else
946
891
  chunks << line_break
@@ -968,11 +913,10 @@ module RbYAML
968
913
  end
969
914
 
970
915
  # We are done.
971
- ScalarToken.new(chunks.to_s, false, start_mark, end_mark,style)
916
+ ScalarToken.new(chunks.to_s, false, style)
972
917
  end
973
918
 
974
- PLUS_MIN = /[+-]/
975
- def scan_block_scalar_indicators(start_mark)
919
+ def scan_block_scalar_indicators
976
920
  # See the specification for details.
977
921
  chomping = nil
978
922
  increment = nil
@@ -982,13 +926,13 @@ module RbYAML
982
926
  forward1
983
927
  ch = peek0
984
928
  if ch.__is_ascii_num
985
- increment = ch.to_i
986
- raise ScannerError.new("while scanning a block scalar", start_mark,"expected indentation indicator in the range 1-9, but found 0",get_mark) if increment == 0
929
+ increment = ch.chr.to_i
930
+ raise ScannerError.new("while scanning a block scalar","expected indentation indicator in the range 1-9, but found 0") if increment == 0
987
931
  forward1
988
932
  end
989
933
  elsif ch.__is_ascii_num
990
- increment = ch
991
- raise ScannerError.new("while scanning a block scalar", start_mark,"expected indentation indicator in the range 1-9, but found 0",get_mark) if increment == 0
934
+ increment = ch.chr.to_i
935
+ raise ScannerError.new("while scanning a block scalar","expected indentation indicator in the range 1-9, but found 0") if increment == 0
992
936
  forward1
993
937
  ch = peek0
994
938
  if PLUS_MIN =~ ch.chr
@@ -996,50 +940,44 @@ module RbYAML
996
940
  forward1
997
941
  end
998
942
  end
999
- raise ScannerError.new("while scanning a block scalar", start_mark,"expected chomping or indentation indicators, but found #{peek0}",get_mark) if !NULL_BL_LINEBR.include?(peek0)
943
+ raise ScannerError.new("while scanning a block scalar","expected chomping or indentation indicators, but found #{peek0}") if !NULL_BL_LINEBR.include?(peek0)
1000
944
  [chomping, increment]
1001
945
  end
1002
946
 
1003
- def scan_block_scalar_ignored_line(start_mark)
947
+ def scan_block_scalar_ignored_line
1004
948
  # See the specification for details.
1005
949
  forward1 while peek0 == 32
1006
950
  if peek0 == ?#
1007
951
  forward1 while !NULL_OR_LINEBR.include?(peek0)
1008
952
  end
1009
- raise ScannerError.new("while scanning a block scalar", start_mark,"expected a comment or a line break, but found #{peek0}",get_mark) if !NULL_OR_LINEBR.include?(peek0)
953
+ raise ScannerError.new("while scanning a block scalar","expected a comment or a line break, but found #{peek0}") if !NULL_OR_LINEBR.include?(peek0)
1010
954
  scan_line_break
1011
955
  end
1012
956
 
1013
- BLANK_OR_LINEBR = " \r\n\x85"
1014
957
  def scan_block_scalar_indentation
1015
958
  # See the specification for details.
1016
959
  chunks = []
1017
960
  max_indent = 0
1018
- end_mark = get_mark
1019
961
  while BLANK_OR_LINEBR.include?(peek0)
1020
962
  if peek0 != 32
1021
963
  chunks << scan_line_break
1022
- end_mark = get_mark
1023
964
  else
1024
965
  forward1
1025
966
  max_indent = column if column > max_indent
1026
967
  end
1027
968
  end
1028
- [chunks, max_indent, end_mark]
969
+ [chunks, max_indent]
1029
970
  end
1030
971
 
1031
- FULL_LINEBR = "\r\n\x85"
1032
972
  def scan_block_scalar_breaks(indent)
1033
973
  # See the specification for details.
1034
974
  chunks = []
1035
- end_mark = get_mark
1036
975
  forward1 while @column < indent && peek0 == 32
1037
976
  while FULL_LINEBR.include?(peek0)
1038
977
  chunks << scan_line_break
1039
- end_mark = get_mark
1040
978
  forward1 while @column < indent && peek0 == 32
1041
979
  end
1042
- [chunks, end_mark]
980
+ chunks
1043
981
  end
1044
982
 
1045
983
  def scan_flow_scalar(style)
@@ -1051,45 +989,18 @@ module RbYAML
1051
989
  # that document separators are not included in scalars.
1052
990
  double = style == ?"
1053
991
  chunks = []
1054
- start_mark = get_mark
1055
992
  quote = peek0
1056
993
  forward1
1057
- chunks += scan_flow_scalar_non_spaces(double, start_mark)
994
+ chunks += scan_flow_scalar_non_spaces(double)
1058
995
  while peek0 != quote
1059
- chunks += scan_flow_scalar_spaces(double, start_mark)
1060
- chunks += scan_flow_scalar_non_spaces(double, start_mark)
996
+ chunks += scan_flow_scalar_spaces(double)
997
+ chunks += scan_flow_scalar_non_spaces(double)
1061
998
  end
1062
999
  forward1
1063
- end_mark = get_mark
1064
- ScalarToken.new(chunks.to_s, false, start_mark, end_mark,style)
1000
+ ScalarToken.new(chunks.to_s, false, style)
1065
1001
  end
1066
1002
 
1067
- ESCAPE_REPLACEMENTS = {
1068
- "0" => "\0",
1069
- "a" => "\x07",
1070
- "b" => "\x08",
1071
- "t" => "\x09",
1072
- "\t" => "\x09",
1073
- "n" => "\x0A",
1074
- "v" => "\x0B",
1075
- "f" => "\x0C",
1076
- "r" => "\x0D",
1077
- "e" => "\x1B",
1078
- " " => "\x20",
1079
- '"' => '"',
1080
- "\\" => "\\",
1081
- "N" => "\x85",
1082
- "_" => "\xA0"
1083
- }
1084
-
1085
- ESCAPE_CODES = {
1086
- 'x' => 2
1087
- }
1088
-
1089
- SPACES_AND_STUFF = "'\"\\\0 \t\r\n\x85"
1090
- DOUBLE_ESC = "\"\\"
1091
- NOT_HEXA = /[^0-9A-Fa-f]/
1092
- def scan_flow_scalar_non_spaces(double, start_mark)
1003
+ def scan_flow_scalar_non_spaces(double)
1093
1004
  # See the specification for details.
1094
1005
  chunks = []
1095
1006
  while true
@@ -1109,24 +1020,23 @@ module RbYAML
1109
1020
  elsif double && ch == ?\\
1110
1021
  forward1
1111
1022
  ch = peek0
1112
- if ESCAPE_REPLACEMENTS.member?(ch.chr)
1113
- chunks << ESCAPE_REPLACEMENTS[ch.chr]
1023
+ if UNESCAPES.member?(ch.chr)
1024
+ chunks << UNESCAPES[ch.chr]
1114
1025
  forward1
1115
1026
  elsif ESCAPE_CODES.member?(ch.chr)
1116
1027
  length = ESCAPE_CODES[ch.chr]
1117
1028
  forward1
1118
1029
  if NOT_HEXA =~ prefix(length)
1119
- raise ScannerError.new("while scanning a double-quoted scalar", start_mark,
1120
- "expected escape sequence of #{length} hexdecimal numbers, but found something else: #{prefix(length)}}",get_mark)
1030
+ raise ScannerError.new("while scanning a double-quoted scalar","expected escape sequence of #{length} hexdecimal numbers, but found something else: #{prefix(length)}}")
1121
1031
  end
1122
- code = prefix(length).to_i.to_s(16)
1032
+ code = prefix(length).to_i(16).to_s
1123
1033
  chunks << code
1124
1034
  forward(length)
1125
1035
  elsif FULL_LINEBR.include?(ch)
1126
1036
  scan_line_break
1127
- chunks += scan_flow_scalar_breaks(double, start_mark)
1037
+ chunks += scan_flow_scalar_breaks(double)
1128
1038
  else
1129
- raise ScannerError.new("while scanning a double-quoted scalar", start_mark,"found unknown escape character #{ch}",get_mark)
1039
+ raise ScannerError.new("while scanning a double-quoted scalar","found unknown escape character #{ch}")
1130
1040
  end
1131
1041
  else
1132
1042
  return chunks
@@ -1134,7 +1044,7 @@ module RbYAML
1134
1044
  end
1135
1045
  end
1136
1046
 
1137
- def scan_flow_scalar_spaces(double, start_mark)
1047
+ def scan_flow_scalar_spaces(double)
1138
1048
  # See the specification for details.
1139
1049
  chunks = []
1140
1050
  length = 0
@@ -1143,11 +1053,11 @@ module RbYAML
1143
1053
  forward(length)
1144
1054
  ch = peek0
1145
1055
  if ch == ?\0
1146
- raise ScannerError.new("while scanning a quoted scalar", start_mark,"found unexpected end of stream",get_mark)
1056
+ raise ScannerError.new("while scanning a quoted scalar","found unexpected end of stream")
1147
1057
  elsif FULL_LINEBR.include?(ch)
1148
1058
  line_break = scan_line_break
1149
- breaks = scan_flow_scalar_breaks(double, start_mark)
1150
- if line_break != ?\n
1059
+ breaks = scan_flow_scalar_breaks(double)
1060
+ if line_break != "\n"
1151
1061
  chunks << line_break
1152
1062
  elsif breaks.empty?
1153
1063
  chunks << ' '
@@ -1159,7 +1069,7 @@ module RbYAML
1159
1069
  chunks
1160
1070
  end
1161
1071
 
1162
- def scan_flow_scalar_breaks(double, start_mark)
1072
+ def scan_flow_scalar_breaks(double)
1163
1073
  # See the specification for details.
1164
1074
  chunks = []
1165
1075
  while true
@@ -1167,7 +1077,7 @@ module RbYAML
1167
1077
  # separators.
1168
1078
  prefix = prefix(3)
1169
1079
  if (prefix == "---" || prefix == "...") &&NULL_BL_T_LINEBR.include?(peek3)
1170
- raise ScannerError.new("while scanning a quoted scalar", start_mark,"found unexpected document separator", get_mark)
1080
+ raise ScannerError.new("while scanning a quoted scalar","found unexpected document separator")
1171
1081
  end
1172
1082
  forward1 while BLANK_T.include?(peek0)
1173
1083
  if FULL_LINEBR.include?(peek0)
@@ -1178,11 +1088,6 @@ module RbYAML
1178
1088
  end
1179
1089
  end
1180
1090
 
1181
-
1182
- R_flowzero = /[\0 \t\r\n\x85]|(:[\0 \t\r\n\x28])/
1183
- R_flownonzero = /[\0 \t\r\n\x85\[\]{},:?]/
1184
- S4 = "\0 \t\r\n\x28[]{}"
1185
-
1186
1091
  def scan_plain
1187
1092
  # See the specification for details.
1188
1093
  # We add an additional restriction for the flow context:
@@ -1190,7 +1095,6 @@ module RbYAML
1190
1095
  # We also keep track of the `allow_simple_key` flag here.
1191
1096
  # Indentation rules are loosed for the flow context.
1192
1097
  chunks = []
1193
- end_mark = start_mark = get_mark
1194
1098
  indent = @indent+1
1195
1099
  # We allow zero indentation for scalars, but then we need to check for
1196
1100
  # document separators at the beginning of the line.
@@ -1210,22 +1114,20 @@ module RbYAML
1210
1114
  ch = peek(length)
1211
1115
  if f_nzero && ch == ?: && !S4.include?(peek(length+1))
1212
1116
  forward(length)
1213
- raise ScannerError.new("while scanning a plain scalar",start_mark,"found unexpected ':'",get_mark,"Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.")
1117
+ raise ScannerError.new("while scanning a plain scalar","found unexpected ':'","Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.")
1214
1118
  end
1215
1119
  break if length == 0
1216
1120
  @allow_simple_key = false
1217
1121
  chunks += spaces
1218
1122
  chunks << prefix(length)
1219
1123
  forward(length)
1220
- end_mark = get_mark
1221
- spaces = scan_plain_spaces(indent, start_mark)
1124
+ spaces = scan_plain_spaces(indent)
1222
1125
  break if !spaces || (@flow_zero && @column < indent)
1223
1126
  end
1224
- return ScalarToken.new(chunks.to_s, true, start_mark, end_mark)
1127
+ return ScalarToken.new(chunks.to_s, true)
1225
1128
  end
1226
1129
 
1227
- END_OR_START = /^(---|\.\.\.)[\0 \t\r\n\x85]$/
1228
- def scan_plain_spaces(indent, start_mark)
1130
+ def scan_plain_spaces(indent)
1229
1131
  # See the specification for details.
1230
1132
  # The specification is really confusing about tabs in plain scalars.
1231
1133
  # We just forbid them completely. Do not use tabs in YAML!
@@ -1248,10 +1150,10 @@ module RbYAML
1248
1150
  return if END_OR_START =~ prefix(4)
1249
1151
  end
1250
1152
  end
1251
- if line_break != '\n'
1153
+ if line_break != "\n"
1252
1154
  chunks << line_break
1253
- elsif breaks.empty?
1254
- chunks << ' '
1155
+ elsif breaks.nil? || breaks.empty?
1156
+ chunks << " "
1255
1157
  end
1256
1158
  chunks += breaks
1257
1159
  else
@@ -1261,12 +1163,12 @@ module RbYAML
1261
1163
  end
1262
1164
 
1263
1165
 
1264
- def scan_tag_handle(name, start_mark)
1166
+ def scan_tag_handle(name)
1265
1167
  # See the specification for details.
1266
1168
  # For some strange reasons, the specification does not allow '_' in
1267
1169
  # tag handles. I have allowed it anyway.
1268
1170
  ch = peek0
1269
- raise ScannerError.new("while scanning a #{name}", start_mark,"expected '!', but found #{ch}",get_mark) if ch != ?!
1171
+ raise ScannerError.new("while scanning a #{name}","expected '!', but found #{ch}") if ch != ?!
1270
1172
  length = 1
1271
1173
  ch = peek(length)
1272
1174
  if ch != 32
@@ -1276,7 +1178,7 @@ module RbYAML
1276
1178
  end
1277
1179
  if ch != ?!
1278
1180
  forward(length)
1279
- raise ScannerError.new("while scanning a #{name}", start_mark,"expected '!', but found #{ch}",get_mark)
1181
+ raise ScannerError.new("while scanning a #{name}","expected '!', but found #{ch}")
1280
1182
  end
1281
1183
  length += 1
1282
1184
  end
@@ -1285,8 +1187,7 @@ module RbYAML
1285
1187
  value
1286
1188
  end
1287
1189
 
1288
- STRANGE_CHR = /[\]\[\-';\/?:@&=+$,.!~*()%\w]/
1289
- def scan_tag_uri(name, start_mark)
1190
+ def scan_tag_uri(name)
1290
1191
  # See the specification for details.
1291
1192
  # Note: we do not check if URI is well-formed.
1292
1193
  chunks = []
@@ -1297,7 +1198,7 @@ module RbYAML
1297
1198
  chunks << prefix(length)
1298
1199
  forward(length)
1299
1200
  length = 0
1300
- chunks << scan_uri_escapes(name, start_mark)
1201
+ chunks << scan_uri_escapes(name)
1301
1202
  else
1302
1203
  length += 1
1303
1204
  end
@@ -1306,22 +1207,19 @@ module RbYAML
1306
1207
  if length!=0
1307
1208
  chunks << prefix(length)
1308
1209
  forward(length)
1309
- length = 0
1310
1210
  end
1311
1211
 
1312
- raise ScannerError.new("while parsing a #{name}", start_mark,"expected URI, but found #{ch}",get_mark) if chunks.empty?
1212
+ raise ScannerError.new("while parsing a #{name}","expected URI, but found #{ch}") if chunks.empty?
1313
1213
  chunks.to_s
1314
1214
  end
1315
1215
 
1316
- HEXA_REG = /[0-9A-Fa-f]/
1317
- def scan_uri_escapes(name, start_mark)
1216
+ def scan_uri_escapes(name)
1318
1217
  # See the specification for details.
1319
1218
  bytes = []
1320
- mark = get_mark
1321
1219
  while peek0 == ?%
1322
1220
  forward1
1323
- raise ScannerError.new("while scanning a #{name}", start_mark,"expected URI escape sequence of 2 hexdecimal numbers, but found #{peek1} and #{peek2}",get_mark) if HEXA_REG !~ peek1.chr || HEXA_REG !~ peek2.chr
1324
- bytes << prefix(2).to_i.to_s(16)
1221
+ raise ScannerError.new("while scanning a #{name}","expected URI escape sequence of 2 hexdecimal numbers, but found #{peek1} and #{peek2}") if HEXA_REG !~ peek1.chr || HEXA_REG !~ peek2.chr
1222
+ bytes << prefix(2).to_i(16).to_s
1325
1223
  forward2
1326
1224
  end
1327
1225
  bytes.to_s