RbYAML 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README +1 -1
  2. data/lib/rbyaml/composer.rb +28 -25
  3. data/lib/rbyaml/composer.rb.~1.2.~ +109 -0
  4. data/lib/rbyaml/constructor.rb +94 -84
  5. data/lib/rbyaml/constructor.rb.~1.2.~ +381 -0
  6. data/lib/rbyaml/dumper.rb +10 -17
  7. data/lib/rbyaml/dumper.rb.~1.2.~ +43 -0
  8. data/lib/rbyaml/emitter.rb +13 -26
  9. data/lib/rbyaml/emitter.rb.~1.2.~ +1116 -0
  10. data/lib/rbyaml/error.rb +15 -21
  11. data/lib/rbyaml/events.rb +29 -5
  12. data/lib/rbyaml/events.rb.~1.2.~ +93 -0
  13. data/lib/rbyaml/loader.rb +11 -23
  14. data/lib/rbyaml/loader.rb.~1.2.~ +52 -0
  15. data/lib/rbyaml/nodes.rb +13 -9
  16. data/lib/rbyaml/nodes.rb.~1.2.~ +52 -0
  17. data/lib/rbyaml/parser.rb +481 -343
  18. data/lib/rbyaml/parser.rb.old +531 -0
  19. data/lib/rbyaml/parser.rb.~1.2.~ +494 -0
  20. data/lib/rbyaml/reader.rb.~1.1.1.1.~ +127 -0
  21. data/lib/rbyaml/representer.rb +26 -17
  22. data/lib/rbyaml/representer.rb.~1.2.~ +239 -0
  23. data/lib/rbyaml/resolver.rb +15 -15
  24. data/lib/rbyaml/resolver.rb.~1.1.~ +163 -0
  25. data/lib/rbyaml/scanner.rb +457 -366
  26. data/lib/rbyaml/scanner.rb.~1.2.~ +1259 -0
  27. data/lib/rbyaml/serializer.rb +19 -17
  28. data/lib/rbyaml/serializer.rb.~1.2.~ +115 -0
  29. data/lib/rbyaml/tokens.rb +44 -4
  30. data/lib/rbyaml/tokens.rb.~1.2.~ +164 -0
  31. data/lib/rbyaml/util.rb +28 -0
  32. data/lib/rbyaml/yaml.rb +12 -12
  33. data/lib/rbyaml/yaml.rb.~1.2.~ +136 -0
  34. data/test/test_bm.rb +28 -0
  35. data/test/test_bm_syck.rb +28 -0
  36. data/test/test_invoke.rb +31 -0
  37. data/test/test_one.rb +5 -0
  38. data/test/test_profile.rb +32 -0
  39. data/test/test_rbyaml.rb +2 -1
  40. data/test/test_rbyaml.rb.~1.2.~ +31 -0
  41. data/test/test_time.rb +13 -8
  42. data/test/test_time.rb.~1.1.~ +29 -0
  43. data/test/yamlx.rb +3563 -0
  44. metadata +27 -2
data/README CHANGED
@@ -24,7 +24,7 @@ Just require 'rbyaml' and use it as you would use YAML, but in module RbYAML ins
24
24
 
25
25
  == More information
26
26
 
27
- Visit http://rbyaml.ologix.com for more information and updated versions
27
+ Visit http://rbyaml.rubyforge.org for more information and updated versions
28
28
 
29
29
  == License
30
30
 
@@ -6,13 +6,15 @@ module RbYAML
6
6
  class ComposerError < MarkedYAMLError
7
7
  end
8
8
 
9
- module Composer
10
- def initialize_composer
9
+ class Composer
10
+ def initialize(parser,resolver)
11
+ @parser = parser
12
+ @resolver = resolver
11
13
  @anchors = {}
12
14
  end
13
15
 
14
16
  def check_node
15
- !check_event(StreamEndEvent)
17
+ !@parser.peek_event.__is_stream_end
16
18
  end
17
19
 
18
20
  def get_node
@@ -25,75 +27,76 @@ module RbYAML
25
27
 
26
28
  def compose_document
27
29
  # Drop the STREAM-START event.
