sdl4r 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,4 +1,38 @@
1
- == SDL (Simple Declarative Language)
1
+ = SDL (Simple Declarative Language)
2
+
3
+ == Getting Started with SDL4R
4
+
5
+ To get the Ruby Gem:
6
+
7
+ gem install sdl4r
8
+
9
+ Then, you can start reading SDL documents:
10
+
11
+ require 'pathname'
12
+ require 'sdl4r'
13
+
14
+ root = SDL4R::read(Pathname.new("my_directory/my_config.sdl"))
15
+ puts root.attribute("port")
16
+
17
+ Or you can create SDL documents with the API:
18
+
19
+ require 'fileutils'
20
+ require 'sdl4r'
21
+
22
+ root = SDL4R::Tag.new("root") do
23
+ new_child("server") do
24
+ set_attribute("port", 1234)
25
+ end
26
+ end
27
+ File.open("my_directory/my_config.sdl", "w") { |io|
28
+ io.write(root.children_to_string)
29
+ }
30
+
31
+ which will write the following in your file:
32
+
33
+ server port=1234
34
+
35
+ == SDL Documents
2
36
 
3
37
  SDL documents are made up of Tags. A Tag contains
4
38
 
@@ -50,6 +84,12 @@ optional. SDL identifiers begin with a unicode letter or an underscore (_)
50
84
  followed by zero or more unicode letters, numbers, underscores (_),
51
85
  dashes (-) and periods (.).
52
86
 
87
+ Tags without bodies are terminated by a new line character (\n) and may be
88
+ continue onto the next line by placing a backslash (\) at the end of the
89
+ line. Tags may be nested to an arbitrary depth. SDL ignores all other white
90
+ space characters between tokens. Although nested blocks are indented by
91
+ convention, tabs have no significance in the language.
92
+
53
93
  == Anonymous Tags
54
94
 
55
95
  SDL also supports anonymous tags which are assigned the name "content".
@@ -57,11 +97,13 @@ An anonymous tag starts with a literal and is followed by zero or more
57
97
  additional literals and zero or more attributes. The examples section below
58
98
  demonstrates the use of anonymous tags.
59
99
 
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.
100
+ greetings {
101
+ "hello" language="English"
102
+ }
103
+
104
+ # If we have a handle on the "greetings" tag we can access the
105
+ # anonymous child tag by calling
106
+ # Tag child1 = greetingTag.getChild("content");
65
107
 
66
108
  == String literals
67
109
 
@@ -296,3 +338,34 @@ null:: nil (NilClass)
296
338
 
297
339
  TO FIX: the handling of floating numbers in Ruby being different from the Java world, the behavior
298
340
  of SDL4R at limits might not be perfect for the time being.
341
+
342
+ == UTF-8 Support
343
+
344
+ In Ruby 1.8, in order to enable UTF-8 support, you may have to declare the following lines:
345
+
346
+ $KCODE = 'u'
347
+ require 'jcode'
348
+
349
+ This will give you correct input and output and correct UTF-8 "general" sorting.
350
+ Alternatively you can use the following options when launching the Ruby interpreter:
351
+
352
+ /path/to/ruby -Ku -rjcode
353
+
354
+
355
+ == License
356
+
357
+ Simple Declarative Language (SDL) for Ruby
358
+
359
+ Copyright 2005 Ikayzo, inc.
360
+
361
+ This program is free software. You can distribute or modify it under the
362
+ terms of the GNU Lesser General Public License version 2.1 as published by
363
+ the Free Software Foundation.
364
+
365
+ This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
366
+ INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
367
+ See the GNU Lesser General Public License for more details.
368
+
369
+ You should have received a copy of the GNU Lesser General Public License
370
+ along with this program; if not, contact the Free Software Foundation, Inc.,
371
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
data/Rakefile CHANGED
@@ -3,16 +3,17 @@ require 'rake/clean'
3
3
  require 'rake/testtask'
4
4
  require 'rake/rdoctask'
5
5
  require 'rake/gempackagetask'
6
+ require 'rake/packagetask'
6
7
  require 'rubygems'
7
8
 
8
9
  spec = Gem::Specification.new do |s|
9
10
  s.platform = Gem::Platform::RUBY
10
11
  s.summary = "Simple Declarative Language for Ruby library"
11
12
  s.name = 'sdl4r'
12
- s.version = '0.9.2'
13
+ s.version = '0.9.3'
13
14
  s.requirements << 'none'
14
15
  s.require_path = 'lib'
15
- s.authors = ['Philippe Vosges', 'Daniel Leuck' ]
16
+ s.authors = ['Philippe Vosges', 'Daniel Leuck']
16
17
  s.email = 'sdl-users@ikayzo.org'
17
18
  s.rubyforge_project = 'sdl4r'
18
19
  s.homepage = 'http://www.ikayzo.org/confluence/display/SDL/Home'
@@ -27,6 +28,18 @@ spec = Gem::Specification.new do |s|
27
28
  EOF
28
29
  end
29
30
 
