sdl4r 0.9.7 → 0.9.8

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.
@@ -139,7 +139,7 @@ module SDL4R
139
139
 
140
140
  first_token = tokens.first
141
141
  if first_token.literal?
142
- first_token = Token.new("content")
142
+ first_token = Token.new(ANONYMOUS_TAG_NAME)
143
143
  tokens.insert(0, first_token)
144
144
 
145
145
  elsif first_token.type != :IDENTIFIER
@@ -186,8 +186,7 @@ module SDL4R
186
186
  return tag
187
187
  end
188
188
 
189
- #
190
- # @return The position at the end of the value list
189
+ # Return the position at the end of the value list
191
190
  #
192
191
  def add_tag_values(tag, tokens, start)
193
192
  size = tokens.size()
@@ -648,5 +647,10 @@ module SDL4R
648
647
  def expecting_but_got(expecting, got, line, position)
649
648
  @tokenizer.expecting_but_got(expecting, got, line, position)
650
649
  end
650
+
651
+ # Raises a SdlParseError.
652
+ def parse_error(description, line_no, position)
653
+ @tokenizer.parse_error(description, line_no, position)
654
+ end
651
655
  end
652
656
  end
@@ -58,7 +58,8 @@ module SDL4R
58
58
  # Raises a SdlParseError.
59
59
  def parse_error(description, line_no = nil, position = nil)
60
60
  line_no = @reader.line_no unless line_no
61
- position = @reader.pos - 1 unless position # @reader.pos points to the *next* position
61
+ # @reader.pos points to the *next* position (thence the "pos - 1")
62
+ position = @reader.pos - 1 unless position and position >= 0
62
63
 
63
64
  # We add one because editors typically start with line 1 rather than 0...
64
65
  raise SdlParseError.new(description, line_no + 1, position + 1, @reader.line)
@@ -34,6 +34,9 @@ module SDL4R
34
34
 
35
35
  BASE64_WRAP_LINE_LENGTH = 72
36
36
 
37
+ ANONYMOUS_TAG_NAME = "content"
38
+ ROOT_TAG_NAME = "root"
39
+
37
40
  # Creates an SDL string representation for a given object and returns it.
38
41
  #
39
42
  # +o+:: the object to format
@@ -105,16 +108,18 @@ module SDL4R
105
108
  milliseconds = get_datetime_milliseconds(o)
106
109
 
107
110
  if milliseconds == 0
108
- if o.zone
109
- return o.strftime("#{o.year}/%m/%d %H:%M:%S%Z")
111
+ zone_part = o.strftime("%:z")
112
+ if zone_part and zone_part != "+00:00"
113
+ return o.strftime("#{o.year}/%m/%d %H:%M:%S#{zone_part}")
110
114
  else
111
115
  return o.strftime("#{o.year}/%m/%d %H:%M:%S")
112
116
  end
113
117
  else
114
- if o.zone
115
- return o.strftime("#{o.year}/%m/%d %H:%M:%S." + milliseconds.to_s.ljust(3, '0') + "%Z")
118
+ ms_part = milliseconds.to_s.ljust(3, '0')
119
+ if zone_part and zone_part != "+00:00"
120
+ return o.strftime("#{o.year}/%m/%d %H:%M:%S." + ms_part + zone_part)
116
121
  else
117
- return o.strftime("#{o.year}/%m/%d %H:%M:%S." + milliseconds.to_s.ljust(3, '0'))
122
+ return o.strftime("#{o.year}/%m/%d %H:%M:%S." + ms_part)
118
123
  end
119
124
  end
120
125
 
@@ -174,7 +179,7 @@ module SDL4R
174
179
 
175
180
  # Validates an SDL identifier String. SDL Identifiers must start with a
176
181
  # Unicode letter or underscore (_) and contain only unicode letters,
177
- # digits, underscores (_), dashes(-) and periods (.).
182
+ # digits, underscores (_), dashes(-), periods (.) and dollar signs ($).
178
183
  #
179
184
  # == Raises
180
185
  # ArgumentError if the identifier is not legal
@@ -195,15 +200,15 @@ module SDL4R
195
200
  "an underscore (_)."
196
201
  end
197
202
 
198
- unless identifier.length == 1 or identifier =~ /^[a-zA-Z_][a-zA-Z_0-9\-\.]*$/
203
+ unless identifier.length == 1 or identifier =~ /^[a-zA-Z_][a-zA-Z_0-9\-\.\$]*$/
199
204
  for i in 1..identifier.length