28
- get_event if check_event(StreamStartEvent)
29
- get_event
30
+ @parser.get_event if @parser.peek_event.__is_stream_start
31
+ # Drop the DOCUMENT-START event.
32
+ @parser.get_event
30
33
  # Compose the root node.
31
34
  node = compose_node(nil,nil)
32
35
  # Drop the DOCUMENT-END event.
33
- get_event
36
+ @parser.get_event
34
37
  @anchors = {}
35
38
  node
36
39
  end
37
40
 
38
41
  def compose_node(parent,index)
39
- if check_event(AliasEvent)
40
- event = get_event
42
+ if @parser.peek_event.__is_alias
43
+ event = @parser.get_event
41
44
  anchor = event.anchor
42
45
  raise ComposerError.new(nil, nil, "found undefined alias #{anchor}", event.start_mark) if !@anchors.include?(anchor)
43
46
  return @anchors[anchor]
44
47
  end
45
- event = peek_event
48
+ event = @parser.peek_event
46
49
  anchor = event.anchor
47
50
  if !anchor.nil?
48
51
  if @anchors.include?(anchor)
49
52
  raise ComposerError.new("found duplicate anchor #{anchor}; first occurence", @anchors[anchor].start_mark,"second occurence", event.start_mark)
50
53
  end
51
54
  end
52
- descend_resolver(parent,index)
53
- if check_event(ScalarEvent)
55
+ @resolver.descend_resolver(parent,index)
56
+ if @parser.peek_event.__is_scalar
54
57
  node = compose_scalar_node(anchor)
55
- elsif check_event(SequenceStartEvent)
58
+ elsif @parser.peek_event.__is_sequence_start
56
59
  node = compose_sequence_node(anchor)
57
- elsif check_event(MappingStartEvent)
60
+ elsif @parser.peek_event.__is_mapping_start
58
61
  node = compose_mapping_node(anchor)
59
62
  end
60
- ascend_resolver
63
+ @resolver.ascend_resolver
61
64
  node
62
65
  end
63
66
 
64
67
  def compose_scalar_node(anchor)
65
- event = get_event
68
+ event = @parser.get_event
66
69
  tag = event.tag
67
- tag = resolve(ScalarNode,event.value,event.implicit) if tag.nil? || tag == "!"
70
+ tag = @resolver.resolve(ScalarNode,event.value,event.implicit) if tag.nil? || tag == "!"
68
71
  node = ScalarNode.new(tag, event.value,event.start_mark, event.end_mark, event.style)
69
72
  @anchors[anchor] = node if !anchor.nil?
70
73
  node
71
74
  end
72
75
 
73
76
  def compose_sequence_node(anchor)
74
- start_event = get_event
77
+ start_event = @parser.get_event
75
78
  tag = start_event.tag
76
- tag = resolve(SequenceNode,nil,start_event.implicit) if tag.nil? || tag == "!"
79
+ tag = @resolver.resolve(SequenceNode,nil,start_event.implicit) if tag.nil? || tag == "!"
77
80
  node = SequenceNode.new(tag,[],start_event.start_mark,nil,start_event.flow_style)
78
81
  @anchors[anchor] = node if !anchor.nil?
79
82
  index = 0
80
- while !check_event(SequenceEndEvent)
83
+ while !@parser.peek_event.__is_sequence_end
81
84
  node.value << compose_node(node,index)
82
85
  index += 1
83
86
  end
84
- end_event = get_event
87
+ end_event = @parser.get_event
85
88
  node.end_mark = end_event.end_mark
86
89
  node
87
90
  end
88
91
 
89
92
  def compose_mapping_node(anchor)
90
- start_event = get_event
93
+ start_event = @parser.get_event
91
94
  tag = start_event.tag
92
- tag = resolve(MappingNode,nil,start_event.implicit) if tag.nil? || tag == "!"
95
+ tag = @resolver.resolve(MappingNode,nil,start_event.implicit) if tag.nil? || tag == "!"
93
96
  node = MappingNode.new(tag, {},start_event.start_mark,nil,start_event.flow_style)
94
97
  @anchors[anchor] = node if !anchor.nil?