31
+ Rake::PackageTask.new(spec.name, spec.version) do |p|
32
+ p.need_zip = true
33
+ p.need_tar = false
34
+ p.need_tar_gz = false
35
+ p.need_tar_bz2 = false
36
+ #p.package_files.include("lib/sdl4r/**/*.rb")
37
+
38
+ # If "zip" is not available, we try 7-zip.
39
+ system("zip")
40
+ p.zip_command = "7z a -tzip" if $?.exitstatus == 127
41
+ end
42
+
30
43
  Rake::GemPackageTask.new(spec) do |pkg|
31
44
  pkg.need_zip = true
32
45
  pkg.need_tar = true
data/TODO.txt CHANGED
@@ -62,6 +62,8 @@
62
62
  ==> Time only works in UTC, which means that the original zone code is lost.
63
63
  ==> DateTime doesn't give the zone code but only the offset.
64
64
  [ ] Use TzTime? Use a custom object that knows whether a time zone was specified?
65
+ ==> http://tztime.rubyforge.org/
66
+ ==> along with TzInfo: http://tzinfo.rubyforge.org/
65
67
  [x] BUG: Base64 wrapped lines are 64 chars long and not 72 (traditionnal length)
66
68
  ==> Because of a limitation in the regular expressions ==> find another algorithm
67
69
  [x] See whether we can do better for numbers of arbitrary precision (decimals).
@@ -72,7 +74,7 @@
72
74
  [ ] See how Ruby floats relate to Java floats and doubles.
73
75
  [ ] Add tests for the SDL class
74
76
  [ ] Allow unicode characters in identifiers.
75
- [ ] FUTURE: It would probably be useful to allow people to replace the standard types by their own. This
77
+ [ ] FUTURE: It might be useful to allow people to replace the standard types by their own. This
76
78
  could be useful for dates or numbers, for instance.
77
79
  [N] To install a gem in the Netbeans gems repository, it needs to run as an administrator.
78
80
  Otherwise, it fails silently.
@@ -96,12 +98,13 @@
96
98
  ==> This is normal provided that flt was not installed.
97
99
  [ ] Tag.to_string(): break up long lines using the backslash
98
100
  [ ] Tag.hash: the implementation is not very efficient.
101
+ ==> Difficult to make better and simple
99
102
  [x] Implement reading from a URL(?) Other sources idiomatic in Ruby?
100
103
  ==> Strings, URIs, Pathnames, IOs
101
- [ ] See the XML and YAML APIs to find enhancements.
102
- [ ] Check the XML functionalities of Tag.
103
- [ ] Add tests for Tag
104
- [ ] Maybe some methods in the SDL module are not so useful to the general user: make them protected?
104
+ [x] See the XML and YAML APIs to find enhancements.
105
+ [x] Check the XML functionalities of Tag.
106
+ [x] Add tests for Tag
107
+ [x] Maybe some methods in the SDL module are not so useful to the general user: make them protected?
105
108
  [ ] FUTURE: xpath, ypath ==> sdlpath(?)
106
109
  [ ] FUTURE: evenemential parsing(?)
107
110
  [x] Move Tokenizer, Reader, etc into the Parser module/class or prefix by Sdl
@@ -126,4 +129,32 @@
126
129
  ==> it's stated explicitely in the test
127
130
  [w] Make it so that each test appears separately in test.rb (if possible)
128
131
  [ ] Have the use of Flt be optional.
129
- [ ] Turn Rationals to Floats in coerc_or_fail()?
132
+ [ ] Be sure that there is a way to change the precision of Flt outside of SDL4R
133
+ [ ] Turn Rationals to Floats in coerc_or_fail()?
134
+ [ ] BUG: "rake package" tries to archive the contents twice: once with the command that I configure
135
+ in Rakefime, once with a zip command that can't work on my machine (zip is not installed). Why?
136
+ At least, the first archive is created and seems correct.
137
+ [x] Add a "Getting Started" chapter to the README
138
+ [ ] FUTURE: Would we need a "write" method in SDL4R?
139
+ [ ] Implement coerce_or_fail: it is right now allowed to add any garbage to the SDL tags
140
+ [x] Fix the doc of Tag.add_value
141
+ [ ] Add tests and release a RC or beta version
142
+ [x] Make the parser components disappear from the RDoc
143
+ [x] Add tests for Tag attributes
144
+ [x] Add tests for Tag to_child_hash, etc
145
+ [x] Add tests for Tag eql?, etc
146
+ [x] Should we interpret arrays in arrays in Tag.<< as a structure specification?
147
+ Example: tag << [[1, 2], [3, 4]]
148
+ could mean adding 2 anonymous "content" tags to "tag" with the corresponding values
149
+ ==> Works fine for matrices
150
+ [x] Make the methods of Tag that take a block have a better yield doc/completion
151
+ ==> I added :yields: RDoc directives, which doesn't look like it's helping but I guess that's
152
+ all I can do for now.
153
+ [x] See if we can not support the right order for the namespaces
154
+ attribute("a1") # => just the name
155
+ attribute("ns1", "a1") # => namespace + name (instead of attribute("a1", "ns1") now)
156
+ [N] Never call a class "Test" => it can easily conflict with the "Test" module of Test::Unit and
157
+ then, it becomes quite difficult to understand why.
158
+ [x] Add tests for to_xml_string
159
+ [x] Be stricter and more explicit with Tag and attributes name/namespace
160
+ [x] Fix set_attributes: it was correct before.
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Sat, 31 Jul 2010 01:26:33 +0900
1
+ Thu, 05 Aug 2010 13:24:04 +0900
@@ -22,10 +22,6 @@
22
22
  <div id="index-entries">