200
- unless identifier[i..i] =~ /^[a-zA-Z_0-9\-]$/
205
+ unless identifier[i..i] =~ /^[a-zA-Z_0-9\-\.\$]$/
201
206
  raise ArgumentError,
202
207
  "'" + identifier[i..i] +
203
208
  "' is not a legal character for an SDL identifier. " +
204
209
  "SDL Identifiers must start with a unicode letter or " +
205
210
  "underscore (_) followed by 0 or more unicode " +
206
- "letters, digits, underscores (_), or dashes (-)"
211
+ "letters, digits, underscores (_), dashes (-), periodss (.) and dollar signs ($)"
207
212
  end
208
213
  end
209
214
  end
@@ -230,7 +235,7 @@ module SDL4R
230
235
  # root = SDL4R::read(URI.new("http://my_site/my_file.sdl"))
231
236
  #
232
237
  def self.read(input)
233
- Tag.new("root").read(input)
238
+ Tag.new(ROOT_TAG_NAME).read(input)
234
239
  end
235
240
 
236
241
  # Parses and returns the value corresponding with the specified SDL literal.
@@ -37,7 +37,7 @@ module SDL4R
37
37
  super(
38
38
  "#{description} Line " + ((line_no.nil? or line_no < 0)? "unknown" : line_no.to_s) +
39
39
  ", Position " + ((position.nil? or position < 0)? "unknown" : position.to_s) + $/ +
40
- (line ? line + (position ? " " * (position - 1) : "") + "^" : ""))
40
+ ((line and position >= 0)? line + (position ? " " * (position - 1) : "") + "^" : ""))
41
41
 
42
42
  @line = line_no
43
43
  @position = position
@@ -209,7 +209,7 @@ module SDL4R
209
209
  elsif o.is_a? Enumerable
210
210
  o.each { |item|
211
211
  if item.is_a? Enumerable and not item.is_a? String
212
- anonymous = new_child("content")
212
+ anonymous = new_child(ANONYMOUS_TAG_NAME)
213
213
  anonymous << item
214
214
  else
215
215
  self << item
@@ -772,8 +772,11 @@ module SDL4R
772
772
  else
773
773
  first = true
774
774
  children do |child|
775
- io << $/ unless first
776
- first = false
775
+ if first
776
+ first = false
777
+ else
778
+ io << $/
779
+ end
777
780
  io << child.to_s
778
781
  end
779
782
  end
@@ -803,7 +806,7 @@ module SDL4R
803
806
  s = ""
804
807
  s << line_prefix
805
808
 
806
- if name == "content" && namespace.empty?
809
+ if name == ANONYMOUS_TAG_NAME && namespace.empty?
807
810
  skip_value_space = true
808
811
  else
809
812
  skip_value_space = false
@@ -18,13 +18,15 @@
18
18
  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
19
  #++
20
20
 
21
+ # Work-around a bug in NetBeans (http://netbeans.org/bugzilla/show_bug.cgi?id=188653)
22
+ # $:[0] = File.join(File.dirname(__FILE__),'../../lib') if ENV["NB_EXEC_EXTEXECUTION_PROCESS_UUID"]
21
23
 
22
24
  module SDL4R
23
-
25
+
24
26
  require 'bigdecimal'
25
27
  require 'test/unit'
26
-
27
- require File.dirname(__FILE__) + '/../../lib/sdl4r/tag'
28
+
29
+ require "sdl4r/tag"
28
30
 
29
31
  class ParserTest < Test::Unit::TestCase
30
32
 
@@ -195,6 +197,10 @@ EOS
195
197
  local_civil_date(1807, 11, 11, 22, 28, Rational(13888, 1000), Rational(-85, 240)),
196
198
  tag1.attribute("date6"),
197
199
  "date6");
200
+
201
+ tag1 = parse_one_tag1("tag1 2008/06/01 5d:12:34") # not a datetime: a date + a timespan
202
+ assert_equal Date.civil(2008, 6, 1), tag1.values[0]
203
+ assert_equal SdlTimeSpan.new(5, 12, 34), tag1.values[1]
198
204
  end
199
205
 
200
206
  def test_numbers
@@ -380,6 +386,40 @@ EOS
380
386
  assert_equal expected, root
381
387
  end
382
388
 