95
- while !check_event(MappingEndEvent)
96
- key_event = peek_event
98
+ while !@parser.peek_event.__is_mapping_end
99
+ key_event = @parser.peek_event
97
100
  item_key = compose_node(node,nil)
98
101
  if node.value.include?(item_key)
99
102
  raise ComposerError.new("while composing a mapping", start_event.start_mark,"found duplicate key", key_event.start_mark)
@@ -101,7 +104,7 @@ module RbYAML
101
104
  item_value = compose_node(node,item_key)
102
105
  node.value[item_key] = item_value
103
106
  end
104
- end_event = get_event
107
+ end_event = @parser.get_event
105
108
  node.end_mark = end_event.end_mark
106
109
  node
107
110
  end
@@ -0,0 +1,109 @@
1
+ require 'rbyaml/error'
2
+ require 'rbyaml/events'
3
+ require 'rbyaml/nodes'
4
+
5
+ module RbYAML
6
+ class ComposerError < MarkedYAMLError
7
+ end
8
+
9
+ module Composer
10
+ def initialize_composer
11
+ @anchors = {}
12
+ end
13
+
14
+ def check_node
15
+ !check_event(StreamEndEvent)
16
+ end
17
+
18
+ def get_node
19
+ compose_document if check_node
20
+ end
21
+
22
+ def each_node
23
+ yield compose_document while check_node
24
+ end
25
+
26
+ def compose_document
27
+ # Drop the STREAM-START event.
28
+ get_event if check_event(StreamStartEvent)
29
+ get_event
30
+ # Compose the root node.
31
+ node = compose_node(nil,nil)
32
+ # Drop the DOCUMENT-END event.
33
+ get_event
34
+ @anchors = {}
35
+ node
36
+ end
37
+
38
+ def compose_node(parent,index)
39
+ if check_event(AliasEvent)
40
+ event = get_event
41
+ anchor = event.anchor
42
+ raise ComposerError.new(nil, nil, "found undefined alias #{anchor}", event.start_mark) if !@anchors.include?(anchor)
43
+ return @anchors[anchor]
44
+ end
45
+ event = peek_event
46
+ anchor = event.anchor
47
+ if !anchor.nil?
48
+ if @anchors.include?(anchor)
49
+ raise ComposerError.new("found duplicate anchor #{anchor}; first occurence", @anchors[anchor].start_mark,"second occurence", event.start_mark)
50
+ end
51
+ end
52
+ descend_resolver(parent,index)
53
+ if check_event(ScalarEvent)
54
+ node = compose_scalar_node(anchor)
55
+ elsif check_event(SequenceStartEvent)
56
+ node = compose_sequence_node(anchor)
57
+ elsif check_event(MappingStartEvent)
58
+ node = compose_mapping_node(anchor)
59
+ end
60
+ ascend_resolver
61
+ node
62
+ end
63
+
64
+ def compose_scalar_node(anchor)
65
+ event = get_event
66
+ tag = event.tag
67
+ tag = resolve(ScalarNode,event.value,event.implicit) if tag.nil? || tag == "!"
68
+ node = ScalarNode.new(tag, event.value,event.start_mark, event.end_mark, event.style)
69
+ @anchors[anchor] = node if !anchor.nil?
70
+ node
71
+ end
72
+
73
+ def compose_sequence_node(anchor)
74
+ start_event = get_event
75
+ tag = start_event.tag
76
+ tag = resolve(SequenceNode,nil,start_event.implicit) if tag.nil? || tag == "!"
77
+ node = SequenceNode.new(tag,[],start_event.start_mark,nil,start_event.flow_style)
78
+ @anchors[anchor] = node if !anchor.nil?
79
+ index = 0
80
+ while !check_event(SequenceEndEvent)
81
+ node.value << compose_node(node,index)
82
+ index += 1
83
+ end
84
+ end_event = get_event
85
+ node.end_mark = end_event.end_mark
86
+ node
87
+ end
88
+
89
+ def compose_mapping_node(anchor)
90
+ start_event = get_event
91
+ tag = start_event.tag
92
+ tag = resolve(MappingNode,nil,start_event.implicit) if tag.nil? || tag == "!"
93
+ node = MappingNode.new(tag, {},start_event.start_mark,nil,start_event.flow_style)
94
+ @anchors[anchor] = node if !anchor.nil?
95
+ while !check_event(MappingEndEvent)
96
+ key_event = peek_event
97
+ item_key = compose_node(node,nil)
98
+ if node.value.include?(item_key)
99
+ raise ComposerError.new("while composing a mapping", start_event.start_mark,"found duplicate key", key_event.start_mark)
100
+ end
101
+ item_value = compose_node(node,item_key)
102
+ node.value[item_key] = item_value
103
+ end
104
+ end_event = get_event
105
+ node.end_mark = end_event.end_mark
106
+ node
107
+ end
108
+ end
109
+ end
@@ -5,35 +5,54 @@ require 'rbyaml/error'
5
5
  require 'rbyaml/nodes'