23
23
  <a href="classes/SDL4R.html">SDL4R</a><br />
24
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
25
  <a href="classes/SDL4R/SdlBinary.html">SDL4R::SdlBinary</a><br />
30
26
  <a href="classes/SDL4R/SdlParseError.html">SDL4R::SdlParseError</a><br />
31
27
  <a href="classes/SDL4R/SdlTimeSpan.html">SDL4R::SdlTimeSpan</a><br />
@@ -20,121 +20,88 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
- <a href="classes/SDL4R/Tag.html#M000048"><< (SDL4R::Tag)</a><br />
24
- <a href="classes/SDL4R/SdlTimeSpan.html#M000114"><=> (SDL4R::SdlTimeSpan)</a><br />
25
- <a href="classes/SDL4R/Tag.html#M000084">== (SDL4R::Tag)</a><br />
26
- <a href="classes/SDL4R/SdlBinary.html#M000088">== (SDL4R::SdlBinary)</a><br />
27
- <a href="classes/SDL4R/SdlTimeSpan.html#M000113">== (SDL4R::SdlTimeSpan)</a><br />
23
+ <a href="classes/SDL4R/Tag.html#M000035"><< (SDL4R::Tag)</a><br />
24
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000029"><=> (SDL4R::SdlTimeSpan)</a><br />
25
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000028">== (SDL4R::SdlTimeSpan)</a><br />
26
+ <a href="classes/SDL4R/SdlBinary.html#M000078">== (SDL4R::SdlBinary)</a><br />
27
+ <a href="classes/SDL4R/Tag.html#M000071">== (SDL4R::Tag)</a><br />
28
28
  <a href="classes/SDL4R.html#M000008">SdlBinary (SDL4R)</a><br />