389
+ def test_identifiers
390
+ root = SDL4R::read("my_ns:my_tag my_ns2:my_attr=-13.8")
391
+ assert_equal "my_ns", root.child.namespace
392
+ assert_equal "my_tag", root.child.name
393
+ assert_equal({ "my_ns2:my_attr" => -13.8 }, root.child.attributes)
394
+
395
+ root = SDL4R::read("_my_ns:_my_tag _my_ns2:_my_attr=-13.8")
396
+ assert_equal "_my_ns", root.child.namespace
397
+ assert_equal "_my_tag", root.child.name
398
+ assert_equal({ "_my_ns2:_my_attr" => -13.8 }, root.child.attributes)
399
+
400
+ root = SDL4R::read("my.ns:my.tag my.ns2:my.attr=-13.8")
401
+ assert_equal "my.ns", root.child.namespace
402
+ assert_equal "my.tag", root.child.name
403
+ assert_equal({ "my.ns2:my.attr" => -13.8 }, root.child.attributes)
404
+
405
+ root = SDL4R::read("my$ns:my$tag my$ns2:my$attr=-13.8")
406
+ assert_equal "my$ns", root.child.namespace
407
+ assert_equal "my$tag", root.child.name
408
+ assert_equal({ "my$ns2:my$attr" => -13.8 }, root.child.attributes)
409
+ end
410
+
411
+ def test_empty_block
412
+ tag1 = parse_one_tag1("tag1 {\n}")
413
+ assert_equal [], tag1.values
414
+ assert_equal({}, tag1.attributes)
415
+ assert_equal [], tag1.children
416
+
417
+ # tag1 = parse_one_tag1("tag1 {}")
418
+ # assert_equal [], tag1.values
419
+ # assert_equal({}, tag1.attributes)
420
+ # assert_equal [], tag1.children
421
+ end
422
+
383
423
  def test_parse_error
384
424
  # WARNING: the line and col of an error is not accurate science. The goal here is to point to
385
425
  # coordinates that are useful to the user.
@@ -32,7 +32,7 @@ module SDL4R
32
32
  require 'date'
33
33
 
34
34
  require 'test/unit'
35
- require File.dirname(__FILE__) + '/../../lib/sdl4r'
35
+ require 'sdl4r'
36
36
 
37
37
  # SDL unit tests.
38
38
  #
@@ -126,17 +126,17 @@ module SDL4R
126
126
  end
127
127
 
128
128
  def test_tag_write_parse_basic_types
129
- test_tag_write_parse @@root_basic_types
129
+ check_tag_write_parse @@root_basic_types
130
130
  end
131
131
 
132
132
  def test_tag_write_parse_structures
133
- test_tag_write_parse @@root_structures
133
+ check_tag_write_parse @@root_structures
134
134
  end
135
135
 
136
136
  #
137
137
  # Does a to_s/parse test on the specified Tag (+root+)
138
138
  #
139
- def test_tag_write_parse(root)
139
+ def check_tag_write_parse(root)
140
140
  # puts '========================================'
141
141
  # puts root.to_s
142
142
  # puts '========================================'
@@ -23,7 +23,7 @@ module SDL4R
23
23
  require 'test/unit'
24
24
  require "rexml/document"
25
25
 
26
- require File.dirname(__FILE__) + '/../../lib/sdl4r/tag'
26
+ require 'sdl4r/tag'
27
27
 
28
28
  class SDLTest < Test::Unit::TestCase
29
29
 
@@ -23,7 +23,7 @@ module SDL4R
23
23
  require 'test/unit'
24
24
  require "rexml/document"
25
25
 
26
- require File.dirname(__FILE__) + '/../../lib/sdl4r/tag'
26
+ require 'sdl4r/tag'
27
27
 
28
28
 
29
29
  class TagTest < Test::Unit::TestCase
@@ -566,6 +566,7 @@ EOF
566
566
 
567
567
  def test_write
568
568
  root = Tag.new("root")
569
+ root << 999
569
570
 
570
571
  output = ""
571
572
  root.write(output)
@@ -573,7 +574,7 @@ EOF
573
574
 
574
575
  output = ""
575
576
  root.write(output, true)
576
- assert_equal "root", output
577
+ assert_equal "root 999", output
577
578
 
578
579
  child1 = root.new_child "child1"
579
580
  child1 << 123
@@ -585,7 +586,7 @@ EOF
585
586
  output = ""
586
587
  root.write(output, true)
587
588
  assert_equal(
588
- "root {\n" +
589
+ "root 999 {\n" +
589
590
  "\tchild1 123\n" +
590
591
  "}",
591
592
  output)
@@ -600,11 +601,25 @@ EOF
600
601
  output = ""
601
602
  root.write(output, true)
602
603
  assert_equal(
603
- "root {\n" +
604
+ "root 999 {\n" +
604
605
  "\tchild1 123\n" +
605
606
  "\tchild2 \"abc\"\n" +
606
607
  "}",
607
608
  output)
