sxp 0.0.2 → 0.0.3
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.
- data/VERSION +1 -1
- data/lib/sxp/reader.rb +29 -15
- data/lib/sxp/version.rb +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/sxp/reader.rb
CHANGED
@@ -18,6 +18,7 @@ module SXP
|
|
18
18
|
# @param [Hash{Symbol => Object}] options
|
19
19
|
# @return [Enumerable<Object>]
|
20
20
|
def self.read_files(*filenames)
|
21
|
+
options = filenames.last.is_a?(Hash) ? filenames.pop : {}
|
21
22
|
filenames.map { |filename| read_file(filename, options) }.inject { |sxps, sxp| sxps + sxp }
|
22
23
|
end
|
23
24
|
|
@@ -73,7 +74,7 @@ module SXP
|
|
73
74
|
INTEGER_BASE_10 = /^[+-]?\d+$/
|
74
75
|
INTEGER_BASE_16 = /^[+-]?[\da-z]+$/i
|
75
76
|
RATIONAL = /^([+-]?\d+)\/(\d+)$/
|
76
|
-
ATOM = /^[^\s()]+/
|
77
|
+
ATOM = /^[^\s()\[\]]+/
|
77
78
|
|
78
79
|
attr_reader :input
|
79
80
|
|
@@ -95,43 +96,48 @@ module SXP
|
|
95
96
|
|
96
97
|
def read_all(options = {})
|
97
98
|
list = []
|
98
|
-
catch (:eof)
|
99
|
+
catch (:eof) do
|
100
|
+
list << read(options.merge(:eof => :throw)) until eof?
|
101
|
+
end
|
99
102
|
list
|
100
103
|
end
|
101
104
|
|
102
105
|
def read(options = {})
|
106
|
+
skip_comments
|
103
107
|
token, value = read_token
|
104
108
|
case token
|
105
109
|
when :eof
|
106
110
|
throw :eof if options[:eof] == :throw
|
107
111
|
raise EOF, 'unexpected end of input'
|
108
112
|
when :list
|
109
|
-
if value == ?(
|
113
|
+
if value == ?( || value == ?[
|
110
114
|
read_list
|
111
115
|
else
|
112
|
-
throw :eol if options[:eol] == :throw
|
113
|
-
raise Error,
|
116
|
+
throw :eol if options[:eol] == :throw # end of list
|
117
|
+
raise Error, "unexpected list terminator: ?#{value.chr}"
|
114
118
|
end
|
115
119
|
else value
|
116
120
|
end
|
117
121
|
end
|
118
122
|
|
119
|
-
|
123
|
+
alias_method :skip, :read
|
120
124
|
|
121
125
|
def read_token
|
122
|
-
skip_comments
|
123
126
|
case peek_char
|
124
|
-
when nil
|
127
|
+
when nil then :eof
|
125
128
|
when ?(, ?) then [:list, read_char]
|
126
|
-
when
|
127
|
-
when ?"
|
129
|
+
when ?[, ?] then [:list, read_char]
|
130
|
+
when ?" then [:atom, read_string]
|
131
|
+
when ?# then [:atom, read_sharp]
|
128
132
|
else [:atom, read_atom]
|
129
133
|
end
|
130
134
|
end
|
131
135
|
|
132
136
|
def read_list
|
133
137
|
list = []
|
134
|
-
catch (:eol)
|
138
|
+
catch (:eol) do
|
139
|
+
list << read(:eol => :throw) while true
|
140
|
+
end
|
135
141
|
list
|
136
142
|
end
|
137
143
|
|
@@ -147,6 +153,7 @@ module SXP
|
|
147
153
|
when ?x then read_integer(16)
|
148
154
|
when ?\\ then read_character
|
149
155
|
when ?; then skip; read
|
156
|
+
when ?! then skip_line # shebang
|
150
157
|
else raise Error, "invalid sharp-sign read syntax: ##{char.chr}"
|
151
158
|
end
|
152
159
|
end
|
@@ -161,9 +168,10 @@ module SXP
|
|
161
168
|
|
162
169
|
def read_atom
|
163
170
|
case buffer = read_literal
|
164
|
-
when
|
171
|
+
when '.' then buffer.to_sym
|
172
|
+
when FLOAT then buffer.to_f
|
165
173
|
when INTEGER_BASE_10 then buffer.to_i
|
166
|
-
when RATIONAL
|
174
|
+
when RATIONAL then Rational($1.to_i, $2.to_i)
|
167
175
|
else buffer.to_sym
|
168
176
|
end
|
169
177
|
end
|
@@ -204,7 +212,7 @@ module SXP
|
|
204
212
|
def skip_comments
|
205
213
|
until eof?
|
206
214
|
case (char = peek_char).chr
|
207
|
-
when /;/
|
215
|
+
when /;/ then skip_line
|
208
216
|
when /\s+/ then skip_char
|
209
217
|
else break
|
210
218
|
end
|
@@ -223,7 +231,13 @@ module SXP
|
|
223
231
|
char
|
224
232
|
end
|
225
233
|
|
226
|
-
|
234
|
+
def skip_line
|
235
|
+
loop do
|
236
|
+
break if eof? || read_char.chr == $/
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
alias_method :skip_char, :read_char
|
227
241
|
|
228
242
|
def peek_char
|
229
243
|
char = @input.getc
|
data/lib/sxp/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arto Bendiken
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-14 00:00:00 +02:00
|
18
18
|
default_executable: sxp2rdf
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|