29
- <a href="classes/SDL4R/Tag.html#M000047">add_child (SDL4R::Tag)</a><br />
30
- <a href="classes/SDL4R/Tag.html#M000061">add_value (SDL4R::Tag)</a><br />
31
- <a href="classes/SDL4R/Tag.html#M000068">attribute (SDL4R::Tag)</a><br />
32
- <a href="classes/SDL4R/Tag.html#M000070">attributes (SDL4R::Tag)</a><br />
33
- <a href="classes/SDL4R/Tag.html#M000074">attributes= (SDL4R::Tag)</a><br />
34
- <a href="classes/SDL4R/Tag.html#M000056">child (SDL4R::Tag)</a><br />
35
- <a href="classes/SDL4R/Tag.html#M000053">child_count (SDL4R::Tag)</a><br />
36
- <a href="classes/SDL4R/Tag.html#M000054">children (SDL4R::Tag)</a><br />
37
- <a href="classes/SDL4R/Tag.html#M000082">children_to_string (SDL4R::Tag)</a><br />
38
- <a href="classes/SDL4R/Tag.html#M000055">children_values (SDL4R::Tag)</a><br />
39
- <a href="classes/SDL4R/Tag.html#M000072">clear_attributes (SDL4R::Tag)</a><br />
40
- <a href="classes/SDL4R/Tag.html#M000050">clear_children (SDL4R::Tag)</a><br />
41
- <a href="classes/SDL4R/Tag.html#M000064">clear_values (SDL4R::Tag)</a><br />
42
- <a href="classes/SDL4R/Parser/Tokenizer.html#M000014">close (SDL4R::Parser::Tokenizer)</a><br />
43
- <a href="classes/SDL4R/Parser/Reader.html#M000044">close (SDL4R::Parser::Reader)</a><br />
44
- <a href="classes/SDL4R.html#M000003">coerce_or_fail (SDL4R)</a><br />
45
- <a href="classes/SDL4R/Parser/Reader.html#M000036">current_char (SDL4R::Parser::Reader)</a><br />
46
- <a href="classes/SDL4R/SdlTimeSpan.html#M000096">days (SDL4R::SdlTimeSpan)</a><br />
47
- <a href="classes/SDL4R/SdlBinary.html#M000092">decode64 (SDL4R::SdlBinary)</a><br />
48
- <a href="classes/SDL4R/Parser/TimeSpanWithZone.html#M000012">default_time_zone_offset (SDL4R::Parser::TimeSpanWithZone)</a><br />
49
- <a href="classes/SDL4R/Parser/Reader.html#M000030">end_of_file? (SDL4R::Parser::Reader)</a><br />
50
- <a href="classes/SDL4R/Parser/Reader.html#M000032">end_of_line? (SDL4R::Parser::Reader)</a><br />
51
- <a href="classes/SDL4R/SdlTimeSpan.html#M000112">eql? (SDL4R::SdlTimeSpan)</a><br />
52
- <a href="classes/SDL4R/SdlBinary.html#M000089">eql? (SDL4R::SdlBinary)</a><br />
53
- <a href="classes/SDL4R/Tag.html#M000083">eql? (SDL4R::Tag)</a><br />
54
- <a href="classes/SDL4R/Parser/Tokenizer.html#M000016">expecting_but_got (SDL4R::Parser::Tokenizer)</a><br />
55
- <a href="classes/SDL4R/Parser/Reader.html#M000040">find_next_in_line (SDL4R::Parser::Reader)</a><br />
56
- <a href="classes/SDL4R.html#M000002">format (SDL4R)</a><br />
57
- <a href="classes/SDL4R/Parser/Reader.html#M000035">get_line_char (SDL4R::Parser::Reader)</a><br />
58
- <a href="classes/SDL4R/Tag.html#M000069">has_attribute? (SDL4R::Tag)</a><br />
59
- <a href="classes/SDL4R/Tag.html#M000057">has_child? (SDL4R::Tag)</a><br />
60
- <a href="classes/SDL4R/Tag.html#M000058">has_children? (SDL4R::Tag)</a><br />
61
- <a href="classes/SDL4R/Tag.html#M000062">has_value? (SDL4R::Tag)</a><br />
62
- <a href="classes/SDL4R/Tag.html#M000085">hash (SDL4R::Tag)</a><br />
63
- <a href="classes/SDL4R/SdlTimeSpan.html#M000111">hash (SDL4R::SdlTimeSpan)</a><br />
64
- <a href="classes/SDL4R/SdlBinary.html#M000090">hash (SDL4R::SdlBinary)</a><br />
65
- <a href="classes/SDL4R/SdlTimeSpan.html#M000097">hours (SDL4R::SdlTimeSpan)</a><br />
66
- <a href="classes/SDL4R/Parser/Tokenizer.html#M000020">line (SDL4R::Parser::Tokenizer)</a><br />
67
- <a href="classes/SDL4R/Parser/Reader.html#M000027">line_length (SDL4R::Parser::Reader)</a><br />
68
- <a href="classes/SDL4R/Parser/Tokenizer.html#M000018">line_no (SDL4R::Parser::Tokenizer)</a><br />
69
- <a href="classes/SDL4R/Parser/Token.html#M000022">literal? (SDL4R::Parser::Token)</a><br />
70
- <a href="classes/SDL4R/SdlTimeSpan.html#M000100">milliseconds (SDL4R::SdlTimeSpan)</a><br />
71
- <a href="classes/SDL4R/SdlTimeSpan.html#M000098">minutes (SDL4R::SdlTimeSpan)</a><br />
72
- <a href="classes/SDL4R/Parser/Reader.html#M000031">more_chars_in_line? (SDL4R::Parser::Reader)</a><br />
73
- <a href="classes/SDL4R/Tag.html#M000075">name= (SDL4R::Tag)</a><br />
74
- <a href="classes/SDL4R/Tag.html#M000076">namespace= (SDL4R::Tag)</a><br />
75
- <a href="classes/SDL4R/SdlTimeSpan.html#M000105">negate (SDL4R::SdlTimeSpan)</a><br />
76
- <a href="classes/SDL4R/Parser/Reader.html#M000026">new (SDL4R::Parser::Reader)</a><br />
77
- <a href="classes/SDL4R/Parser/Tokenizer.html#M000013">new (SDL4R::Parser::Tokenizer)</a><br />
78
- <a href="classes/SDL4R/SdlTimeSpan.html#M000094">new (SDL4R::SdlTimeSpan)</a><br />
79
- <a href="classes/SDL4R/SdlParseError.html#M000093">new (SDL4R::SdlParseError)</a><br />
80
- <a href="classes/SDL4R/SdlBinary.html#M000087">new (SDL4R::SdlBinary)</a><br />
81
- <a href="classes/SDL4R/Tag.html#M000045">new (SDL4R::Tag)</a><br />
82
- <a href="classes/SDL4R/Parser/Token.html#M000021">new (SDL4R::Parser::Token)</a><br />
83
- <a href="classes/SDL4R/Parser/TimeSpanWithZone.html#M000011">new (SDL4R::Parser::TimeSpanWithZone)</a><br />
84
- <a href="classes/SDL4R/Parser.html#M000009">new (SDL4R::Parser)</a><br />
85
- <a href="classes/SDL4R/Tag.html#M000046">new_child (SDL4R::Tag)</a><br />
86
- <a href="classes/SDL4R/Parser/Token.html#M000023">object_for_literal (SDL4R::Parser::Token)</a><br />
87
- <a href="classes/SDL4R/Parser.html#M000010">parse (SDL4R::Parser)</a><br />
88
- <a href="classes/SDL4R/Parser/Tokenizer.html#M000015">parse_error (SDL4R::Parser::Tokenizer)</a><br />
89
- <a href="classes/SDL4R/Parser/Token.html#M000025">parse_time_span_with_zone (SDL4R::Parser::Token)</a><br />
90
- <a href="classes/SDL4R/Parser/Tokenizer.html#M000019">pos (SDL4R::Parser::Tokenizer)</a><br />
91
- <a href="classes/SDL4R/Parser/Reader.html#M000039">previous_char (SDL4R::Parser::Reader)</a><br />
92
- <a href="classes/SDL4R/Tag.html#M000077">read (SDL4R::Tag)</a><br />
93
- <a href="classes/SDL4R.html#M000001">read (SDL4R)</a><br />
94
- <a href="classes/SDL4R/Parser/Reader.html#M000038">read_char (SDL4R::Parser::Reader)</a><br />
95
- <a href="classes/SDL4R/Tag.html#M000078">read_from_io (SDL4R::Tag)</a><br />
96
- <a href="classes/SDL4R/Parser/Reader.html#M000028">read_line (SDL4R::Parser::Reader)</a><br />
97
- <a href="classes/SDL4R/Parser/Tokenizer.html#M000017">read_line_tokens (SDL4R::Parser::Tokenizer)</a><br />
98
- <a href="classes/SDL4R/Parser/Reader.html#M000043">read_raw_line (SDL4R::Parser::Reader)</a><br />
99
- <a href="classes/SDL4R/Tag.html#M000071">remove_attribute (SDL4R::Tag)</a><br />
100
- <a href="classes/SDL4R/Tag.html#M000049">remove_child (SDL4R::Tag)</a><br />
101
- <a href="classes/SDL4R/Tag.html#M000063">remove_value (SDL4R::Tag)</a><br />
102
- <a href="classes/SDL4R/Parser/Reader.html#M000029">rest_of_line (SDL4R::Parser::Reader)</a><br />
103
- <a href="classes/SDL4R/SdlTimeSpan.html#M000106">roll_days (SDL4R::SdlTimeSpan)</a><br />
104
- <a href="classes/SDL4R/SdlTimeSpan.html#M000107">roll_hours (SDL4R::SdlTimeSpan)</a><br />
105
- <a href="classes/SDL4R/SdlTimeSpan.html#M000110">roll_milliseconds (SDL4R::SdlTimeSpan)</a><br />
106
- <a href="classes/SDL4R/SdlTimeSpan.html#M000108">roll_minutes (SDL4R::SdlTimeSpan)</a><br />
107
- <a href="classes/SDL4R/SdlTimeSpan.html#M000109">roll_seconds (SDL4R::SdlTimeSpan)</a><br />
108
- <a href="classes/SDL4R/SdlTimeSpan.html#M000099">seconds (SDL4R::SdlTimeSpan)</a><br />
109
- <a href="classes/SDL4R/Tag.html#M000067">set_attribute (SDL4R::Tag)</a><br />
110
- <a href="classes/SDL4R/Tag.html#M000073">set_attributes (SDL4R::Tag)</a><br />
111
- <a href="classes/SDL4R/SdlTimeSpan.html#M000095">sign (SDL4R::SdlTimeSpan)</a><br />
112
- <a href="classes/SDL4R/Parser/Reader.html#M000037">skip_char (SDL4R::Parser::Reader)</a><br />
113
- <a href="classes/SDL4R/Parser/Reader.html#M000033">skip_line (SDL4R::Parser::Reader)</a><br />
114
- <a href="classes/SDL4R/Parser/Reader.html#M000041">skip_to (SDL4R::Parser::Reader)</a><br />
115
- <a href="classes/SDL4R/Parser/Reader.html#M000034">skip_whitespaces (SDL4R::Parser::Reader)</a><br />
116
- <a href="classes/SDL4R/Parser/Reader.html#M000042">substring (SDL4R::Parser::Reader)</a><br />
29
+ <a href="classes/SDL4R/Tag.html#M000034">add_child (SDL4R::Tag)</a><br />
30
+ <a href="classes/SDL4R/Tag.html#M000048">add_value (SDL4R::Tag)</a><br />
31
+ <a href="classes/SDL4R/Tag.html#M000055">attribute (SDL4R::Tag)</a><br />
32
+ <a href="classes/SDL4R/Tag.html#M000057">attributes (SDL4R::Tag)</a><br />
33
+ <a href="classes/SDL4R/Tag.html#M000061">attributes= (SDL4R::Tag)</a><br />
34
+ <a href="classes/SDL4R/Tag.html#M000043">child (SDL4R::Tag)</a><br />
35
+ <a href="classes/SDL4R/Tag.html#M000040">child_count (SDL4R::Tag)</a><br />
36
+ <a href="classes/SDL4R/Tag.html#M000041">children (SDL4R::Tag)</a><br />
37
+ <a href="classes/SDL4R/Tag.html#M000069">children_to_string (SDL4R::Tag)</a><br />
38
+ <a href="classes/SDL4R/Tag.html#M000042">children_values (SDL4R::Tag)</a><br />
39
+ <a href="classes/SDL4R/Tag.html#M000059">clear_attributes (SDL4R::Tag)</a><br />
40
+ <a href="classes/SDL4R/Tag.html#M000037">clear_children (SDL4R::Tag)</a><br />
41
+ <a href="classes/SDL4R/Tag.html#M000051">clear_values (SDL4R::Tag)</a><br />
42
+ <a href="classes/SDL4R.html#M000002">coerce_or_fail (SDL4R)</a><br />
43
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000011">days (SDL4R::SdlTimeSpan)</a><br />
44
+ <a href="classes/SDL4R/SdlBinary.html#M000082">decode64 (SDL4R::SdlBinary)</a><br />
45
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000027">eql? (SDL4R::SdlTimeSpan)</a><br />
46
+ <a href="classes/SDL4R/SdlBinary.html#M000079">eql? (SDL4R::SdlBinary)</a><br />
47
+ <a href="classes/SDL4R/Tag.html#M000070">eql? (SDL4R::Tag)</a><br />
48
+ <a href="classes/SDL4R.html#M000001">format (SDL4R)</a><br />
49
+ <a href="classes/SDL4R/Tag.html#M000056">has_attribute? (SDL4R::Tag)</a><br />
50
+ <a href="classes/SDL4R/Tag.html#M000044">has_child? (SDL4R::Tag)</a><br />
51
+ <a href="classes/SDL4R/Tag.html#M000045">has_children? (SDL4R::Tag)</a><br />
52
+ <a href="classes/SDL4R/Tag.html#M000049">has_value? (SDL4R::Tag)</a><br />
53
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000026">hash (SDL4R::SdlTimeSpan)</a><br />
54
+ <a href="classes/SDL4R/SdlBinary.html#M000080">hash (SDL4R::SdlBinary)</a><br />
55
+ <a href="classes/SDL4R/Tag.html#M000072">hash (SDL4R::Tag)</a><br />
56
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000012">hours (SDL4R::SdlTimeSpan)</a><br />
57
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000015">milliseconds (SDL4R::SdlTimeSpan)</a><br />
58
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000013">minutes (SDL4R::SdlTimeSpan)</a><br />
59
+ <a href="classes/SDL4R/Tag.html#M000062">name= (SDL4R::Tag)</a><br />
60
+ <a href="classes/SDL4R/Tag.html#M000063">namespace= (SDL4R::Tag)</a><br />
61
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000020">negate (SDL4R::SdlTimeSpan)</a><br />
62
+ <a href="classes/SDL4R/Tag.html#M000032">new (SDL4R::Tag)</a><br />
63
+ <a href="classes/SDL4R/SdlParseError.html#M000031">new (SDL4R::SdlParseError)</a><br />
64
+ <a href="classes/SDL4R/Parser.html#M000074">new (SDL4R::Parser)</a><br />
65
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000009">new (SDL4R::SdlTimeSpan)</a><br />
66
+ <a href="classes/SDL4R/SdlBinary.html#M000077">new (SDL4R::SdlBinary)</a><br />
67
+ <a href="classes/SDL4R/Tag.html#M000033">new_child (SDL4R::Tag)</a><br />
68
+ <a href="classes/SDL4R/Parser.html#M000076">new_date_time (SDL4R::Parser)</a><br />
69
+ <a href="classes/SDL4R/Parser.html#M000075">parse (SDL4R::Parser)</a><br />
70
+ <a href="classes/SDL4R.html#M000004">read (SDL4R)</a><br />
71
+ <a href="classes/SDL4R/Tag.html#M000064">read (SDL4R::Tag)</a><br />
72
+ <a href="classes/SDL4R/Tag.html#M000065">read_from_io (SDL4R::Tag)</a><br />
73
+ <a href="classes/SDL4R/Tag.html#M000058">remove_attribute (SDL4R::Tag)</a><br />
74
+ <a href="classes/SDL4R/Tag.html#M000036">remove_child (SDL4R::Tag)</a><br />
75
+ <a href="classes/SDL4R/Tag.html#M000050">remove_value (SDL4R::Tag)</a><br />
76
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000021">roll_days (SDL4R::SdlTimeSpan)</a><br />
77
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000022">roll_hours (SDL4R::SdlTimeSpan)</a><br />
78
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000025">roll_milliseconds (SDL4R::SdlTimeSpan)</a><br />
79
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000023">roll_minutes (SDL4R::SdlTimeSpan)</a><br />
80
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000024">roll_seconds (SDL4R::SdlTimeSpan)</a><br />
81
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000014">seconds (SDL4R::SdlTimeSpan)</a><br />
82
+ <a href="classes/SDL4R/Tag.html#M000054">set_attribute (SDL4R::Tag)</a><br />
83
+ <a href="classes/SDL4R/Tag.html#M000060">set_attributes (SDL4R::Tag)</a><br />
84
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000010">sign (SDL4R::SdlTimeSpan)</a><br />
117
85
  <a href="classes/SDL4R.html#M000007">to_attribute_map (SDL4R)</a><br />