609
+
610
+ output = ""
611
+ root.clear_children
612
+ root.clear_values
613
+ root << Date.civil(1876, 7, 1)
614
+ root << DateTime.civil(1592, 9, 13, 9, 5, 0, 0)
615
+ root << DateTime.civil(1592, 9, 13, 9, 5, 7, 0)
616
+ root << DateTime.civil(-98, 6, 15, 13, 47, 1234.to_r/100, 0)
617
+ root << DateTime.civil(3112, 1, 10, 0, 0, 0, 1.to_r/24)
618
+ root.write(output, true)
619
+ assert_equal(
620
+ "root 1876/07/01 1592/09/13 09:05:00 1592/09/13 09:05:07" +
621
+ " -98/06/15 13:47:12.340 3112/01/10 00:00:00+01:00",
622
+ output)
608
623
  end
609
624
 
610
625
  end
metadata CHANGED
@@ -3,19 +3,19 @@ name: sdl4r
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 0
7
- - 9
8
- - 7
9
- version: 0.9.7
6
+ - 0
7
+ - 9
8
+ - 8
9
+ version: 0.9.8
10
10
  platform: ruby
11
11
  authors:
12
- - Philippe Vosges
13
- - Daniel Leuck
12
+ - Philippe Vosges
13
+ - Daniel Leuck
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-26 00:00:00 +09:00
18
+ date: 2010-09-16 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -28,62 +28,62 @@ extensions: []
28
28
  extra_rdoc_files: []
29
29
 
30
30
  files:
