RbYAML 0.0.2 → 0.1.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.
- data/README +1 -1
- data/lib/rbyaml/composer.rb +28 -25
- data/lib/rbyaml/composer.rb.~1.2.~ +109 -0
- data/lib/rbyaml/constructor.rb +94 -84
- data/lib/rbyaml/constructor.rb.~1.2.~ +381 -0
- data/lib/rbyaml/dumper.rb +10 -17
- data/lib/rbyaml/dumper.rb.~1.2.~ +43 -0
- data/lib/rbyaml/emitter.rb +13 -26
- data/lib/rbyaml/emitter.rb.~1.2.~ +1116 -0
- data/lib/rbyaml/error.rb +15 -21
- data/lib/rbyaml/events.rb +29 -5
- data/lib/rbyaml/events.rb.~1.2.~ +93 -0
- data/lib/rbyaml/loader.rb +11 -23
- data/lib/rbyaml/loader.rb.~1.2.~ +52 -0
- data/lib/rbyaml/nodes.rb +13 -9
- data/lib/rbyaml/nodes.rb.~1.2.~ +52 -0
- data/lib/rbyaml/parser.rb +481 -343
- data/lib/rbyaml/parser.rb.old +531 -0
- data/lib/rbyaml/parser.rb.~1.2.~ +494 -0
- data/lib/rbyaml/reader.rb.~1.1.1.1.~ +127 -0
- data/lib/rbyaml/representer.rb +26 -17
- data/lib/rbyaml/representer.rb.~1.2.~ +239 -0
- data/lib/rbyaml/resolver.rb +15 -15
- data/lib/rbyaml/resolver.rb.~1.1.~ +163 -0
- data/lib/rbyaml/scanner.rb +457 -366
- data/lib/rbyaml/scanner.rb.~1.2.~ +1259 -0
- data/lib/rbyaml/serializer.rb +19 -17
- data/lib/rbyaml/serializer.rb.~1.2.~ +115 -0
- data/lib/rbyaml/tokens.rb +44 -4
- data/lib/rbyaml/tokens.rb.~1.2.~ +164 -0
- data/lib/rbyaml/util.rb +28 -0
- data/lib/rbyaml/yaml.rb +12 -12
- data/lib/rbyaml/yaml.rb.~1.2.~ +136 -0
- data/test/test_bm.rb +28 -0
- data/test/test_bm_syck.rb +28 -0
- data/test/test_invoke.rb +31 -0
- data/test/test_one.rb +5 -0
- data/test/test_profile.rb +32 -0
- data/test/test_rbyaml.rb +2 -1
- data/test/test_rbyaml.rb.~1.2.~ +31 -0
- data/test/test_time.rb +13 -8
- data/test/test_time.rb.~1.1.~ +29 -0
- data/test/yamlx.rb +3563 -0
- metadata +27 -2
data/lib/rbyaml/error.rb
CHANGED
@@ -1,49 +1,44 @@
|
|
1
1
|
|
2
2
|
module RbYAML
|
3
|
+
Mark = Struct.new(:name,:column,:buffer,:pointer)
|
3
4
|
class Mark
|
4
|
-
attr_reader :name,:index,:line,:column,:buffer,:pointer
|
5
|
-
def initialize(name, index, line, column, buffer, pointer)
|
6
|
-
@name = name
|
7
|
-
@index = index
|
8
|
-
@line = line
|
9
|
-
@column = column
|
10
|
-
@buffer = buffer
|
11
|
-
@pointer = pointer
|
12
|
-
end
|
13
|
-
|
14
5
|
def get_snippet(indent=4, max_length=75)
|
15
|
-
return nil if
|
6
|
+
return nil if buffer.nil?
|
16
7
|
head = ""
|
17
|
-
start =
|
18
|
-
while start > 0 && !"\0\r\n\x85".include?(
|
8
|
+
start = pointer
|
9
|
+
while start > 0 && !"\0\r\n\x85".include?(buffer[start-1])
|
19
10
|
start -= 1
|
20
|
-
if
|
11
|
+
if pointer-start > max_length/2-1
|
21
12
|
head = " ... "
|
22
13
|
start += 5
|
23
14
|
break
|
24
15
|
end
|
25
16
|
end
|
26
17
|
tail = ""
|
27
|
-
tend =
|
28
|
-
while tend <
|
18
|
+
tend = pointer
|
19
|
+
while tend < buffer.length && !"\0\r\n\x85".include?(buffer[tend])
|
29
20
|
tend += 1
|
30
|
-
if tend
|
21
|
+
if tend-pointer > max_length/2-1
|
31
22
|
tail = " ... "
|
32
23
|
tend -= 5
|
33
24
|
break
|
34
25
|
end
|
35
26
|
end
|
36
|
-
snippet =
|
37
|
-
' ' * indent + "#{head}#{snippet}#{tail}\n" + ' '*(indent
|
27
|
+
snippet = buffer[start..tend]
|
28
|
+
' ' * indent + "#{head}#{snippet}#{tail}\n" + ' '*(indent+pointer-start+head.length) + ' '
|
38
29
|
end
|
39
30
|
|
40
31
|
def to_s
|
41
32
|
snippet = get_snippet()
|
42
|
-
where = " in \"#{
|
33
|
+
where = " in \"#{name}\", line ?, column #{column+1}"
|
43
34
|
if snippet
|
44
35
|
where << ":\n" << snippet
|
45
36
|
end
|
46
37
|
end
|
38
|
+
|
39
|
+
def hash
|
40
|
+
object_id
|
41
|
+
end
|
47
42
|
end
|
48
43
|
|
49
44
|
class YAMLError < StandardError
|
@@ -68,7 +63,6 @@ module RbYAML
|
|
68
63
|
lines << @context if @context
|
69
64
|
if @context_mark && (@problem.nil? || @problem_mark.nil? ||
|
70
65
|
@context_mark.name != @problem_mark.name ||
|
71
|
-
@context_mark.line != @problem_mark.line ||
|
72
66
|
@context_mark.column != @problem_mark.column)
|
73
67
|
lines << @context_mark.to_s
|
74
68
|
end
|
data/lib/rbyaml/events.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
|
2
2
|
module RbYAML
|
3
|
+
Event = Struct.new(:start_mark,:end_mark)
|
3
4
|
class Event
|
4
|
-
|
5
|
-
|
6
|
-
@start_mark = start_mark
|
7
|
-
@end_mark = end_mark
|
5
|
+
def hash
|
6
|
+
object_id
|
8
7
|
end
|
9
|
-
|
10
8
|
def to_s
|
11
9
|
attributes = ["@anchor","@tag","@implicit","@value"] & self.instance_variables
|
12
10
|
args = attributes.collect {|val| "#{val[1..-1]}=" + eval("#{val}").to_s}.join(", ")
|
13
11
|
"#{self.class.name}(#{args})"
|
14
12
|
end
|
13
|
+
def __is_node; false; end
|
14
|
+
def __is_collection_start; false; end
|
15
|
+
def __is_collection_end; false; end
|
16
|
+
def __is_stream_start; false; end
|
17
|
+
def __is_stream_end; false; end
|
18
|
+
def __is_document_start; false; end
|
19
|
+
def __is_document_end; false; end
|
20
|
+
def __is_alias; false; end
|
21
|
+
def __is_scalar; false; end
|
22
|
+
def __is_sequence_start; false; end
|
23
|
+
def __is_sequence_end; false; end
|
24
|
+
def __is_mapping_start; false; end
|
25
|
+
def __is_mapping_end; false; end
|
15
26
|
end
|
16
27
|
|
17
28
|
class NodeEvent < Event
|
@@ -20,6 +31,7 @@ module RbYAML
|
|
20
31
|
super(start_mark,end_mark)
|
21
32
|
@anchor = anchor
|
22
33
|
end
|
34
|
+
def __is_node; true; end
|
23
35
|
end
|
24
36
|
|
25
37
|
class CollectionStartEvent < NodeEvent
|
@@ -30,9 +42,11 @@ module RbYAML
|
|
30
42
|
@implicit = implicit
|
31
43
|
@flow_style = flow_style
|
32
44
|
end
|
45
|
+
def __is_collection_start; true; end
|
33
46
|
end
|
34
47
|
|
35
48
|
class CollectionEndEvent < Event
|
49
|
+
def __is_collection_end; true; end
|
36
50
|
end
|
37
51
|
|
38
52
|
class StreamStartEvent < Event
|
@@ -41,9 +55,11 @@ module RbYAML
|
|
41
55
|
super(start_mark,end_mark)
|
42
56
|
@encoding = encoding
|
43
57
|
end
|
58
|
+
def __is_stream_start; true; end
|
44
59
|
end
|
45
60
|
|
46
61
|
class StreamEndEvent < Event
|
62
|
+
def __is_stream_end; true; end
|
47
63
|
end
|
48
64
|
|
49
65
|
class DocumentStartEvent < Event
|
@@ -54,6 +70,7 @@ module RbYAML
|
|
54
70
|
@version = version
|
55
71
|
@tags = tags
|
56
72
|
end
|
73
|
+
def __is_document_start; true; end
|
57
74
|
end
|
58
75
|
|
59
76
|
class DocumentEndEvent < Event
|
@@ -62,9 +79,11 @@ module RbYAML
|
|
62
79
|
super(start_mark,end_mark)
|
63
80
|
@explicit = explicit
|
64
81
|
end
|
82
|
+
def __is_document_end; true; end
|
65
83
|
end
|
66
84
|
|
67
85
|
class AliasEvent < NodeEvent
|
86
|
+
def __is_alias; true; end
|
68
87
|
end
|
69
88
|
|
70
89
|
class ScalarEvent < NodeEvent
|
@@ -76,18 +95,23 @@ module RbYAML
|
|
76
95
|
@value = value
|
77
96
|
@implicit = implicit
|
78
97
|
end
|
98
|
+
def __is_scalar; true; end
|
79
99
|
end
|
80
100
|
|
81
101
|
class SequenceStartEvent < CollectionStartEvent
|
102
|
+
def __is_sequence_start; true; end
|
82
103
|
end
|
83
104
|
|
84
105
|
class SequenceEndEvent < CollectionEndEvent
|
106
|
+
def __is_sequence_end; true; end
|
85
107
|
end
|
86
108
|
|
87
109
|
class MappingStartEvent < CollectionStartEvent
|
110
|
+
def __is_mapping_start; true; end
|
88
111
|
end
|
89
112
|
|
90
113
|
class MappingEndEvent < CollectionEndEvent
|
114
|
+
def __is_mapping_end; true; end
|
91
115
|
end
|
92
116
|
end
|
93
117
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
module RbYAML
|
3
|
+
class Event
|
4
|
+
attr_reader :start_mark, :end_mark
|
5
|
+
def initialize(start_mark=nil,end_mark=nil)
|
6
|
+
@start_mark = start_mark
|
7
|
+
@end_mark = end_mark
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
attributes = ["@anchor","@tag","@implicit","@value"] & self.instance_variables
|
12
|
+
args = attributes.collect {|val| "#{val[1..-1]}=" + eval("#{val}").to_s}.join(", ")
|
13
|
+
"#{self.class.name}(#{args})"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class NodeEvent < Event
|
18
|
+
attr_reader :anchor
|
19
|
+
def initialize(anchor, start_mark=nil, end_mark=nil)
|
20
|
+
super(start_mark,end_mark)
|
21
|
+
@anchor = anchor
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class CollectionStartEvent < NodeEvent
|
26
|
+
attr_reader :tag, :implicit, :flow_style
|
27
|
+
def initialize(anchor,tag,implicit,start_mark=nil, end_mark=nil,flow_style=nil)
|
28
|
+
super(anchor,start_mark,end_mark)
|
29
|
+
@tag = tag
|
30
|
+
@implicit = implicit
|
31
|
+
@flow_style = flow_style
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class CollectionEndEvent < Event
|
36
|
+
end
|
37
|
+
|
38
|
+
class StreamStartEvent < Event
|
39
|
+
attr_reader :encoding
|
40
|
+
def initialize(start_mark=nil,end_mark=nil,encoding=nil)
|
41
|
+
super(start_mark,end_mark)
|
42
|
+
@encoding = encoding
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class StreamEndEvent < Event
|
47
|
+
end
|
48
|
+
|
49
|
+
class DocumentStartEvent < Event
|
50
|
+
attr_reader :explicit, :version, :tags
|
51
|
+
def initialize(start_mark=nil,end_mark=nil,explicit=nil,version=nil,tags=nil)
|
52
|
+
super(start_mark,end_mark)
|
53
|
+
@explicit = explicit
|
54
|
+
@version = version
|
55
|
+
@tags = tags
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class DocumentEndEvent < Event
|
60
|
+
attr_reader :explicit
|
61
|
+
def initialize(start_mark=nil,end_mark=nil,explicit=nil)
|
62
|
+
super(start_mark,end_mark)
|
63
|
+
@explicit = explicit
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class AliasEvent < NodeEvent
|
68
|
+
end
|
69
|
+
|
70
|
+
class ScalarEvent < NodeEvent
|
71
|
+
attr_reader :tag, :style, :value, :implicit
|
72
|
+
def initialize(anchor,tag,implicit,value,start_mark=nil, end_mark=nil,style=nil)
|
73
|
+
super(anchor,start_mark,end_mark)
|
74
|
+
@tag = tag
|
75
|
+
@style = style
|
76
|
+
@value = value
|
77
|
+
@implicit = implicit
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class SequenceStartEvent < CollectionStartEvent
|
82
|
+
end
|
83
|
+
|
84
|
+
class SequenceEndEvent < CollectionEndEvent
|
85
|
+
end
|
86
|
+
|
87
|
+
class MappingStartEvent < CollectionStartEvent
|
88
|
+
end
|
89
|
+
|
90
|
+
class MappingEndEvent < CollectionEndEvent
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
data/lib/rbyaml/loader.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# This is a more or less straight translation of PyYAML3000 to Ruby
|
2
2
|
|
3
|
-
require 'rbyaml/reader'
|
4
3
|
require 'rbyaml/scanner'
|
5
4
|
require 'rbyaml/parser'
|
6
5
|
require 'rbyaml/composer'
|
@@ -9,43 +8,32 @@ require 'rbyaml/resolver'
|
|
9
8
|
|
10
9
|
module RbYAML
|
11
10
|
class CommonLoader
|
12
|
-
|
13
|
-
|
14
|
-
def initialize(stream)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
attr_accessor :scanner, :parser, :composer, :constructor, :resolver
|
12
|
+
|
13
|
+
def initialize(stream,scanner=Scanner,parser=Parser,composer=Composer,constructor=BaseConstructor,resolver=BaseResolver)
|
14
|
+
@scanner = scanner.new(stream)
|
15
|
+
@parser = parser.new(@scanner)
|
16
|
+
@resolver = resolver.new
|
17
|
+
@composer = composer.new(@parser,@resolver)
|
18
|
+
@constructor = constructor.new(@composer)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
class BaseLoader < CommonLoader
|
23
|
-
include Composer, BaseConstructor, BaseResolver
|
24
23
|
def initialize(stream)
|
25
|
-
super
|
26
|
-
initialize_composer
|
27
|
-
initialize_constructor
|
28
|
-
initialize_resolver
|
24
|
+
super(stream,Scanner,Parser,Composer,BaseConstructor,BaseResolver)
|
29
25
|
end
|
30
26
|
end
|
31
27
|
|
32
28
|
class SafeLoader < CommonLoader
|
33
|
-
include Composer, SafeConstructor, Resolver
|
34
29
|
def initialize(stream)
|
35
|
-
super
|
36
|
-
initialize_composer
|
37
|
-
initialize_constructor
|
38
|
-
initialize_resolver
|
30
|
+
super(stream,Scanner,Parser,Composer,SafeConstructor,Resolver)
|
39
31
|
end
|
40
32
|
end
|
41
33
|
|
42
34
|
class Loader < CommonLoader
|
43
|
-
include Composer, Constructor, Resolver
|
44
35
|
def initialize(stream)
|
45
|
-
super
|
46
|
-
initialize_composer
|
47
|
-
initialize_constructor
|
48
|
-
initialize_resolver
|
36
|
+
super(stream,Scanner,Parser,Composer,Constructor,Resolver)
|
49
37
|
end
|
50
38
|
end
|
51
39
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# This is a more or less straight translation of PyYAML3000 to Ruby
|
2
|
+
|
3
|
+
require 'rbyaml/reader'
|
4
|
+
require 'rbyaml/scanner'
|
5
|
+
require 'rbyaml/parser'
|
6
|
+
require 'rbyaml/composer'
|
7
|
+
require 'rbyaml/constructor'
|
8
|
+
require 'rbyaml/resolver'
|
9
|
+
|
10
|
+
module RbYAML
|
11
|
+
class CommonLoader
|
12
|
+
include Reader, Scanner, Parser
|
13
|
+
|
14
|
+
def initialize(stream)
|
15
|
+
super()
|
16
|
+
initialize_reader(stream)
|
17
|
+
initialize_scanner
|
18
|
+
initialize_parser
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class BaseLoader < CommonLoader
|
23
|
+
include Composer, BaseConstructor, BaseResolver
|
24
|
+
def initialize(stream)
|
25
|
+
super
|
26
|
+
initialize_composer
|
27
|
+
initialize_constructor
|
28
|
+
initialize_resolver
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class SafeLoader < CommonLoader
|
33
|
+
include Composer, SafeConstructor, Resolver
|
34
|
+
def initialize(stream)
|
35
|
+
super
|
36
|
+
initialize_composer
|
37
|
+
initialize_constructor
|
38
|
+
initialize_resolver
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Loader < CommonLoader
|
43
|
+
include Composer, Constructor, Resolver
|
44
|
+
def initialize(stream)
|
45
|
+
super
|
46
|
+
initialize_composer
|
47
|
+
initialize_constructor
|
48
|
+
initialize_resolver
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
data/lib/rbyaml/nodes.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
|
2
2
|
module RbYAML
|
3
|
+
Node = Struct.new(:tag, :value, :start_mark, :end_mark)
|
3
4
|
class Node
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(tag, value, start_mark, end_mark)
|
7
|
-
@tag = tag
|
8
|
-
@value = value
|
9
|
-
@start_mark = start_mark
|
10
|
-
@end_mark = end_mark
|
5
|
+
def hash
|
6
|
+
object_id
|
11
7
|
end
|
12
|
-
|
13
8
|
def to_s
|
14
|
-
"#{self.class.name}(tag=#{
|
9
|
+
"#{self.class.name}(tag=#{tag}, value=#{value})"
|
15
10
|
end
|
11
|
+
|
12
|
+
def __is_scalar; false; end
|
13
|
+
def __is_collection; false; end
|
14
|
+
def __is_sequence; false; end
|
15
|
+
def __is_mapping; false; end
|
16
16
|
end
|
17
17
|
|
18
18
|
class ScalarNode < Node
|
@@ -26,6 +26,7 @@ module RbYAML
|
|
26
26
|
super(tag,value,start_mark,end_mark)
|
27
27
|
@style = style
|
28
28
|
end
|
29
|
+
def __is_scalar; true; end
|
29
30
|
end
|
30
31
|
|
31
32
|
class CollectionNode < Node
|
@@ -35,18 +36,21 @@ module RbYAML
|
|
35
36
|
super(tag,value,start_mark,end_mark)
|
36
37
|
@flow_style = flow_style
|
37
38
|
end
|
39
|
+
def __is_collection; true; end
|
38
40
|
end
|
39
41
|
|
40
42
|
class SequenceNode < CollectionNode
|
41
43
|
def tid
|
42
44
|
"sequence"
|
43
45
|
end
|
46
|
+
def __is_sequence; true; end
|
44
47
|
end
|
45
48
|
|
46
49
|
class MappingNode < CollectionNode
|
47
50
|
def tid
|
48
51
|
"mapping"
|
49
52
|
end
|
53
|
+
def __is_mapping; true; end
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
module RbYAML
|
3
|
+
class Node
|
4
|
+
attr_accessor :tag, :value, :start_mark, :end_mark
|
5
|
+
|
6
|
+
def initialize(tag, value, start_mark, end_mark)
|
7
|
+
@tag = tag
|
8
|
+
@value = value
|
9
|
+
@start_mark = start_mark
|
10
|
+
@end_mark = end_mark
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#{self.class.name}(tag=#{@tag}, value=#{@value})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ScalarNode < Node
|
19
|
+
def tid
|
20
|
+
"scalar"
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor :style
|
24
|
+
|
25
|
+
def initialize(tag, value,start_mark=nil,end_mark=nil,style=nil)
|
26
|
+
super(tag,value,start_mark,end_mark)
|
27
|
+
@style = style
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class CollectionNode < Node
|
32
|
+
attr_accessor :flow_style
|
33
|
+
|
34
|
+
def initialize(tag, value,start_mark=nil,end_mark=nil,flow_style=nil)
|
35
|
+
super(tag,value,start_mark,end_mark)
|
36
|
+
@flow_style = flow_style
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class SequenceNode < CollectionNode
|
41
|
+
def tid
|
42
|
+
"sequence"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class MappingNode < CollectionNode
|
47
|
+
def tid
|
48
|
+
"mapping"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|