118
- <a href="classes/SDL4R/Tag.html#M000059">to_child_hash (SDL4R::Tag)</a><br />
119
- <a href="classes/SDL4R/Tag.html#M000060">to_child_string_hash (SDL4R::Tag)</a><br />
120
- <a href="classes/SDL4R/Parser/Token.html#M000024">to_s (SDL4R::Parser::Token)</a><br />
121
- <a href="classes/SDL4R/Tag.html#M000080">to_s (SDL4R::Tag)</a><br />
122
- <a href="classes/SDL4R/SdlBinary.html#M000091">to_s (SDL4R::SdlBinary)</a><br />
123
- <a href="classes/SDL4R/SdlTimeSpan.html#M000115">to_s (SDL4R::SdlTimeSpan)</a><br />
124
- <a href="classes/SDL4R/Tag.html#M000081">to_string (SDL4R::Tag)</a><br />
86
+ <a href="classes/SDL4R/Tag.html#M000046">to_child_hash (SDL4R::Tag)</a><br />
87
+ <a href="classes/SDL4R/Tag.html#M000047">to_child_string_hash (SDL4R::Tag)</a><br />
88
+ <a href="classes/SDL4R/Tag.html#M000067">to_s (SDL4R::Tag)</a><br />
89
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000030">to_s (SDL4R::SdlTimeSpan)</a><br />
90
+ <a href="classes/SDL4R/SdlBinary.html#M000081">to_s (SDL4R::SdlBinary)</a><br />
91
+ <a href="classes/SDL4R/Tag.html#M000068">to_string (SDL4R::Tag)</a><br />
125
92
  <a href="classes/SDL4R.html#M000005">to_value (SDL4R)</a><br />