6
6
  require 'rbyaml/composer'
7
7
 
8
+ class Symbol
9
+ def __call(obj,*args)
10
+ obj.send(self,*args)
11
+ end
12
+ end
13
+
14
+ class Proc
15
+ def __call(obj,*args)
16
+ call(*args)
17
+ end
18
+ end
19
+
20
+ class Method
21
+ def __call(obj,*args)
22
+ call(*args)
23
+ end
24
+ end
25
+
26
+
8
27
  module RbYAML
9
28
  class ConstructorError < MarkedYAMLError
10
29
  end
11
30
 
12
- module BaseConstructor
13
- include Composer
14
-
31
+ class BaseConstructor
15
32
  @@yaml_constructors = {}
16
33
  @@yaml_multi_constructors = {}
34
+ @@yaml_multi_regexps = {}
17
35
 
18
- def initialize_constructor
36
+ def initialize(composer)
37
+ @composer = composer
19
38
  @constructed_objects = {}
20
39
  @recursive_objects = {}
21
40
  end
22
41
 
23
42
  def check_data
24
43
  # If there are more documents available?
25
- check_node
44
+ @composer.check_node
26
45
  end
27
46
 
28
47
  def get_data
29
48
  # Construct and return the next document.
30
- construct_document(get_node) if check_node
49
+ construct_document(@composer.get_node) if @composer.check_node
31
50
  end
32
51
 
33
52
  def each_document
34
53
  # Iterator protocol.
35
- while check_node
36
- yield construct_document(get_node)
54
+ while @composer.check_node
55
+ yield construct_document(@composer.get_node)
37
56
  end
38
57
  end
39
58
 
@@ -48,52 +67,43 @@ module RbYAML
48
67
  return @constructed_objects[node] if @constructed_objects.include?(node)
49
68
  raise ConstructorError.new(nil,nil,"found recursive nod",node.start_mark) if @recursive_objects.include?(node)
50
69
  @recursive_objects[node] = nil
51
- constructor = nil
52
- ruby_cls = RbYAML::tagged_classes[node.tag]
53
- if @@yaml_constructors.include?(node.tag)
54
- constructor = @@yaml_constructors[node.tag]
55
- elsif !ruby_cls.nil? && self.respond_to?(:construct_ruby_object) && (ruby_cls.method_defined?(:yaml_initialize) || ruby_cls.respond_to?(:yaml_new))
56
- constructor = lambda { |node| send(:construct_ruby_object,RbYAML::tagged_classes[node.tag],node) }
57
- else
58
- through = false
59
- for tag_prefix in @@yaml_multi_constructors.keys
70
+ constructor = @@yaml_constructors[node.tag]
71
+ if !constructor
72
+ ruby_cls = RbYAML::tagged_classes[node.tag]
73
+ if ruby_cls && (ruby_cls.method_defined?(:yaml_initialize) || ruby_cls.respond_to?(:yaml_new))
74
+ constructor = lambda { |node| send(:construct_ruby_object,ruby_cls,node) }
75
+ else
60
76
  through = true