31
- - lib/sdl4r.rb
32
- - lib/sdl4r/sdl_time_span.rb
33
- - lib/sdl4r/sdl_parse_error.rb
34
- - lib/sdl4r/tag.rb
35
- - lib/sdl4r/parser.rb
36
- - lib/sdl4r/sdl_binary.rb
37
- - lib/sdl4r/parser/reader.rb
38
- - lib/sdl4r/parser/tokenizer.rb
39
- - lib/sdl4r/parser/token.rb
40
- - lib/sdl4r/parser/time_span_with_zone.rb
41
- - lib/sdl4r/sdl4r.rb
42
- - README
43
- - Rakefile
44
- - LICENSE
45
- - CHANGELOG
46
- - TODO
47
- - test/sdl4r/parser_test.rb
48
- - test/sdl4r/tag_test.rb
49
- - test/sdl4r/sdl_test.rb
50
- - test/sdl4r/test_structures.sdl
51
- - test/sdl4r/test_basic_types.sdl
52
- - test/sdl4r/sdl4r_test.rb
53
- - doc/rdoc-style.css
54
- - doc/files/README.html
55
- - doc/files/LICENSE.html
56
- - doc/files/CHANGELOG.html
57
- - doc/files/lib/sdl4r_rb.html
58
- - doc/files/lib/sdl4r/sdl_parse_error_rb.html
59
- - doc/files/lib/sdl4r/tag_rb.html
60
- - doc/files/lib/sdl4r/sdl_time_span_rb.html
61
- - doc/files/lib/sdl4r/parser_rb.html
62
- - doc/files/lib/sdl4r/sdl4r_rb.html
63
- - doc/files/lib/sdl4r/sdl_binary_rb.html
64
- - doc/files/lib/sdl4r/parser/reader_rb.html
65
- - doc/files/lib/sdl4r/parser/time_span_with_zone_rb.html
66
- - doc/files/lib/sdl4r/parser/tokenizer_rb.html
67
- - doc/files/lib/sdl4r/parser/token_rb.html
68
- - doc/files/test/sdl4r/parser_test_rb.html
69
- - doc/files/test/sdl4r/sdl_test_rb.html
70
- - doc/files/test/sdl4r/tag_test_rb.html
71
- - doc/files/test/sdl4r/sdl4r_test_rb.html
72
- - doc/classes/SDL4R.html
73
- - doc/classes/SDL4R/SdlTimeSpan.html
74
- - doc/classes/SDL4R/SdlParseError.html
75
- - doc/classes/SDL4R/Tag.html
76
- - doc/classes/SDL4R/Parser.html
77
- - doc/classes/SDL4R/SDLTest.html
78
- - doc/classes/SDL4R/TagTest.html
79
- - doc/classes/SDL4R/SdlBinary.html
80
- - doc/classes/SDL4R/ParserTest.html
81
- - doc/classes/SDL4R/SDL4RTest.html
82
- - doc/fr_file_index.html
83
- - doc/fr_class_index.html
84
- - doc/fr_method_index.html
85
- - doc/index.html
86
- - doc/created.rid
31
+ - lib/sdl4r.rb
32
+ - lib/sdl4r/sdl_time_span.rb
33
+ - lib/sdl4r/sdl_parse_error.rb
34
+ - lib/sdl4r/tag.rb
35
+ - lib/sdl4r/parser.rb
36
+ - lib/sdl4r/sdl_binary.rb
37
+ - lib/sdl4r/sdl4r.rb
38
+ - lib/sdl4r/parser/reader.rb
39
+ - lib/sdl4r/parser/tokenizer.rb
40
+ - lib/sdl4r/parser/token.rb
41
+ - lib/sdl4r/parser/time_span_with_zone.rb
42
+ - README
43
+ - Rakefile
44
+ - LICENSE
45
+ - CHANGELOG
46
+ - TODO
47
+ - test/sdl4r/parser_test.rb
48
+ - test/sdl4r/tag_test.rb
49
+ - test/sdl4r/sdl_test.rb
50
+ - test/sdl4r/test_structures.sdl
51
+ - test/sdl4r/test_basic_types.sdl
52
+ - test/sdl4r/sdl4r_test.rb
53
+ - doc/rdoc-style.css
54
+ - doc/fr_file_index.html
55
+ - doc/fr_class_index.html
56
+ - doc/fr_method_index.html
57
+ - doc/index.html
58
+ - doc/created.rid
59
+ - doc/files/README.html
60
+ - doc/files/LICENSE.html
61
+ - doc/files/CHANGELOG.html
62
+ - doc/files/lib/sdl4r_rb.html
63
+ - doc/files/lib/sdl4r/sdl_time_span_rb.html
64
+ - doc/files/lib/sdl4r/tag_rb.html
65
+ - doc/files/lib/sdl4r/sdl_parse_error_rb.html
66
+ - doc/files/lib/sdl4r/parser_rb.html
67
+ - doc/files/lib/sdl4r/sdl4r_rb.html
68
+ - doc/files/lib/sdl4r/sdl_binary_rb.html
69
+ - doc/files/lib/sdl4r/parser/time_span_with_zone_rb.html
70
+ - doc/files/lib/sdl4r/parser/reader_rb.html
71
+ - doc/files/lib/sdl4r/parser/tokenizer_rb.html
72
+ - doc/files/lib/sdl4r/parser/token_rb.html
73
+ - doc/files/test/sdl4r/tag_test_rb.html
74
+ - doc/files/test/sdl4r/sdl_test_rb.html
75
+ - doc/files/test/sdl4r/parser_test_rb.html
76
+ - doc/files/test/sdl4r/sdl4r_test_rb.html
77
+ - doc/classes/SDL4R.html
78
+ - doc/classes/SDL4R/SdlTimeSpan.html
79
+ - doc/classes/SDL4R/SdlParseError.html
80
+ - doc/classes/SDL4R/Tag.html
81
+ - doc/classes/SDL4R/Parser.html
82
+ - doc/classes/SDL4R/SDLTest.html
83
+ - doc/classes/SDL4R/TagTest.html
84
+ - doc/classes/SDL4R/SdlBinary.html
85
+ - doc/classes/SDL4R/ParserTest.html
86
+ - doc/classes/SDL4R/SDL4RTest.html
87
87
  has_rdoc: true
88
88
  homepage: http://www.ikayzo.org/confluence/display/SDL/Home
89
89
  licenses: []
@@ -92,30 +92,30 @@ post_install_message:
92
92
  rdoc_options: []
93
93
 
94
94
  require_paths:
95
- - lib
95
+ - lib
96
96
  required_ruby_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- segments:
101
- - 0
102
- version: "0"
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- segments:
108
- - 0
109
- version: "0"
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ version: "0"
110
110
  requirements:
111
- - none
111
+ - none
112
112
  rubyforge_project: sdl4r
113
113
  rubygems_version: 1.3.6
114
114
  signing_key:
115
115
  specification_version: 3
116
116
  summary: Simple Declarative Language for Ruby library
117
117
  test_files:
118
- - test/sdl4r/parser_test.rb
119
- - test/sdl4r/tag_test.rb
120
- - test/sdl4r/sdl_test.rb
121
- - test/sdl4r/sdl4r_test.rb
118
+ - test/sdl4r/parser_test.rb
119
+ - test/sdl4r/tag_test.rb
120
+ - test/sdl4r/sdl_test.rb
121
+ - test/sdl4r/sdl4r_test.rb