126
93
  <a href="classes/SDL4R.html#M000006">to_value_array (SDL4R)</a><br />
127
- <a href="classes/SDL4R/Tag.html#M000086">to_xml_string (SDL4R::Tag)</a><br />
128
- <a href="classes/SDL4R/SdlTimeSpan.html#M000101">total_hours (SDL4R::SdlTimeSpan)</a><br />
129
- <a href="classes/SDL4R/SdlTimeSpan.html#M000104">total_milliseconds (SDL4R::SdlTimeSpan)</a><br />
130
- <a href="classes/SDL4R/SdlTimeSpan.html#M000102">total_minutes (SDL4R::SdlTimeSpan)</a><br />
131
- <a href="classes/SDL4R/SdlTimeSpan.html#M000103">total_seconds (SDL4R::SdlTimeSpan)</a><br />
132
- <a href="classes/SDL4R.html#M000004">validate_identifier (SDL4R)</a><br />
133
- <a href="classes/SDL4R/Tag.html#M000052">value (SDL4R::Tag)</a><br />
134
- <a href="classes/SDL4R/Tag.html#M000051">value= (SDL4R::Tag)</a><br />
135
- <a href="classes/SDL4R/Tag.html#M000065">values (SDL4R::Tag)</a><br />
136
- <a href="classes/SDL4R/Tag.html#M000066">values= (SDL4R::Tag)</a><br />
137
- <a href="classes/SDL4R/Tag.html#M000079">write (SDL4R::Tag)</a><br />
94
+ <a href="classes/SDL4R/Tag.html#M000073">to_xml_string (SDL4R::Tag)</a><br />
95
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000016">total_hours (SDL4R::SdlTimeSpan)</a><br />
96
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000019">total_milliseconds (SDL4R::SdlTimeSpan)</a><br />
97
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000017">total_minutes (SDL4R::SdlTimeSpan)</a><br />
98
+ <a href="classes/SDL4R/SdlTimeSpan.html#M000018">total_seconds (SDL4R::SdlTimeSpan)</a><br />
99
+ <a href="classes/SDL4R.html#M000003">validate_identifier (SDL4R)</a><br />
100
+ <a href="classes/SDL4R/Tag.html#M000039">value (SDL4R::Tag)</a><br />
101
+ <a href="classes/SDL4R/Tag.html#M000038">value= (SDL4R::Tag)</a><br />
102
+ <a href="classes/SDL4R/Tag.html#M000052">values (SDL4R::Tag)</a><br />
103
+ <a href="classes/SDL4R/Tag.html#M000053">values= (SDL4R::Tag)</a><br />
104
+ <a href="classes/SDL4R/Tag.html#M000066">write (SDL4R::Tag)</a><br />
138
105
  </div>
