sdl4r 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,3 +1,298 @@
1
- == sdl4r
1
+ == SDL (Simple Declarative Language)
2
2
 
3
+ SDL documents are made up of Tags. A Tag contains
3
4
 
5
+ * a name (if not present, the name "content" is used)
6
+ * a namespace (optional)
7
+ * 0 or more values (optional)
8
+ * 0 or more attributes (optional)
9
+ * 0 or more children (optional)
10
+
11
+ For the SDL code:
12
+
13
+ size 4
14
+ smoker false
15
+
16
+
17
+ Assuming this code is in a file called <tt>values.sdl</tt>, the values can be read
18
+ using the following code (ignoring exceptions):
19
+
20
+ root = Tag.new("root").read(Pathname.new("values.sdl"))
21
+ size = root.child("size").value
22
+ smoker = root.child("smoker").value
23
+
24
+ A tag is basically a data structure with a list of values, a map of
25
+ attributes, and (if it has a body) child tags. In the example above, the
26
+ <tt>values.sdl</tt> file is read into a tag called "root". It has two children
27
+ (tags) called "size" and "smoker". Both these children have one value, no
28
+ attributes, and no bodies.
29
+
30
+ SDL is often used for simple key-value mappings. To simplify things Tag
31
+ has the methods getValue and setValue which operate on the first element in
32
+ the values list. Also notice SDL understands types which are determined
33
+ using type inference.
34
+
35
+ The example above used the simple format common in property files:
36
+
37
+ name value
38
+
39
+ The full SDL tag format is:
40
+
41
+ namespace:name value_list attribute_list {
42
+ children_tags
43
+ }
44
+
45
+ where value_list is zero or more space separated SDL literals and
46
+ attribute_list is zero or more space separated <tt>(namespace:)key=value</tt> pairs.
47
+ The name, namespace, and keys are SDL identifiers. Values are SDL literals.
48
+ Namespace is optional for both tag names and attributes. Tag bodies are also
49
+ optional. SDL identifiers begin with a unicode letter or an underscore (_)
50
+ followed by zero or more unicode letters, numbers, underscores (_),
51
+ dashes (-) and periods (.).
52
+
53
+ == Anonymous Tags
54
+
55
+ SDL also supports anonymous tags which are assigned the name "content".
56
+ An anonymous tag starts with a literal and is followed by zero or more
57
+ additional literals and zero or more attributes. The examples section below
58
+ demonstrates the use of anonymous tags.
59
+
60
+ Tags without bodies are terminated by a new line character (\n) and may be
61
+ continue onto the next line by placing a backslash (\) at the end of the
62
+ line. Tags may be nested to an arbitrary depth. SDL ignores all other white
63
+ space characters between tokens. Although nested blocks are indented by
64
+ convention, tabs have no significance in the language.
65
+
66
+ == String literals
67
+
68
+ There are two ways to write String literals.
69
+
70
+ === Starting and ending with double quotes (")
71
+
72
+ Double quotes, backslash characters (\), and new lines (\n) within this type of String literal
73
+ must be escaped like so:
74
+
75
+ file "C:\\folder\\file.txt"
76
+ say "I said \"something\""
77
+
78
+ This type of String literal can be continued on the next line by placing a
79
+ backslash (\) at the end of the line like so:
80
+
81
+ line "this is a \
82
+ long string of text"
83
+
84
+ White space before the first character in the second line will be ignored.
85
+
86
+ === Starting and ending with a backquote (`)
87
+
88
+ This type of string literal
89
+ can only be ended with a second backquote (`). It is not necessary (or
90
+ possible) to escape any type of character within a backquote string
91
+ literal. This type of literal can also span lines. All white spaces are
92
+ preserved including new lines.
93
+
94
+ Examples:
95
+
96
+ file `C:\folder\file.txt`
97
+ say `I said "something"`
98
+ regex `\w+\.suite\(\)`
99
+ long_line `This is
100
+ a long line
101
+ fee fi fo fum`
102
+
103
+ Note: SDL interprets new lines in `` String literals as a single new line
104
+ character (\n) regarless of the platform.
105
+
106
+ == Binary literals
107
+
108
+ Binary literals use base64 characters enclosed in square brackets ([]).
109
+ The binary literal type can also span lines. White space is ignored.
110
+
111
+ Examples:
112
+ key [sdf789GSfsb2+3324sf2] name="my key"
113
+ image [
114
+ R3df789GSfsb2edfSFSDF
115
+ uikuikk2349GSfsb2edfS
116
+ vFSDFR3df789GSfsb2edf
117
+ ]
118
+ upload from="ikayzo.com" data=[
119
+ R3df789GSfsb2edfSFSDF
120
+ uikuikk2349GSfsb2edfS
121
+ vFSDFR3df789GSfsb2edf
122
+ ]
123
+
124
+ == Date and Time Literals
125
+
126
+ SDL supports date, time span, and date/time literals. Date and Date/Time
127
+ literals use a 24 hour clock (0-23). If a timezone is not specified, the
128
+ default locale's timezone will be used.
129
+
130
+ Examples:
131
+
132
+ * create a tag called "date" with a date value of Dec 5, 2005
133
+ date 2005/12/05
134
+
135
+ * various time span literals
136
+ hours 03:00:00
137
+ minutes 00:12:00
138
+ seconds 00:00:42
139
+ short_time 00:12:32.423 # 12 minutes, 32 seconds, 423 milliseconds
140
+ long_time 30d:15:23:04.023 # 30 days, 15 hours, 23 mins, 4 secs, 23 millis
141
+ before -00:02:30 # 2 hours and 30 minutes ago
142
+
143
+ * a date time literal
144
+ in_japan 2005/12/05 14:12:23.345-JST
145
+
146
+ == Literal Types
147
+
148
+ SDL 1.0 has thirteen literal types (parenthesis indicate optional components)
149
+
150
+ 1. string (unicode) - examples: <tt>"hello"</tt> or <tt>`aloha`</tt>
151
+ 2. character (unicode) - example: <tt>'/'</tt>
152
+ Note: \uXXXX style unicode escapes are not supported (or needed because sdl files are UTF8)
153
+ 3. integer (32 bits signed) - example: <tt>123</tt>
154
+ 4. long integer (64 bits signed) - examples: <tt>123L</tt> or <tt>123l</tt>
155
+ 5. float (32 bits signed) - examples <tt>123.43F</tt> <tt>123.43f</tt>
156
+ 6. double float (64 bits signed) - example: <tt>123.43</tt> or <tt>123.43d</tt> or <tt>123.43D</tt>
157
+ 7. decimal (128+ bits signed) - example: <tt>123.44BD</tt> or <tt>123.44bd</tt>
158
+ 8. boolean - examples: <tt>true</tt> or <tt>false</tt> or <tt>on</tt> or <tt>off</tt>
159
+ 9. date yyyy/mm/dd - example <tt>2005/12/05</tt>
160
+ 10. date time yyyy/mm/dd hh:mm(:ss)(.xxx)(-ZONE)
161
+ example - <tt>2005/12/05 05:21:23.532-JST</tt>
162
+ notes: uses a 24 hour clock (0-23), only hours and minutes are mandatory
163
+ 11. time span using the format (d:)hh:mm:ss(.xxx)
164
+ notes: if the day component is included it must be suffixed with a lower case 'd'
165
+ examples
166
+ 12:14:42 # (12 hours, 14 minutes, 42 seconds)
167
+ 00:09:12 # (9 minutes, 12 seconds)
168
+ 00:00:01.023 # (1 second, 23 milliseconds)
169
+ 23d:05:21:23.532 # (23 days, 5 hours, 21 minutes, 23 seconds, 532 milliseconds)
170
+ 12. binary [base64] example - <tt>[sdf789GSfsb2+3324sf2]</tt>
171
+ 13. <tt>null</tt>
172
+
173
+
174
+ Timezones must be specified using a valid time zone ID (ex. America/Los_Angeles), three letter
175
+ abbreviation (ex. HST), or GMT(+/-)hh(:mm) formatted custom timezone (ex. GMT+02 or GMT+02:30)
176
+
177
+ These types are designed to be portable across Java, .NET, and other popular platforms.
178
+
179
+ == SDL Comments
180
+
181
+ SDL supports four comment types.
182
+
183
+ 1. // single line comments identicle to those used in Java, C, etc. // style
184
+ comments can occur anywhere in a line. All text after // up to the new line
185
+ will be ignored.
186
+ 2. # property style comments. They work the same way as //
187
+ 3. -- separator comments useful for visually dividing content. They work the same way as //
188
+ 4. Slash star (/*) style multiline comments. These begin with a slash
189
+ star and end with a star slash. Everything in between is ignored.
190
+
191
+
192
+ == Example
193
+
194
+ An example SDL file:
195
+
196
+ # a tag having only a name
197
+ my_tag
198
+
199
+ # three tags acting as name value pairs
200
+ first_name "Akiko"
201
+ last_name "Johnson"
202
+ height 68
203
+
204
+ # a tag with a value list
205
+ person "Akiko" "Johnson" 68
206
+
207
+ # a tag with attributes
208
+ person first_name="Akiko" last_name="Johnson" height=68
209
+
210
+ # a tag with values and attributes
211
+ person "Akiko" "Johnson" height=60
212
+
213
+ # a tag with attributes using namespaces
214
+ person name:first-name="Akiko" name:last-name="Johnson"
215
+
216
+ # a tag with values, attributes, namespaces, and children
217
+ my_namespace:person "Akiko" "Johnson" dimensions:height=68 {
218
+ son "Nouhiro" "Johnson"
219
+ daughter "Sabrina" "Johnson" location="Italy" {
220
+ hobbies "swimming" "surfing"
221
+ languages "English" "Italian"
222
+ smoker false
223
+ }
224
+ }
225
+
226
+ ------------------------------------------------------------------
227
+ // (notice the separator style comment above...)
228
+
229
+ # a log entry
230
+ # note - this tag has two values (date_time and string) and an
231
+ # attribute (error)
232
+ entry 2005/11/23 10:14:23.253-GMT "Something bad happened" error=true
233
+
234
+ # a long line
235
+ mylist "something" "another" true "shoe" 2002/12/13 "rock" \
236
+ "morestuff" "sink" "penny" 12:15:23.425
237
+
238
+ # a long string
239
+ text "this is a long rambling line of text with a continuation \
240
+ and it keeps going and going..."
241
+
242
+ # anonymous tag examples
243
+
244
+ files {
245
+ "/folder1/file.txt"
246
+ "/file2.txt"
247
+ }
248
+
249
+ # To retrieve the files as a list of strings
250
+ #
251
+ # List files = tag.getChild("files").getChildrenValues("content");
252
+ #
253
+ # We us the name "content" because the files tag has two children, each of
254
+ # which are anonymous tags (values with no name.) These tags are assigned
255
+ # the name "content"
256
+
257
+ matrix {
258
+ 1 2 3
259
+ 4 5 6
260
+ }
261
+
262
+ # To retrieve the values from the matrix (as a list of lists)
263
+ #
264
+ # List rows = tag.getChild("matrix").getChildrenValues("content");
265
+
266
+
267
+ Example of getting the "location" attribute from the "daughter" tag
268
+ above (ignoring exceptions)
269
+
270
+ root = SDL4R.read(Pathname.new("myfile.sdl"))
271
+ daughter = root.child("daughter", true) // recursive search
272
+ location = daughter.attribute("location")
273
+
274
+ SDL is normally stored in a file with the .sdl extension. These files
275
+ should always be encoded using UTF8. SDL fully supports unicode in
276
+ identifiers and literals.
277
+
278
+ == Ruby and SDL types
279
+
280
+ The following list gives what types are used in Ruby in order to represent SDL types.
281
+
282
+ *SDL*:: *Ruby*
283
+ unicode string:: String
284
+ unicode character:: single-character String
285
+ integer (32 bits signed):: Integer (Fixnum or Bignum)
286
+ long integer (64 bits signed):: Integer (Fixnum or Bignum)
287
+ float (32 bits signed):: Float
288
+ double float (64 bits signed):: Float
289
+ decimal (128+ bits signed):: Flt::DecNum (if installed; see http://flt.rubyforge.org/), core numeric classes otherwise
290
+ boolean:: true (TrueClass) and false (FalseClass)
291
+ date (day):: Date
292
+ date time:: DateTime
293
+ time span:: SdlTimeSpan
294
+ binary:: SdlBinary (to avoid confusion with simple strings)
295
+ null:: nil (NilClass)
296
+
297
+ TO FIX: the handling of floating numbers in Ruby being different from the Java world, the behavior
298
+ of SDL4R at limits might not be perfect for the time being.
data/Rakefile CHANGED
@@ -9,14 +9,14 @@ spec = Gem::Specification.new do |s|
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = "Simple Declarative Language for Ruby library"
11
11
  s.name = 'sdl4r'
12
- s.version = '0.9.1'
12
+ s.version = '0.9.2'
13
13
  s.requirements << 'none'
14
14
  s.require_path = 'lib'
15
- s.author = 'Philippe Vosges'
15
+ s.authors = ['Philippe Vosges', 'Daniel Leuck' ]
16
16
  s.email = 'sdl-users@ikayzo.org'
17
17
  s.rubyforge_project = 'sdl4r'
18
18
  s.homepage = 'http://www.ikayzo.org/confluence/display/SDL/Home'
19
- s.files = FileList['lib/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
19
+ s.files = FileList['lib/sdl4r/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*', 'doc/*'].to_a
20
20
  s.test_files = FileList[ 'test/**/*test.rb' ].to_a
21
21
  s.description = <<EOF
22
22
  The Simple Declarative Language provides an easy way to describe lists, maps,
@@ -33,7 +33,10 @@ Rake::GemPackageTask.new(spec) do |pkg|
33
33
  end
34
34
 
35
35
  Rake::RDocTask.new do |rd|
36
- rd.rdoc_files.include("lib/**/*.rb")
36
+ files = ['README', 'LICENSE', 'CHANGELOG',
37
+ 'lib/sdl4r/**/*.rb', 'doc/**/*.rdoc', 'test/*.rb']
38
+ rd.main = 'README'
39
+ rd.rdoc_files.include(files)
37
40
  rd.rdoc_dir = "doc"
38
41
  rd.title = "Simple Declarative Language for Ruby"
39
42
  end
data/TODO.txt CHANGED
@@ -27,16 +27,17 @@
27
27
  [x] Date + time test
28
28
  [x] Time zone tests
29
29
  [x] Number literal tests
30
- [ ] Strings literals (especially with line continuations)
31
- [ ] Sub tags tests
30
+ [x] Strings literals (especially with line continuations)
31
+ [x] Sub tags tests
32
32
  [x] "null" value test
33
33
  [x] Comment tests
34
34
  [ ] Bad syntax tests
35
35
  [ ] Test write (unit tests)
36
36
  [ ] Dates
37
37
  [ ] Numbers
38
- [ ] Use YARD in order to generate documentation ?
39
- [ ] In the documentation, present a table giving the returned Ruby type for each SDL type.
38
+ [A] Use YARD in order to generate documentation ?
39
+ ==> alternatively, I tried to generate some RDoc templates but none worked in Rake...
40
+ [x] In the documentation, present a table giving the returned Ruby type for each SDL type.
40
41
  [A] Change the interface of SdlTimeSpan to look like the interfaces of Date, DateTime or Time
41
42
  ==> Really? This is a timespan, not a date.
42
43
  [x] Have SdlTimeSpan implement Comparable
@@ -71,47 +72,58 @@
71
72
  [ ] See how Ruby floats relate to Java floats and doubles.
72
73
  [ ] Add tests for the SDL class
73
74
  [ ] Allow unicode characters in identifiers.
74
- [ ] It would probably be useful to allow people to replace the standard types by their own. This
75
+ [ ] FUTURE: It would probably be useful to allow people to replace the standard types by their own. This
75
76
  could be useful for dates or numbers, for instance.
76
77
  [N] To install a gem in the Netbeans gems repository, it needs to run as an administrator.
77
78
  Otherwise, it fails silently.
78
- [ ] Make it so that the tests pass (with errors or not), when Ftl (DecNum) is not available.
79
+ [x] Make it so that the tests pass (with errors or not), when Ftl (DecNum) is not available.
79
80
  [x] Fix the ParserTest test.
80
81
  [x] SDL 1.1: tag1; tag2 "a value"; tag3 name="foo"
81
82
  [x] Create a Tokenizer class
82
83
  [A] Test attributes with/without namespaces
83
84
  ==> Guess this is done in test_structures...
84
- [ ] Propose to Dan that the top level is considered as a root tag that can't have values but
85
- just attributes and sub-tags.
86
85
  [x] Fix Test.test_strings: support for Unicode
87
86
  ==> Seems to work.
88
- [ ] Consider being able to read text files that are not UTF-8(?)
87
+ [ ] FUTURE: Consider being able to read text files that are not UTF-8(?)
89
88
  [ ] BUG: the report on the line no in errors is off by 1 (at least in some cases)
90
- [ ] Try to move Reader, Tokenizer, etc to the private part of the SDL module
89
+ [x] Try to move Reader, Tokenizer, etc to the private part of the SDL module
91
90
  ==> Doesn't seem to make a difference.
91
+ ==> Moved to the Parser namespace.
92
92
  [x] Factorize "each_child..." methods in Tag and refactor "children(recursive, name)" consequently
93
93
  + invert "name" and "recursive" in "children()"
94
94
  [ ] Return copies or original arrays in Tag?
95
- [ ] BUG: test_tag_write_parse() does not work from the command line (ruby v1.8.7).
95
+ [A] BUG: test_tag_write_parse() does not work from the command line (ruby v1.8.7).
96
+ ==> This is normal provided that flt was not installed.
96
97
  [ ] Tag.to_string(): break up long lines using the backslash
97
98
  [ ] Tag.hash: the implementation is not very efficient.
98
- [ ] Implement reading from a URL(?) Other sources idiomatic in Ruby?
99
+ [x] Implement reading from a URL(?) Other sources idiomatic in Ruby?
100
+ ==> Strings, URIs, Pathnames, IOs
99
101
  [ ] See the XML and YAML APIs to find enhancements.
100
102
  [ ] Check the XML functionalities of Tag.
101
103
  [ ] Add tests for Tag
102
104
  [ ] Maybe some methods in the SDL module are not so useful to the general user: make them protected?
103
105
  [ ] FUTURE: xpath, ypath ==> sdlpath(?)
104
106
  [ ] FUTURE: evenemential parsing(?)
105
- [ ] Move Tokenizer, Reader, etc into the Parser module/class or prefix by Sdl
107
+ [x] Move Tokenizer, Reader, etc into the Parser module/class or prefix by Sdl
108
+ ==> moved to sdl4r/parser
106
109
  [ ] FUTURE: add a way to insert a tag after or before another(?)
107
110
  [ ] FUTURE: allow some way of generating YAML(?)
108
111
  [ ] FUTURE: allow to turn a YAML structure into a SDL one(?)
109
- [ ] Make a Gem
110
- [ ] Implement the convenience method of SDL (value(), list(), map())
112
+ [x] Make a Gem
113
+ [x] Implement the convenience method of SDL (value(), list(), map())
111
114
  [x] Move the test files to a sdl4r subdir
112
- [ ] 1.2: Ensure that there is a SDL.read() that returns a Tag
113
- [ ] 1.2: hasChild(), hasChildren(), getChildMap(), getChildStringMap() methods
114
- [ ] 1.3: periods in identifiers
115
- [ ] Create a History.txt file
116
- [ ] Setup the Rubyforge website
117
- [ ] See how both Subversion repositories can be handled (is it necessary?)
115
+ [x] 1.2: Ensure that there is a SDL.read() that returns a Tag
116
+ [x] 1.2: hasChild(), hasChildren() methods
117
+ [x] 1.2: getChildMap(), getChildStringMap() methods
118
+ [x] 1.3: periods in identifiers
119
+ [A] Create a History.txt file ==> See CHANGELOG
120
+ [x] Setup the Rubyforge website
121
+ [A] See how both Subversion repositories can be handled (is it necessary?)
122
+ ==> No need for the Rubyforge project anymore, it seems (we use Rubygem and gemcutter directly)
123
+ [x] Add info to README
124
+ [x] Add LICENSE & CHANGELOG files
125
+ [x] State in the README that without Flt, all the tests can't run.
126
+ ==> it's stated explicitely in the test
127
+ [w] Make it so that each test appears separately in test.rb (if possible)
128
+ [ ] Have the use of Flt be optional.
129
+ [ ] Turn Rationals to Floats in coerc_or_fail()?
data/doc/created.rid ADDED
@@ -0,0 +1 @@
1
+ Sat, 31 Jul 2010 01:26:33 +0900
@@ -0,0 +1,36 @@
1
+
2
+ <?xml version="1.0" encoding="iso-8859-1"?>
3
+ <!DOCTYPE html
4
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
+
7
+ <!--
8
+
9
+ Classes
10
+
11
+ -->
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
13
+ <head>
14
+ <title>Classes</title>
15
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
16
+ <link rel="stylesheet" href="rdoc-style.css" type="text/css" />
17
+ <base target="docwin" />
18
+ </head>
19
+ <body>
20
+ <div id="index">
21
+ <h1 class="section-bar">Classes</h1>
22
+ <div id="index-entries">
23
+ <a href="classes/SDL4R.html">SDL4R</a><br />
24
+ <a href="classes/SDL4R/Parser.html">SDL4R::Parser</a><br />
25
+ <a href="classes/SDL4R/Parser/Reader.html">SDL4R::Parser::Reader</a><br />
26
+ <a href="classes/SDL4R/Parser/TimeSpanWithZone.html">SDL4R::Parser::TimeSpanWithZone</a><br />
27
+ <a href="classes/SDL4R/Parser/Token.html">SDL4R::Parser::Token</a><br />
28
+ <a href="classes/SDL4R/Parser/Tokenizer.html">SDL4R::Parser::Tokenizer</a><br />
29
+ <a href="classes/SDL4R/SdlBinary.html">SDL4R::SdlBinary</a><br />
30
+ <a href="classes/SDL4R/SdlParseError.html">SDL4R::SdlParseError</a><br />
31
+ <a href="classes/SDL4R/SdlTimeSpan.html">SDL4R::SdlTimeSpan</a><br />
32
+ <a href="classes/SDL4R/Tag.html">SDL4R::Tag</a><br />
33
+ </div>
34
+ </div>
35
+ </body>
36
+ </html>