udat 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/udat.rb +32 -4
- metadata +2 -2
data/lib/udat.rb
CHANGED
@@ -52,6 +52,11 @@ class Udat
|
|
52
52
|
|
53
53
|
[rational|2/3]
|
54
54
|
|
55
|
+
The following 7 characters must be escaped with a backslash, when
|
56
|
+
being part of a tag or being part of the content of a scalar:
|
57
|
+
|
58
|
+
\< \> \[ \] \| \~ \\
|
59
|
+
|
55
60
|
|
56
61
|
Arrays (or sets):
|
57
62
|
|
@@ -69,6 +74,21 @@ class Udat
|
|
69
74
|
References like in YAML with &id and *id
|
70
75
|
are not directly supported by UDAT.
|
71
76
|
|
77
|
+
Empty arrays, sets or maps must contain the ~ character, to avoid
|
78
|
+
ambiguity with scalars:
|
79
|
+
|
80
|
+
[ ] scalar containing three spaces
|
81
|
+
[ ~ ] empty array
|
82
|
+
[list of numbers| ~ ] empty array, tagged with "list of numbers"
|
83
|
+
[ ~ comment ] empty array with a comment
|
84
|
+
[ comment ~ ] another empty array with a comment
|
85
|
+
[ ~~ ] empty array too (multiple ~ are allowed)
|
86
|
+
|
87
|
+
It is also allowed to write ~ in non-empty arrays. In that case the ~
|
88
|
+
symbol is ignored.
|
89
|
+
|
90
|
+
[~ [1] [2] [3] ] Array containing "1", "2" and "3"
|
91
|
+
|
72
92
|
|
73
93
|
Ordered or unordered maps:
|
74
94
|
|
@@ -145,7 +165,7 @@ class Udat
|
|
145
165
|
# Returns an escaped version of a string, where backslashes are preceding
|
146
166
|
# certain reserved characters.
|
147
167
|
def self.escape_string(string)
|
148
|
-
string.to_s.gsub /([<>\[\]
|
168
|
+
string.to_s.gsub /([<>\[\]|~\\])/, "\\\\\\1"
|
149
169
|
end
|
150
170
|
# Calls Udat.escape_string.
|
151
171
|
def escape_string(string)
|
@@ -245,8 +265,8 @@ class Udat
|
|
245
265
|
if char.empty?
|
246
266
|
raise UdatParseError, "Backslash at end of input."
|
247
267
|
end
|
248
|
-
if char =~ /([<>\[\]
|
249
|
-
string << char
|
268
|
+
if char =~ /([<>\[\]|~\\])/
|
269
|
+
string << char if string
|
250
270
|
elsif char == "\n"
|
251
271
|
elsif char == "\r"
|
252
272
|
next_char = input[pos + 1, 1]
|
@@ -259,9 +279,16 @@ class Udat
|
|
259
279
|
if tag
|
260
280
|
raise UdatParseError, "Multiple occurrences of pipe symbol."
|
261
281
|
end
|
282
|
+
unless string
|
283
|
+
raise UdatParseError, "Unexpected occurrence of pipe symbol."
|
284
|
+
end
|
262
285
|
tag = string
|
263
286
|
string = ""
|
264
287
|
pos += 1
|
288
|
+
when "~"
|
289
|
+
collection ||= UdatCollection.new(tag, [])
|
290
|
+
string = nil
|
291
|
+
pos += 1
|
265
292
|
when "<"
|
266
293
|
if key
|
267
294
|
raise UdatParseError, "Unexpected opening angle bracket."
|
@@ -289,7 +316,7 @@ class Udat
|
|
289
316
|
when "]"
|
290
317
|
break
|
291
318
|
else
|
292
|
-
string << char
|
319
|
+
string << char if string
|
293
320
|
pos += 1
|
294
321
|
end
|
295
322
|
end
|
@@ -810,6 +837,7 @@ class UdatCollection < Udat
|
|
810
837
|
def encoded_content
|
811
838
|
synchronize do
|
812
839
|
return (
|
840
|
+
@entries.empty? ? "~" :
|
813
841
|
@entries.collect do |key, value|
|
814
842
|
if key
|
815
843
|
"<#{key.encode}>[#{value.encode}]"
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: udat
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2007-05-
|
6
|
+
version: 1.2.0
|
7
|
+
date: 2007-05-25 00:00:00 +00:00
|
8
8
|
summary: Parser and generator for UDAT documents, a generic data format similar to XML or YAML.
|
9
9
|
require_paths:
|
10
10
|
- lib/
|