61
- if Regexp.new("^"+Regexp.escape(tag_prefix)) =~ node.tag
62
- tag_suffix = node.tag[tag_prefix.length..-1]
63
- if Symbol === @@yaml_multi_constructors[tag_prefix]
64
- constructor = lambda { |node| send(@@yaml_multi_constructors[tag_prefix],tag_suffix, node) }
65
- else
66
- constructor = lambda { |node| @@yaml_multi_constructors[tag_prefix].call(tag_suffix, node) }
77
+ for tag_prefix,reg in @@yaml_multi_regexps
78
+ if reg =~ node.tag
79
+ tag_suffix = node.tag[tag_prefix.length..-1]
80
+ constructor = lambda { |node| @@yaml_multi_constructors[tag_prefix].__call(self,tag_suffix, node) }
81
+ through = false
82
+ break
67
83
  end
68
- break
69
84
  end
70
- end
71
- if !through
72
- if @@yaml_multi_constructors.include?(nil)
73
- if Symbol === @@yaml_multi_constructors[nil]
74
- constructor = lambda { |node| send(@@yaml_multi_constructors[nil],node.tag, node) }
85
+ if through
86
+ ctor = @@yaml_multi_constructors[nil] || @@yaml_constructors[nil]
87
+ if ctor
88
+ constructor = lambda { |node| ctor.__call(self,node.tag,node) }
75
89
  else
76
- constructor = lambda { |node| @@yaml_multi_constructors[nil].call(node.tag, node) }
90
+ constructor = lambda { |node| construct_primitive(node) }
77
91
  end
78
- elsif @@yaml_constructors.include?(nil)
79
- constructor = @@yaml_constructors[nil]
80
- else
81
- constructor = lambda { |node| construct_primitive(node) }
82
92
  end
83
93
  end
84
94
  end
85
- data = (Symbol === constructor) ? send(constructor,node) : constructor.call(node)
95
+ data = constructor.__call(self,node)
86
96
  @constructed_objects[node] = data
87
97
  @recursive_objects.delete(node)
88
98
  data
89
99
  end
90
100
 
91
101
  def construct_primitive(node)
92
- if ScalarNode === node
102
+ if node.__is_scalar
93
103
  construct_scalar(node)
94
- elsif SequenceNode === node
104
+ elsif node.__is_sequence
95
105
  construct_sequence(node)
96
- elsif MappingNode === node
106
+ elsif node.__is_mapping
97
107
  construct_mapping(node)
98
108
  else
99
109
  puts node.tag
@@ -101,8 +111,8 @@ module RbYAML
101
111
  end
102
112
 
103
113
  def construct_scalar(node)
104
- if !ScalarNode === node
105
- if MappingNode === node
114
+ if !node.__is_scalar
115
+ if node.__is_mapping
106
116
  for key_node in node.value.keys
107
117
  if key_node.tag == "tag:yaml.org,2002:value"
108
118
  return construct_scalar(node.value[key_node])
@@ -115,46 +125,39 @@ module RbYAML
115
125
  end
116
126
 
117
127
  def construct_sequence(node)
118
- raise ConstructorError.new(nil,nil,"expected a sequence node, but found #{node.tid}",node.start_mark) if !SequenceNode === node
119
- sequence = []
120
- for child in node.value
121
- sequence << construct_object(child)
122
- end
123
- sequence
128
+ raise ConstructorError.new(nil,nil,"expected a sequence node, but found #{node.tid}",node.start_mark) if !node.__is_sequence
129
+ node.value.map {|child| construct_object(child) }
124
130
  end
125
131
 
126
132
  def construct_mapping(node)
127
- raise ConstructorError.new(nil,nil,"expected a mapping node, but found #{node.tid}",node.start_mark) if !MappingNode === node
133
+ raise ConstructorError.new(nil,nil,"expected a mapping node, but found #{node.tid}",node.start_mark) if !node.__is_mapping
128
134
  mapping = {}
129
135
  merge = nil
130
- for key_node in node.value.keys
136
+ for key_node,value_node in node.value
131
137
  if key_node.tag == "tag:yaml.org,2002:merge"
132
138
  raise ConstructorError.new("while constructing a mapping", node.start_mark,"found duplicate merge key", key_node.start_mark) if !merge.nil?
133
- value_node = node.value[key_node]
134
- if MappingNode === value_node
139
+ if value_node.__is_mapping
135
140
  merge = [construct_mapping(value_node)]
