clj 0.0.5.1 → 0.0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/clj/parser.rb +58 -25
- metadata +35 -60
data/lib/clj/parser.rb
CHANGED
@@ -13,6 +13,7 @@ require 'stringio'
|
|
13
13
|
class Clojure
|
14
14
|
|
15
15
|
class Parser
|
16
|
+
NUMBERS = '0' .. '9'
|
16
17
|
IGNORE = [" ", ",", "\n", "\r", "\t"]
|
17
18
|
SEPARATOR = ['"', '{', '}', '(', ')', '[', ']', '#']
|
18
19
|
BOTH = IGNORE + SEPARATOR
|
@@ -55,7 +56,7 @@ class Parser
|
|
55
56
|
private
|
56
57
|
def next_type (ch)
|
57
58
|
case ch
|
58
|
-
when
|
59
|
+
when NUMBERS, '-', '+' then :number
|
59
60
|
when 't', 'f' then :boolean
|
60
61
|
when 'n' then :nil
|
61
62
|
when '\\' then :char
|
@@ -65,7 +66,7 @@ private
|
|
65
66
|
when '(' then :list
|
66
67
|
when '[' then :vector
|
67
68
|
when '#'
|
68
|
-
case read(1)
|
69
|
+
case @source.read(1)
|
69
70
|
when 'i' then :instant
|
70
71
|
when '{' then :set
|
71
72
|
when '"' then :regexp
|
@@ -82,8 +83,12 @@ private
|
|
82
83
|
end
|
83
84
|
|
84
85
|
def read_nil (ch)
|
85
|
-
|
86
|
+
check = @source.read(2)
|
87
|
+
|
88
|
+
if check.bytesize != 2
|
86
89
|
raise SyntaxError, 'unexpected EOF'
|
90
|
+
elsif check != 'il'
|
91
|
+
raise SyntaxError, "expected nil, found n#{check}"
|
87
92
|
end
|
88
93
|
|
89
94
|
nil
|
@@ -91,14 +96,22 @@ private
|
|
91
96
|
|
92
97
|
def read_boolean (ch)
|
93
98
|
if ch == 't'
|
94
|
-
|
99
|
+
check = @source.read(3)
|
100
|
+
|
101
|
+
if check.bytesize != 3
|
95
102
|
raise SyntaxError, 'unexpected EOF'
|
103
|
+
elsif check != 'rue'
|
104
|
+
raise SyntaxError, "expected true, found t#{check}"
|
96
105
|
end
|
97
|
-
|
106
|
+
|
98
107
|
true
|
99
108
|
else
|
100
|
-
|
109
|
+
check = @source.read(4)
|
110
|
+
|
111
|
+
if check.bytesize != 4
|
101
112
|
raise SyntaxError, 'unexpected EOF'
|
113
|
+
elsif check != 'alse'
|
114
|
+
raise SyntaxError, "expected false, found f#{check}"
|
102
115
|
end
|
103
116
|
|
104
117
|
false
|
@@ -108,7 +121,7 @@ private
|
|
108
121
|
def read_number (ch)
|
109
122
|
piece = ch
|
110
123
|
|
111
|
-
while (ch = read(1)) && !
|
124
|
+
while (ch = @source.read(1)) && !both?(ch)
|
112
125
|
piece << ch
|
113
126
|
end
|
114
127
|
|
@@ -134,10 +147,10 @@ private
|
|
134
147
|
end
|
135
148
|
|
136
149
|
def read_char (ch)
|
137
|
-
ch = read(1)
|
150
|
+
ch = @source.read(1)
|
138
151
|
|
139
152
|
unescape(if ch == 'u' && lookahead(1) =~ /[0-9a-fA-F]/
|
140
|
-
"\\u#{read(4)}"
|
153
|
+
"\\u#{@source.read(4)}"
|
141
154
|
else
|
142
155
|
ch
|
143
156
|
end)
|
@@ -146,7 +159,7 @@ private
|
|
146
159
|
def read_keyword (ch)
|
147
160
|
result = ''
|
148
161
|
|
149
|
-
while (ch = read(1)) && !
|
162
|
+
while (ch = @source.read(1)) && !keyword?(ch)
|
150
163
|
result << ch
|
151
164
|
end
|
152
165
|
|
@@ -158,13 +171,13 @@ private
|
|
158
171
|
def read_string (ch)
|
159
172
|
result = ''
|
160
173
|
|
161
|
-
while (ch = read(1)) != '"'
|
174
|
+
while (ch = @source.read(1)) != '"'
|
162
175
|
raise SyntaxError, 'unexpected EOF' unless ch
|
163
176
|
|
164
177
|
result << ch
|
165
178
|
|
166
179
|
if ch == '\\'
|
167
|
-
result << read(1)
|
180
|
+
result << @source.read(1)
|
168
181
|
end
|
169
182
|
end
|
170
183
|
|
@@ -172,7 +185,7 @@ private
|
|
172
185
|
end
|
173
186
|
|
174
187
|
def read_instant (ch)
|
175
|
-
read(3)
|
188
|
+
@source.read(3)
|
176
189
|
|
177
190
|
DateTime.rfc3339(read_string(ignore(false)))
|
178
191
|
end
|
@@ -180,13 +193,13 @@ private
|
|
180
193
|
def read_regexp (ch)
|
181
194
|
result = ''
|
182
195
|
|
183
|
-
while (ch = read(1)) != '"'
|
196
|
+
while (ch = @source.read(1)) != '"'
|
184
197
|
raise SyntaxError, 'unexpected EOF' unless ch
|
185
198
|
|
186
199
|
result << ch
|
187
200
|
|
188
201
|
if ch == '\\'
|
189
|
-
result << read(1)
|
202
|
+
result << @source.read(1)
|
190
203
|
end
|
191
204
|
end
|
192
205
|
|
@@ -203,7 +216,7 @@ private
|
|
203
216
|
ignore
|
204
217
|
end
|
205
218
|
|
206
|
-
read(1)
|
219
|
+
@source.read(1)
|
207
220
|
|
208
221
|
result
|
209
222
|
end
|
@@ -218,7 +231,7 @@ private
|
|
218
231
|
ignore
|
219
232
|
end
|
220
233
|
|
221
|
-
read(1)
|
234
|
+
@source.read(1)
|
222
235
|
|
223
236
|
result
|
224
237
|
end
|
@@ -233,7 +246,7 @@ private
|
|
233
246
|
ignore
|
234
247
|
end
|
235
248
|
|
236
|
-
read(1)
|
249
|
+
@source.read(1)
|
237
250
|
|
238
251
|
if result.uniq!
|
239
252
|
raise SyntaxError, 'the set contains non unique values'
|
@@ -255,7 +268,7 @@ private
|
|
255
268
|
result[key] = value
|
256
269
|
end
|
257
270
|
|
258
|
-
read(1)
|
271
|
+
@source.read(1)
|
259
272
|
|
260
273
|
result
|
261
274
|
end
|
@@ -284,10 +297,6 @@ private
|
|
284
297
|
}
|
285
298
|
end
|
286
299
|
|
287
|
-
def read (length)
|
288
|
-
@source.read(length)
|
289
|
-
end
|
290
|
-
|
291
300
|
def lookahead (length = nil)
|
292
301
|
original = @source.tell
|
293
302
|
result = @source.read(length)
|
@@ -298,7 +307,7 @@ private
|
|
298
307
|
end
|
299
308
|
|
300
309
|
def ignore (ungetc = true)
|
301
|
-
while
|
310
|
+
while ignore?(ch = @source.read(1)); end
|
302
311
|
|
303
312
|
return false unless ch
|
304
313
|
|
@@ -308,7 +317,31 @@ private
|
|
308
317
|
def revert (ch)
|
309
318
|
return unless ch
|
310
319
|
|
311
|
-
@source.
|
320
|
+
@source.seek -1, IO::SEEK_CUR
|
321
|
+
end
|
322
|
+
|
323
|
+
def ignore? (ch)
|
324
|
+
if ch == ' ' || ch == ',' || ch == "\n" || ch == "\r" || ch == "\t"
|
325
|
+
true
|
326
|
+
else
|
327
|
+
false
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
def both? (ch)
|
332
|
+
if ch == ' ' || ch == ',' || ch == '"' || ch == '{' || ch == '}' || ch == '(' || ch == ')' || ch == '[' || ch == ']' || ch == '#' || ch == "\n" || ch == "\r" || ch == "\t"
|
333
|
+
true
|
334
|
+
else
|
335
|
+
false
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
def keyword? (ch)
|
340
|
+
if ch == ' ' || ch == ',' || ch == '"' || ch == '{' || ch == '}' || ch == '(' || ch == ')' || ch == '[' || ch == ']' || ch == '#' || ch == "'" || ch == '^' || ch == '@' || ch == '`' || ch == '~' || ch == '\\' || ch == ';' || ch == "\n" || ch == "\r" || ch == "\t"
|
341
|
+
true
|
342
|
+
else
|
343
|
+
false
|
344
|
+
end
|
312
345
|
end
|
313
346
|
end
|
314
347
|
|
metadata
CHANGED
@@ -1,95 +1,70 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: clj
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 5
|
10
|
-
- 1
|
11
|
-
version: 0.0.5.1
|
12
6
|
platform: ruby
|
13
|
-
authors:
|
7
|
+
authors:
|
14
8
|
- meh.
|
15
9
|
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-02-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rake
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &7849260 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: *7849260
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &7848580 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
47
33
|
type: :development
|
48
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *7848580
|
49
36
|
description:
|
50
37
|
email: meh@paranoici.org
|
51
38
|
executables: []
|
52
|
-
|
53
39
|
extensions: []
|
54
|
-
|
55
40
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
41
|
+
files:
|
58
42
|
- lib/clj.rb
|
59
43
|
- lib/clj/types.rb
|
60
44
|
- lib/clj/parser.rb
|
61
45
|
homepage: http://github.com/meh/ruby-clj
|
62
46
|
licenses: []
|
63
|
-
|
64
47
|
post_install_message:
|
65
48
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
49
|
+
require_paths:
|
68
50
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
52
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
58
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
version: "0"
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
87
63
|
requirements: []
|
88
|
-
|
89
64
|
rubyforge_project:
|
90
65
|
rubygems_version: 1.8.15
|
91
66
|
signing_key:
|
92
67
|
specification_version: 3
|
93
68
|
summary: Like json, but with clojure sexps.
|
94
69
|
test_files: []
|
95
|
-
|
70
|
+
has_rdoc:
|