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/CHANGELOG +0 -0
- data/LICENSE +502 -0
- data/README +296 -1
- data/Rakefile +7 -4
- data/TODO.txt +33 -21
- data/doc/created.rid +1 -0
- data/doc/fr_class_index.html +36 -0
- data/doc/fr_file_index.html +39 -0
- data/doc/fr_method_index.html +141 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/sdl4r/parser.rb +1 -30
- data/lib/sdl4r/parser/reader.rb +175 -0
- data/lib/sdl4r/parser/time_span_with_zone.rb +52 -0
- data/lib/sdl4r/parser/token.rb +133 -0
- data/lib/sdl4r/parser/tokenizer.rb +506 -0
- data/lib/sdl4r/sdl.rb +126 -76
- data/lib/sdl4r/tag.rb +108 -54
- data/test/sdl4r/parser_test.rb +90 -19
- data/test/sdl4r/test.rb +93 -101
- data/test/sdl4r/test_basic_types.sdl +3 -3
- metadata +49 -37
- data/lib/scratchpad.rb +0 -49
- data/lib/sdl4r/reader.rb +0 -171
- data/lib/sdl4r/token.rb +0 -129
- data/lib/sdl4r/tokenizer.rb +0 -501
@@ -29,9 +29,9 @@ string10 "escapes \"\\\n\t"
|
|
29
29
|
# (http://home.att.net/~jameskass/code2000_page.htm), or MS Arial
|
30
30
|
# Unicode (http://support.microsoft.com/default.aspx?scid=kb;en-us;287247) and
|
31
31
|
# ensure your text editor supports UTF8 encoding
|
32
|
-
japanese "日本語"
|
33
|
-
korean "여보세요"
|
34
|
-
russian "здравствулте"
|
32
|
+
japanese.hello "日本語"
|
33
|
+
korean.hello "여보세요"
|
34
|
+
russian.hello "здравствулте"
|
35
35
|
xml `
|
36
36
|
<root type="widget">
|
37
37
|
<color red="255" green="0" blue="0"/>
|
metadata
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdl4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 63
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
version: 0.9.
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 2
|
10
|
+
version: 0.9.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
|
-
|
13
|
+
- Philippe Vosges
|
14
|
+
- Daniel Leuck
|
13
15
|
autorequire:
|
14
16
|
bindir: bin
|
15
17
|
cert_chain: []
|
16
18
|
|
17
|
-
date: 2010-07-
|
19
|
+
date: 2010-07-31 00:00:00 +09:00
|
18
20
|
default_executable:
|
19
21
|
dependencies: []
|
20
22
|
|
@@ -27,23 +29,31 @@ extensions: []
|
|
27
29
|
extra_rdoc_files: []
|
28
30
|
|
29
31
|
files:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
32
|
+
- lib/sdl4r/sdl_time_span.rb
|
33
|
+
- lib/sdl4r/sdl.rb
|
34
|
+
- lib/sdl4r/sdl_parse_error.rb
|
35
|
+
- lib/sdl4r/tag.rb
|
36
|
+
- lib/sdl4r/parser.rb
|
37
|
+
- lib/sdl4r/sdl_binary.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
|
+
- TODO.txt
|
44
|
+
- Rakefile
|
45
|
+
- LICENSE
|
46
|
+
- CHANGELOG
|
47
|
+
- test/sdl4r/test_structures.sdl
|
48
|
+
- test/sdl4r/parser_test.rb
|
49
|
+
- test/sdl4r/test.rb
|
50
|
+
- test/sdl4r/test_basic_types.sdl
|
51
|
+
- doc/rdoc-style.css
|
52
|
+
- doc/fr_file_index.html
|
53
|
+
- doc/fr_class_index.html
|
54
|
+
- doc/fr_method_index.html
|
55
|
+
- doc/index.html
|
56
|
+
- doc/created.rid
|
47
57
|
has_rdoc: true
|
48
58
|
homepage: http://www.ikayzo.org/confluence/display/SDL/Home
|
49
59
|
licenses: []
|
@@ -52,30 +62,32 @@ post_install_message:
|
|
52
62
|
rdoc_options: []
|
53
63
|
|
54
64
|
require_paths:
|
55
|
-
|
65
|
+
- lib
|
56
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
57
67
|
none: false
|
58
68
|
requirements:
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
64
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
76
|
none: false
|
66
77
|
requirements:
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
72
84
|
requirements:
|
73
|
-
|
85
|
+
- none
|
74
86
|
rubyforge_project: sdl4r
|
75
87
|
rubygems_version: 1.3.7
|
76
88
|
signing_key:
|
77
89
|
specification_version: 3
|
78
90
|
summary: Simple Declarative Language for Ruby library
|
79
91
|
test_files:
|
80
|
-
|
81
|
-
|
92
|
+
- test/sdl4r/parser_test.rb
|
93
|
+
- test/sdl4r/test.rb
|
data/lib/scratchpad.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
if RUBY_VERSION < '1.9.0'
|
2
|
-
$KCODE = 'u'
|
3
|
-
require 'jcode'
|
4
|
-
end
|
5
|
-
|
6
|
-
#require "rubygems"
|
7
|
-
require "flt"
|
8
|
-
#
|
9
|
-
#puts "DecNum=" + Flt::DecNum("12345678901234567890").to_s
|
10
|
-
#puts "DecNum precision=" + Flt::DecNum.context.precision.to_s
|
11
|
-
|
12
|
-
puts "Flt::DecNum available" if defined? Flt::DecNum
|
13
|
-
|
14
|
-
require 'time'
|
15
|
-
require File.dirname(__FILE__) + '/sdl4r/sdl'
|
16
|
-
require File.dirname(__FILE__) + '/sdl4r/tag'
|
17
|
-
|
18
|
-
#if "+09:00" =~ /(?:-([a-zA-Z]+))|(?:([\+\-]\d+)(?::(\d+))?)/
|
19
|
-
# puts "matches " + $1.to_s + " " + $2.to_s
|
20
|
-
#end
|
21
|
-
|
22
|
-
#if "03:00-UTC-04" =~ /^([+-]?\d+):(\d+)(?::(\d+)(?:\.(\d+))?)?(?:(?:-([a-zA-Z]+))?(?:([\+\-]\d+)(?::(\d+))?)?)?$/i
|
23
|
-
# puts $~
|
24
|
-
#end
|
25
|
-
|
26
|
-
root = SDL4R::Tag.new("root")
|
27
|
-
#open("D:\\dev\\sdl\\sdl4r\\test\\test_structures.sdl") do |io|
|
28
|
-
# root.read(io)
|
29
|
-
#end
|
30
|
-
##root.read(
|
31
|
-
##<<EOF
|
32
|
-
##matrix {
|
33
|
-
# 1 2 3
|
34
|
-
# 4 5 6
|
35
|
-
#}
|
36
|
-
##EOF
|
37
|
-
##)
|
38
|
-
root.read(
|
39
|
-
<<EOF
|
40
|
-
toto titi=null tata=2
|
41
|
-
EOF
|
42
|
-
)
|
43
|
-
#local_offset = DateTime.now.offset
|
44
|
-
#puts "local_offset=#{local_offset * 24}"
|
45
|
-
#puts DateTime.civil(1980,12,5,12,30,0,local_offset)
|
46
|
-
|
47
|
-
root.children { |child| puts child.to_s }
|
48
|
-
|
49
|
-
puts root.to_s
|
data/lib/sdl4r/reader.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
# Simple Declarative Language (SDL) for Ruby
|
2
|
-
# Copyright 2005 Ikayzo, inc.
|
3
|
-
#
|
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
|
6
|
-
# the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
|
9
|
-
# INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
10
|
-
# See the GNU Lesser General Public License for more details.
|
11
|
-
#
|
12
|
-
# You should have received a copy of the GNU Lesser General Public License
|
13
|
-
# along with this program; if not, contact the Free Software Foundation, Inc.,
|
14
|
-
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15
|
-
|
16
|
-
|
17
|
-
module SDL4R
|
18
|
-
|
19
|
-
# Gives access to the characters read to the Parser.
|
20
|
-
# This class was designed to gather the handling of the UTF-8 issues in one place and shield the
|
21
|
-
# Parser class from these problems.
|
22
|
-
class Reader
|
23
|
-
|
24
|
-
RUBY_1_8_OR_LESS = require 'jcode'
|
25
|
-
|
26
|
-
|
27
|
-
# +io+ an open IO from which the characters are read.
|
28
|
-
def initialize(io)
|
29
|
-
raise ArgumentError, "io == nil" if io.nil?
|
30
|
-
|
31
|
-
@io = io
|
32
|
-
@line = nil
|
33
|
-
@line_chars = nil
|
34
|
-
@line_no = 0
|
35
|
-
@pos = 0
|
36
|
-
end
|
37
|
-
|
38
|
-
attr_reader :line_no, :pos, :line;
|
39
|
-
|
40
|
-
def line_length
|
41
|
-
return @line_chars.nil? ? 0 : @line_chars.length
|
42
|
-
end
|
43
|
-
|
44
|
-
# Reads next line in stream skipping comment lines and blank lines.
|
45
|
-
#
|
46
|
-
# Returns the next line or nil at the end of the file.
|
47
|
-
def read_line
|
48
|
-
@line_chars = nil
|
49
|
-
|
50
|
-
while @line = read_raw_line()
|
51
|
-
# Skip empty and commented lines
|
52
|
-
break unless @line.empty? or @line =~ /^#/
|
53
|
-
end
|
54
|
-
|
55
|
-
return @line
|
56
|
-
end
|
57
|
-
|
58
|
-
# Returns the string that goes from the current position of this Reader to the end of the line
|
59
|
-
# or nil if the current position doesn't allow that.
|
60
|
-
def rest_of_line
|
61
|
-
return @line[@pos..-1]
|
62
|
-
end
|
63
|
-
|
64
|
-
# Indicates whether the end of file has been reached.
|
65
|
-
def end_of_file?
|
66
|
-
return @line.nil?
|
67
|
-
end
|
68
|
-
|
69
|
-
# Indicates whether there are more characters in the current line
|
70
|
-
def more_chars_in_line?
|
71
|
-
return @pos < line_length - 1
|
72
|
-
end
|
73
|
-
|
74
|
-
# Returns whether the end of the current +line+ as been reached.
|
75
|
-
def end_of_line?
|
76
|
-
return @pos >= line_length
|
77
|
-
end
|
78
|
-
|
79
|
-
# Skips the current line by going just after its end.
|
80
|
-
def skip_line
|
81
|
-
@pos = line_length
|
82
|
-
end
|
83
|
-
|
84
|
-
# Skips the whitespaces that follow the current position.
|
85
|
-
def skip_whitespaces
|
86
|
-
while (@pos + 1) < line_length and
|
87
|
-
(@line[@pos + 1] == ?\s or @line[@pos + 1] == ?\t)
|
88
|
-
@pos += 1
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Returns the character at position +pos+ in the current line.
|
93
|
-
# Returns nil if there is no current line or if +pos+ is after the end of the line.
|
94
|
-
def get_line_char(pos)
|
95
|
-
if @line_chars and pos < line_length
|
96
|
-
return @line_chars[pos]
|
97
|
-
else
|
98
|
-
return nil
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# Returns the character at the current position or nil after end-of-line or end-of -file.
|
103
|
-
def current_char
|
104
|
-
return get_line_char(@pos)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Go to the next character in the stream.
|
108
|
-
def skip_char
|
109
|
-
@pos += 1 if @pos < line_length
|
110
|
-
end
|
111
|
-
|
112
|
-
# Go to the next character and returns it (or nil if end-of-line or -file has been reached).
|
113
|
-
def read_char
|
114
|
-
skip_char()
|
115
|
-
return current_char
|
116
|
-
end
|
117
|
-
|
118
|
-
# Returns to the previous char if possible.
|
119
|
-
def previous_char
|
120
|
-
@pos -= 1 if @pos >= -1
|
121
|
-
end
|
122
|
-
|
123
|
-
# Returns the next index of the expression (string, regexp, fixnum) in the current line, starting
|
124
|
-
# from after the current position if no position is specified.
|
125
|
-
def find_next_in_line(searched, start_pos = nil)
|
126
|
-
start_pos = @pos + 1 unless start_pos
|
127
|
-
return @line.index(searched, start_pos)
|
128
|
-
end
|
129
|
-
|
130
|
-
# Skips the specified position in the current line.
|
131
|
-
def skip_to(new_pos)
|
132
|
-
@pos = new_pos
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
|
-
# Returns a subpart of the current line starting from +from+ and stopping at +to+ (excluded).
|
137
|
-
def substring(from, to = -1)
|
138
|
-
return @line[from..to]
|
139
|
-
end
|
140
|
-
|
141
|
-
# Reads and returns a "raw" line including lines with comments and blank lines.
|
142
|
-
#
|
143
|
-
# Returns the next line or nil if at the end of the file.
|
144
|
-
#
|
145
|
-
# This method changes the value of @line, @lineNo and @pos.
|
146
|
-
def read_raw_line
|
147
|
-
@line = @io.gets()
|
148
|
-
|
149
|
-
# We ensure that only \n is used as an end-of-line by replacing \r and \r\n.
|
150
|
-
if @line
|
151
|
-
if not @line.gsub!(/\r\n/m, "\n")
|
152
|
-
@line.gsub!(/\r/m, "\n")
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
@pos = 0;
|
157
|
-
@line_chars = nil
|
158
|
-
if @line
|
159
|
-
@line_no += 1
|
160
|
-
@line_chars = @line.scan(/./m)
|
161
|
-
end
|
162
|
-
return @line
|
163
|
-
end
|
164
|
-
|
165
|
-
# Closes this Reader and its underlying +IO+.
|
166
|
-
def close
|
167
|
-
@io.close
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
data/lib/sdl4r/token.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
# Simple Declarative Language (SDL) for Ruby
|
2
|
-
# Copyright 2005 Ikayzo, inc.
|
3
|
-
#
|
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
|
6
|
-
# the Free Software Foundation.
|
7
|
-
#
|
8
|
-
# This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
|
9
|
-
# INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
10
|
-
# See the GNU Lesser General Public License for more details.
|
11
|
-
#
|
12
|
-
# You should have received a copy of the GNU Lesser General Public License
|
13
|
-
# along with this program; if not, contact the Free Software Foundation, Inc.,
|
14
|
-
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15
|
-
|
16
|
-
|
17
|
-
module SDL4R
|
18
|
-
|
19
|
-
require File.dirname(__FILE__) + '/parser'
|
20
|
-
|
21
|
-
# An SDL token.
|
22
|
-
#
|
23
|
-
# @author Daniel Leuck, Philippe Vosges
|
24
|
-
#
|
25
|
-
class Token
|
26
|
-
|
27
|
-
def initialize(text, line = -1, position = -1)
|
28
|
-
@text = text
|
29
|
-
@line = line
|
30
|
-
@pos = position
|
31
|
-
@size = text.length
|
32
|
-
|
33
|
-
begin
|
34
|
-
@type = nil
|
35
|
-
@object = nil
|
36
|
-
|
37
|
-
if text =~ /^["`]/
|
38
|
-
@type = :STRING
|
39
|
-
@object = Parser.parse_string(text)
|
40
|
-
|
41
|
-
elsif text =~ /^'/
|
42
|
-
@type = :CHARACTER
|
43
|
-
@object = text[1...-1]
|
44
|
-
|
45
|
-
elsif text == "null"
|
46
|
-
@type = :NULL
|
47
|
-
@object = nil
|
48
|
-
|
49
|
-
elsif text =~ /^true$|^on$/
|
50
|
-
@type = :BOOLEAN
|
51
|
-
@object = true
|
52
|
-
|
53
|
-
elsif text =~ /^false$|^off$/
|
54
|
-
@type = :BOOLEAN
|
55
|
-
@object = false
|
56
|
-
|
57
|
-
elsif text =~ /^\[/
|
58
|
-
@type=:BINARY
|
59
|
-
@object = Parser.parse_binary(text)
|
60
|
-
|
61
|
-
elsif text =~ /^\d+\/\d+\/\d+$/
|
62
|
-
@type = :DATE;
|
63
|
-
@object = Parser.parse_date_time(text)
|
64
|
-
|
65
|
-
elsif text =~ /^-?\d+d?:\d+/
|
66
|
-
@type = :TIME
|
67
|
-
@object = parse_time_span_with_zone(text)
|
68
|
-
|
69
|
-
elsif text =~ /^[\d\-\.]/
|
70
|
-
@type = :NUMBER
|
71
|
-
@object = Parser.parse_number(text)
|
72
|
-
|
73
|
-
else
|
74
|
-
case text[0]
|
75
|
-
when ?{
|
76
|
-
@type = :START_BLOCK
|
77
|
-
when ?}
|
78
|
-
@type = :END_BLOCK
|
79
|
-
when ?=
|
80
|
-
@type = :EQUALS
|
81
|
-
when ?:
|
82
|
-
@type = :COLON
|
83
|
-
when ?;
|
84
|
-
@type = :SEMICOLON
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
rescue ArgumentError
|
89
|
-
raise SdlParseError.new($!.message, @line, @pos)
|
90
|
-
end
|
91
|
-
|
92
|
-
@type = :IDENTIFIER if @type.nil? # if all hope is lost, it's an identifier
|
93
|
-
|
94
|
-
@punctuation =
|
95
|
-
@type == :COLON || @type == :SEMICOLON || @type == :EQUALS ||
|
96
|
-
@type == :START_BLOCK || @type == :END_BLOCK
|
97
|
-
@literal = @type != :IDENTIFIER && !@punctuation
|
98
|
-
end
|
99
|
-
|
100
|
-
attr_reader :text, :type, :line, :position
|
101
|
-
|
102
|
-
def literal?
|
103
|
-
@literal
|
104
|
-
end
|
105
|
-
|
106
|
-
# Returns the Ruby object corresponding to this literal (or nil if it is
|
107
|
-
# not a literal).
|
108
|
-
def object_for_literal
|
109
|
-
return @object
|
110
|
-
end
|
111
|
-
|
112
|
-
def to_s
|
113
|
-
@type.to_s + " " + @text + " pos:" + @pos.to_s
|
114
|
-
end
|
115
|
-
|
116
|
-
# This special parse method is used only by the Token class for
|
117
|
-
# tokens which are ambiguously either a TimeSpan or the time component
|
118
|
-
# of a date/time type
|
119
|
-
def parse_time_span_with_zone(literal)
|
120
|
-
raise ArgumentError("time span or date literal is nil") if literal.nil?
|
121
|
-
|
122
|
-
days, hours, minutes, seconds, time_zone_offset =
|
123
|
-
Parser.parse_time_span_and_time_zone(literal, true, true)
|
124
|
-
|
125
|
-
return Parser::TimeSpanWithZone.new(days, hours, minutes, seconds, time_zone_offset)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|