136
- elsif SequenceNode === value_node
141
+ elsif value_node.__is_sequence
137
142
  merge = []
138
143
  for subnode in value_node.value
139
- if !MappingNode === subnode
144
+ if !subnode.__is_mapping
140
145
  raise ConstructorError.new("while constructing a mapping",node.start_mark,"expected a mapping for merging, but found #{subnode.tid}", subnode.start_mark)
141
146
  end
142
- merge << construct_mapping(subnode)
147
+ merge.unshift(construct_mapping(subnode))
143
148
  end
144
- merge.reverse!
145
149
  else
146
150
  raise ConstructorError.new("while constructing a mapping", node.start_mark,"expected a mapping or list of mappings for merging, but found #{value_node.tid}", value_node.start_mark)
147
151
  end
148
152
  elsif key_node.tag == "tag:yaml.org,2002:value"
149
153
  raise ConstructorError.new("while construction a mapping", node.start_mark,"found duplicate value key", key_node.start_mark) if mapping.include?("=")
150
- value = construct_object(node.value[key_node])
154
+ value = construct_object(value_node)
151
155
  mapping["="] = value
152
-
153
156
  else
154
157
  key = construct_object(key_node)
155
158
  # raise ConstructorError.new("while constructing a mapping", node.start_mark,"found duplicate key", key_node.start_mark) if mapping.include?(key)
156
159
  end
157
- value = construct_object(node.value[key_node])
160
+ value = construct_object(value_node)
158
161
  mapping[key] = value
159
162
  end
160
163
  if !merge.nil?
@@ -168,14 +171,8 @@ module RbYAML
168
171
  end
169
172
 
170
173
  def construct_pairs(node)
171
- raise ConstructorError.new(nil,nil,"expected a mapping node, but found #{node.tid}",node.start_mark) if !MappingNode === node
172
- pairs = []
173
- for key_node in node.value.keys
174
- key = construct_object(key_node)
175
- value = construct_object(node.value[key_node])
176
- pairs << [key, value]
177
- end
178
- pairs
174
+ raise ConstructorError.new(nil,nil,"expected a mapping node, but found #{node.tid}",node.start_mark) if !node.__is_mapping
175
+ node.value.collect {|key_node,value_node| [construct_object(key_node), construct_object(value_node)] }
179
176
  end
180
177
 
181
178
  def self.add_constructor(tag, constructor)
@@ -184,12 +181,11 @@ module RbYAML
184
181
 
185
182
  def self.add_multi_constructor(tag_prefix, multi_constructor)
186
183
  @@yaml_multi_constructors[tag_prefix] = multi_constructor
184
+ @@yaml_multi_regexps[tag_prefix] = Regexp.new("^"+Regexp.escape(tag_prefix))
187
185
  end
188
186
  end
189
187
 
190
- module SafeConstructor
191
- include BaseConstructor
192
-
188
+ class SafeConstructor < BaseConstructor
193
189
  def construct_yaml_null(node)
194
190
  construct_scalar(node)
195
191
  nil
@@ -208,23 +204,32 @@ module RbYAML
208
204
 
209
205
  def construct_yaml_bool(node)
210
206
  value = construct_scalar(node)
211
- SafeConstructor::BOOL_VALUES[value.downcase]
207
+ BOOL_VALUES[value.downcase]
212
208
  end
213
209
 
214
210
  def construct_yaml_int(node)
215
211
  value = construct_scalar(node).to_s
216
212
  value = value.gsub(/_/, '')
217
213
  sign = +1
218
- sign = -1 if value[0] == ?-
219
- value = value[1..-1] if "+-".include?(value[0])
214
+ first = value[0]
215
+ if first == ?-
216
+ sign = -1
217
+ value.slice!(0)
218
+ elsif first == ?+
219
+ value.slice!(0)
220
+ end
221
+ base = 10
220
222
  if value == "0"
221
223
  return 0
222
224
  elsif value[0..1] == "0b"
223
- return sign*value[2..-1].to_i(2)
225
+ value.slice!(0..1)
226
+ base = 2
224
227
  elsif value[0..1] == "0x"