139
106
  </div>
140
107
  </body>
data/lib/sdl4r/parser.rb CHANGED
@@ -1,8 +1,9 @@
1
+ #--
1
2
  # Simple Declarative Language (SDL) for Ruby
2
3
  # Copyright 2005 Ikayzo, inc.
3
4
  #
4
- # This program is free software. You can distribute or modify it under the
5
- # terms of the GNU Lesser General Public License version 2.1 as published by
5
+ # This program is free software. You can distribute or modify it under the
6
+ # terms of the GNU Lesser General Public License version 2.1 as published by
6
7
  # the Free Software Foundation.
7
8
  #
8
9
  # This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
@@ -12,6 +13,7 @@
12
13
  # You should have received a copy of the GNU Lesser General Public License
13
14
  # along with this program; if not, contact the Free Software Foundation, Inc.,
14
15
  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
+ #++
15
17
 
16
18
 
17
19
  module SDL4R
@@ -32,8 +34,6 @@ module SDL4R
32
34
 
33
35
  # The SDL parser.
34
36
  #
35
- # Authors: Daniel Leuck, Philippe Vosges
36
- #
37
37
  # In Ruby 1.8, in order to enable UTF-8 support, you may have to declare the following lines:
38
38
  #
39
39
  # $KCODE = 'u'