225
- return sign*value[2..-1].to_i(16)
228
+ value.slice!(0..1)
229
+ base = 16
226
230
  elsif value[0] == ?0
227
- return sign*value[1..-1].to_i(8)
231
+ value.slice!(0)
232
+ base = 8
228
233
  elsif value.include?(?:)
229
234
  digits = (value.split(/:/).map {|val| val.to_i}).reverse
230
235
  base = 1
@@ -237,6 +242,7 @@ module RbYAML
237
242
  else
238
243
  return sign*value.to_i
239
244
  end
245
+ return sign*value.to_i(base)
240
246
  end
241
247
 
242
248
  INF_VALUE = +1.0/0.0
@@ -246,12 +252,17 @@ module RbYAML
246
252
  value = construct_scalar(node).to_s
247
253
  value = value.gsub(/_/, '')
248
254
  sign = +1
249
- sign = -1 if value[0] == ?-
250
- value = value[1..-1] if "+-".include?(value[0])
255
+ first = value[0]
256
+ if first == ?-
257
+ sign = -1
258
+ value.slice!(0)
259
+ elsif first == ?+
260
+ value.slice!(0)
261
+ end
251
262
  if value.downcase == ".inf"
252
- return sign*SafeConstructor::INF_VALUE
263
+ return sign*INF_VALUE
253
264
  elsif value.downcase == ".nan"
254
- return SafeConstructor::NAN_VALUE
265
+ return NAN_VALUE
255
266
  elsif value.include?(?:)
256
267
  digits = (value.split(/:/).map {|val| val.to_f}).reverse
257
268
  base = 1
@@ -275,7 +286,7 @@ module RbYAML
275
286
 
276
287
  def construct_yaml_timestamp(node)
277
288
  value = construct_scalar(node)
278
- match = SafeConstructor::TIMESTAMP_REGEXP.match(node.value)
289
+ match = TIMESTAMP_REGEXP.match(node.value)
279
290
  values = match.captures.map {|val| val.to_i}
280
291
  fraction = values[6]
281
292
  if fraction != 0
@@ -292,11 +303,11 @@ module RbYAML
292
303
  # Note: we do not check for duplicate keys, because its too
293
304
  # CPU-expensive.
294
305
  raise ConstructorError.new("while constructing an ordered map", node.start_mark,
295
- "expected a sequence, but found #{node.tid}", node.start_mark) if !SequenceNode === node
306
+ "expected a sequence, but found #{node.tid}", node.start_mark) if !node.__is_sequence
296
307
  omap = []
297
308
  for subnode in node.value
298
309
  raise ConstructorError.new("while constructing an ordered map", node.start_mark,
299
- "expected a mapping of length 1, but found #{subnode.tid}",subnode.start_mark) if !MappingNode === subnode
310
+ "expected a mapping of length 1, but found #{subnode.tid}",subnode.start_mark) if !subnode.__is_mapping
300
311
  raise ConstructorError.new("while constructing an ordered map", node.start_mark,
301
312
  "expected a single mapping item, but found #{subnode.value.length} items",subnode.start_mark) if subnode.value.length != 1
302
313
  key_node = subnode.value.keys[0]
@@ -359,7 +370,7 @@ module RbYAML
359
370
  end
360
371
  end
361
372
 
362
- BaseConstructor::add_constructor('tag:yaml.org,2002:null',:construct_yaml_null)
373
+ SafeConstructor::add_constructor('tag:yaml.org,2002:null',:construct_yaml_null)
363
374
  BaseConstructor::add_constructor('tag:yaml.org,2002:bool',:construct_yaml_bool)
364
375
  BaseConstructor::add_constructor('tag:yaml.org,2002:int',:construct_yaml_int)
365
376
  BaseConstructor::add_constructor('tag:yaml.org,2002:float',:construct_yaml_float)
@@ -375,7 +386,6 @@ module RbYAML
375
386
 
376
387
  BaseConstructor::add_multi_constructor("!ruby/object:",:construct_ruby)
377
388
 
378
- module Constructor
379
- include SafeConstructor
389
+ class Constructor < SafeConstructor
380
390
  end
381
391
  end