@@ -44,6 +44,9 @@ module SDL4R
44
44
  #
45
45
  # /path/to/ruby -Ku -rjcode
46
46
  #
47
+ # == Authors
48
+ # Daniel Leuck, Philippe Vosges
49
+ #
47
50
  class Parser
48
51
 
49
52
  # Passed to parse_error() in order to specify an error that occured on no specific position
@@ -51,6 +54,12 @@ module SDL4R
51
54
  UNKNOWN_POSITION = -2
52
55
 
53
56
  # Creates an SDL parser on the specified +IO+.
57
+ #
58
+ # IO.open("path/to/sdl_file") { |io|
59
+ # parser = SDL4R::Parser.new(io)
60
+ # tags = parser.parse()
61
+ # }
62
+ #
54
63
  def initialize(io)
55
64
  raise ArgumentError, "io == nil" if io.nil?
56
65
 
@@ -89,6 +98,17 @@ module SDL4R
89
98
 
90
99
  return tags
91
100
  end
101
+
102
+ # Creates and returns the object representing a datetime (DateTime in the default
103
+ # implementation). Can be overriden.
104
+ #
105
+ # def new_date_time(year, month, day, hour, min, sec, time_zone_offset)
106
+ # Time.utc(year, month, day, hour, min, sec)
107
+ # end
108
+ #
109
+ def new_date_time(year, month, day, hour, min, sec, time_zone_offset)
110
+ DateTime.civil(year, month, day, hour, min, sec, time_zone_offset)
111
+ end
92
112
 
93
113
  private
94
114
 
@@ -151,7 +171,7 @@ module SDL4R
151
171
  end
152
172
 
153
173
  third_token = tokens[2];
154
- tag = Tag.new(third_token.text, first_token.text)
174
+ tag = Tag.new(first_token.text, third_token.text)
155
175
  values_start_index = 3
156
176
 
157
177
  else
@@ -312,8 +332,7 @@ module SDL4R
312
332
  token.line,
313
333
  token.position)
314
334
  else
315
- tag.set_attribute(
316
- name, combine(date, time_span_with_zone), name_or_namespace)
335
+ tag.set_attribute(name_or_namespace, name, combine(date, time_span_with_zone))
317
336
  end
318
337
 
319
338
  i += 1
@@ -336,9 +355,9 @@ module SDL4R
336
355
  time_span_with_zone.min,
337
356
  time_span_with_zone.sec)
338
357
 
339
- tag.set_attribute(name, time_span, name_or_namespace)
358
+ tag.set_attribute(name_or_namespace, name, time_span)
340
359
  else
341
- tag.set_attribute(name, value, name_or_namespace);
360
+ tag.set_attribute(name_or_namespace, name, value);
342
361
  end
343
362
  end
344
363
  elsif token.type == :EQUALS
@@ -363,8 +382,7 @@ module SDL4R
363
382
  token.line,
364
383
  token.position)
365
384
  end
366
- tag.set_attribute(
367
- name_or_namespace, combine(date, time_span_with_zone))
385
+ tag.set_attribute(name_or_namespace, combine(date, time_span_with_zone))
368
386
 
369
387
  i += 1
370
388
  else
@@ -404,7 +422,7 @@ module SDL4R
404
422
  time_zone_offset = time_span_with_zone.time_zone_offset
405
423
  time_zone_offset = TimeSpanWithZone.default_time_zone_offset if time_zone_offset.nil?
406
424
 
407
- return DateTime.new(
425
+ new_date_time(
408
426
  date.year,
409
427
  date.month,
410
428
  date.day,
@@ -559,14 +577,8 @@ module SDL4R
559
577
  days, hours, minutes, seconds, time_zone_offset =
560
578
  parse_time_span_and_time_zone(time_part, false, true)
561
579
 
562
- return DateTime.civil(
563
- date.year,
564
- date.month,
565
- date.day,
566
- hours,
567
- minutes,
568
- seconds,
569
- time_zone_offset)
580
+ return new_date_time(
581
+ date.year, date.month, date.day, hours, minutes, seconds, time_zone_offset)
570
582
  end
571
583
 
572
584
  rescue ArgumentError