jiffy 1.0.4 → 1.1.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +13 -0
- data/Gemfile.lock +1 -1
- data/README.md +27 -28
- data/Rakefile +17 -0
- data/bin/jiffy +28 -3
- data/jiffy.gemspec +15 -66
- data/lib/jiffy.rb +27 -27
- data/lib/jiffy/array_mimicking_io.rb +1 -1
- data/lib/jiffy/outputter.rb +85 -0
- data/lib/jiffy/outputters/json.rb +35 -0
- data/lib/jiffy/outputters/ruby.rb +35 -0
- data/lib/jiffy/parser.rb +17 -0
- data/lib/jiffy/parsers/json.rb +18 -42
- data/lib/jiffy/parsers/json.rl +10 -22
- data/lib/jiffy/parsers/json_array.rb +22 -29
- data/lib/jiffy/parsers/json_array.rl +11 -12
- data/lib/jiffy/parsers/json_float.rb +39 -21
- data/lib/jiffy/parsers/json_float.rl +15 -7
- data/lib/jiffy/parsers/json_object.rb +30 -49
- data/lib/jiffy/parsers/json_object.rl +13 -20
- data/lib/jiffy/parsers/json_string.rb +70 -27
- data/lib/jiffy/parsers/json_string.rl +21 -6
- data/lib/jiffy/parsers/json_value.rb +33 -52
- data/lib/jiffy/parsers/json_value.rl +15 -34
- data/lib/jiffy/version.rb +1 -1
- data/test/jiffy_test.rb +261 -34
- data/test/outputter_test.rb +155 -0
- data/test/outputters/json_test.rb +22 -0
- metadata +9 -60
- data/lib/jiffy/json_outputter.rb +0 -62
- data/test/negative-examples/hexadecimal.json +0 -3
- data/test/negative-examples/infinity-value.json +0 -3
- data/test/negative-examples/leading-comma.json +0 -3
- data/test/negative-examples/leading-zero.json +0 -3
- data/test/negative-examples/line-break.json +0 -4
- data/test/negative-examples/missing-colon.json +0 -3
- data/test/negative-examples/nan-value,json +0 -3
- data/test/negative-examples/positive-float.json +0 -3
- data/test/negative-examples/positive-integer.json +0 -3
- data/test/negative-examples/single-quote.json +0 -3
- data/test/negative-examples/string-as-root.json +0 -1
- data/test/negative-examples/tab-character.json +0 -3
- data/test/negative-examples/trailing-array-seperator.json +0 -3
- data/test/negative-examples/trailing-object-seperator.json +0 -3
- data/test/negative-examples/true-as-root.json +0 -1
- data/test/negative-examples/unclosed-array.json +0 -2
- data/test/negative-examples/unclosed-object.json +0 -2
- data/test/positive-examples/array-as-root.json +0 -3
- data/test/positive-examples/array-nested-inside-array.json +0 -5
- data/test/positive-examples/array-nested-inside-object.json +0 -5
- data/test/positive-examples/false-value.json +0 -3
- data/test/positive-examples/null-value.json +0 -3
- data/test/positive-examples/number-1.json +0 -3
- data/test/positive-examples/number-10.json +0 -3
- data/test/positive-examples/number-11.json +0 -3
- data/test/positive-examples/number-12.json +0 -3
- data/test/positive-examples/number-13.json +0 -3
- data/test/positive-examples/number-14.json +0 -3
- data/test/positive-examples/number-15.json +0 -3
- data/test/positive-examples/number-16.json +0 -3
- data/test/positive-examples/number-17.json +0 -3
- data/test/positive-examples/number-18.json +0 -3
- data/test/positive-examples/number-19.json +0 -3
- data/test/positive-examples/number-2.json +0 -3
- data/test/positive-examples/number-20.json +0 -3
- data/test/positive-examples/number-3.json +0 -3
- data/test/positive-examples/number-4.json +0 -3
- data/test/positive-examples/number-5.json +0 -3
- data/test/positive-examples/number-6.json +0 -3
- data/test/positive-examples/number-7.json +0 -3
- data/test/positive-examples/number-8.json +0 -3
- data/test/positive-examples/number-9.json +0 -3
- data/test/positive-examples/object-as-root.json +0 -3
- data/test/positive-examples/object-nested-inside-array.json +0 -5
- data/test/positive-examples/object-nested-inside-object.json +0 -5
- data/test/positive-examples/seperated-array-values.json +0 -4
- data/test/positive-examples/seperated-object-properties.json +0 -4
- data/test/positive-examples/string-backspace.json +0 -3
- data/test/positive-examples/string-carriage-return.json +0 -3
- data/test/positive-examples/string-formfeed.json +0 -3
- data/test/positive-examples/string-horizontal-tab.json +0 -3
- data/test/positive-examples/string-newline.json +0 -3
- data/test/positive-examples/string-quotation.json +0 -3
- data/test/positive-examples/string-reverse-solidus.json +0 -3
- data/test/positive-examples/string-solidus.json +0 -3
- data/test/positive-examples/string-trivial.json +0 -3
- data/test/positive-examples/string-unicode.json +0 -3
- data/test/positive-examples/true-value.json +0 -3
@@ -4,32 +4,40 @@
|
|
4
4
|
|
5
5
|
action exit { fhold; fbreak; }
|
6
6
|
|
7
|
-
action char {
|
8
|
-
action number {
|
7
|
+
action char { y << [:char, [data[p]].pack("c*")] }
|
8
|
+
action number { y << [:number, [data[p]].pack("c*").to_i] }
|
9
|
+
action exponent { y << :exponent }
|
10
|
+
action minus { y << :minus }
|
11
|
+
action plus { y << :plus }
|
9
12
|
|
10
|
-
significand = '-'? @
|
13
|
+
significand = '-'? @minus ('0' >number | [1-9] >number [0-9]* $number) ('.' >char [0-9]+ $number)?;
|
11
14
|
|
12
|
-
exponent = [Ee] >
|
15
|
+
exponent = [Ee] >exponent ( '-' >minus | '+' >plus )? [0-9]+ $number;
|
13
16
|
|
14
17
|
main := (significand exponent?) (^[0-9Ee.\-]? @exit );
|
15
18
|
}%%
|
16
19
|
|
17
20
|
class Jiffy
|
18
21
|
module Parsers
|
19
|
-
|
22
|
+
class JsonFloat < Parser
|
20
23
|
def initialize(*args)
|
21
24
|
%% write data;
|
25
|
+
|
22
26
|
super
|
23
27
|
end
|
24
28
|
|
25
|
-
def
|
26
|
-
|
29
|
+
def parse
|
30
|
+
pe = :ignored
|
31
|
+
eof = :ignored
|
32
|
+
p = self.p
|
27
33
|
|
28
34
|
%% write init;
|
29
35
|
%% write exec;
|
30
36
|
|
31
37
|
if cs >= json_float_first_final
|
32
38
|
p
|
39
|
+
else
|
40
|
+
raise_unparseable p
|
33
41
|
end
|
34
42
|
end
|
35
43
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
|
2
2
|
# line 1 "json_object.rl"
|
3
3
|
|
4
|
-
# line
|
4
|
+
# line 24 "json_object.rl"
|
5
5
|
|
6
6
|
|
7
7
|
class Jiffy
|
8
8
|
module Parsers
|
9
|
-
|
9
|
+
class JsonObject < Parser
|
10
10
|
def initialize(*args)
|
11
11
|
|
12
12
|
# line 13 "json_object.rb"
|
@@ -140,22 +140,27 @@ end
|
|
140
140
|
self.json_object_en_main = 1;
|
141
141
|
|
142
142
|
|
143
|
-
# line
|
143
|
+
# line 31 "json_object.rl"
|
144
|
+
|
144
145
|
super
|
145
146
|
end
|
146
147
|
|
147
|
-
def
|
148
|
+
def parse
|
149
|
+
pe = :ignored
|
150
|
+
eof = :ignored
|
151
|
+
p = self.p
|
152
|
+
|
148
153
|
|
149
|
-
# line
|
154
|
+
# line 155 "json_object.rb"
|
150
155
|
begin
|
151
156
|
p ||= 0
|
152
157
|
pe ||= data.length
|
153
158
|
cs = json_object_start
|
154
159
|
end
|
155
160
|
|
156
|
-
# line
|
161
|
+
# line 41 "json_object.rl"
|
157
162
|
|
158
|
-
# line
|
163
|
+
# line 164 "json_object.rb"
|
159
164
|
begin
|
160
165
|
_klen, _trans, _keys, _acts, _nacts = nil
|
161
166
|
_goto_level = 0
|
@@ -240,42 +245,18 @@ when 0 then
|
|
240
245
|
# line 5 "json_object.rl"
|
241
246
|
begin
|
242
247
|
|
243
|
-
|
244
|
-
|
245
|
-
if np
|
246
|
-
begin p = (( np))-1; end
|
247
|
-
|
248
|
-
else
|
249
|
-
p = p - 1; begin
|
250
|
-
p += 1
|
251
|
-
_trigger_goto = true
|
252
|
-
_goto_level = _out
|
253
|
-
break
|
254
|
-
end
|
248
|
+
begin p = (( JsonValue.new(p: p, data: data, yielder: yielder).parse))-1; end
|
255
249
|
|
256
|
-
end
|
257
250
|
end
|
258
251
|
when 1 then
|
259
|
-
# line
|
252
|
+
# line 9 "json_object.rl"
|
260
253
|
begin
|
261
254
|
|
262
|
-
|
255
|
+
begin p = (( JsonString.new(p: p, data: data, yielder: yielder).parse))-1; end
|
263
256
|
|
264
|
-
if np
|
265
|
-
begin p = (( np))-1; end
|
266
|
-
|
267
|
-
else
|
268
|
-
p = p - 1; begin
|
269
|
-
p += 1
|
270
|
-
_trigger_goto = true
|
271
|
-
_goto_level = _out
|
272
|
-
break
|
273
|
-
end
|
274
|
-
|
275
|
-
end
|
276
257
|
end
|
277
258
|
when 2 then
|
278
|
-
# line
|
259
|
+
# line 13 "json_object.rl"
|
279
260
|
begin
|
280
261
|
p = p - 1; begin
|
281
262
|
p += 1
|
@@ -285,30 +266,30 @@ when 2 then
|
|
285
266
|
end
|
286
267
|
end
|
287
268
|
when 3 then
|
288
|
-
# line
|
269
|
+
# line 15 "json_object.rl"
|
289
270
|
begin
|
290
|
-
|
271
|
+
y << :begin_name end
|
291
272
|
when 4 then
|
292
|
-
# line
|
273
|
+
# line 15 "json_object.rl"
|
293
274
|
begin
|
294
|
-
|
275
|
+
y << :end_name end
|
295
276
|
when 5 then
|
296
|
-
# line
|
277
|
+
# line 15 "json_object.rl"
|
297
278
|
begin
|
298
|
-
|
279
|
+
y << :name_separator end
|
299
280
|
when 6 then
|
300
|
-
# line
|
281
|
+
# line 17 "json_object.rl"
|
301
282
|
begin
|
302
|
-
|
283
|
+
y << :value_separator end
|
303
284
|
when 7 then
|
304
|
-
# line
|
285
|
+
# line 20 "json_object.rl"
|
305
286
|
begin
|
306
|
-
|
287
|
+
y << :begin_object end
|
307
288
|
when 8 then
|
308
|
-
# line
|
289
|
+
# line 22 "json_object.rl"
|
309
290
|
begin
|
310
|
-
|
311
|
-
# line
|
291
|
+
y << :end_object end
|
292
|
+
# line 293 "json_object.rb"
|
312
293
|
end # action switch
|
313
294
|
end
|
314
295
|
end
|
@@ -335,7 +316,7 @@ when 8 then
|
|
335
316
|
end
|
336
317
|
end
|
337
318
|
|
338
|
-
# line
|
319
|
+
# line 42 "json_object.rl"
|
339
320
|
|
340
321
|
if cs >= json_object_first_final
|
341
322
|
p + 1
|
@@ -3,47 +3,40 @@
|
|
3
3
|
include json_common "json_common.rl";
|
4
4
|
|
5
5
|
action parse_value {
|
6
|
-
|
7
|
-
|
8
|
-
if np
|
9
|
-
fexec np;
|
10
|
-
else
|
11
|
-
fhold; fbreak;
|
12
|
-
end
|
6
|
+
fexec JsonValue.new(p: p, data: data, yielder: yielder).parse;
|
13
7
|
}
|
14
8
|
|
15
9
|
action parse_name {
|
16
|
-
|
17
|
-
|
18
|
-
if np
|
19
|
-
fexec np;
|
20
|
-
else
|
21
|
-
fhold; fbreak;
|
22
|
-
end
|
10
|
+
fexec JsonString.new(p: p, data: data, yielder: yielder).parse;
|
23
11
|
}
|
24
12
|
|
25
13
|
action exit { fhold; fbreak; }
|
26
14
|
|
27
|
-
pair = ignore* begin_name >{
|
15
|
+
pair = ignore* begin_name >{ y << :begin_name } >parse_name @{ y << :end_name } ignore* name_separator >{ y << :name_separator } ignore* begin_value >parse_value;
|
28
16
|
|
29
|
-
next_pair = ignore* value_separator >{
|
17
|
+
next_pair = ignore* value_separator >{ y << :value_separator } pair;
|
30
18
|
|
31
19
|
main := (
|
32
|
-
begin_object >{
|
20
|
+
begin_object >{ y << :begin_object }
|
33
21
|
(pair (next_pair)*)? ignore*
|
34
|
-
end_object >{
|
22
|
+
end_object >{ y << :end_object }
|
35
23
|
) @exit;
|
36
24
|
}%%
|
37
25
|
|
38
26
|
class Jiffy
|
39
27
|
module Parsers
|
40
|
-
|
28
|
+
class JsonObject < Parser
|
41
29
|
def initialize(*args)
|
42
30
|
%% write data;
|
31
|
+
|
43
32
|
super
|
44
33
|
end
|
45
34
|
|
46
|
-
def
|
35
|
+
def parse
|
36
|
+
pe = :ignored
|
37
|
+
eof = :ignored
|
38
|
+
p = self.p
|
39
|
+
|
47
40
|
%% write init;
|
48
41
|
%% write exec;
|
49
42
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
|
2
2
|
# line 1 "json_string.rl"
|
3
3
|
|
4
|
-
# line
|
4
|
+
# line 29 "json_string.rl"
|
5
5
|
|
6
6
|
|
7
7
|
class Jiffy
|
8
8
|
module Parsers
|
9
|
-
|
9
|
+
class JsonString < Parser
|
10
10
|
def initialize(*args)
|
11
11
|
|
12
12
|
# line 13 "json_string.rb"
|
@@ -15,7 +15,10 @@ class << self
|
|
15
15
|
private :_json_string_actions, :_json_string_actions=
|
16
16
|
end
|
17
17
|
self._json_string_actions = [
|
18
|
-
0, 1, 0, 1, 1
|
18
|
+
0, 1, 0, 1, 1, 1, 2, 1,
|
19
|
+
3, 1, 4, 1, 5, 1, 6, 1,
|
20
|
+
7, 1, 8, 1, 9, 1, 10, 1,
|
21
|
+
11, 2, 11, 12
|
19
22
|
]
|
20
23
|
|
21
24
|
class << self
|
@@ -66,25 +69,16 @@ self._json_string_index_offsets = [
|
|
66
69
|
32
|
67
70
|
]
|
68
71
|
|
69
|
-
class << self
|
70
|
-
attr_accessor :_json_string_indicies
|
71
|
-
private :_json_string_indicies, :_json_string_indicies=
|
72
|
-
end
|
73
|
-
self._json_string_indicies = [
|
74
|
-
0, 1, 3, 4, 1, 2, 2, 2,
|
75
|
-
2, 2, 2, 2, 2, 2, 5, 1,
|
76
|
-
6, 6, 6, 1, 7, 7, 7, 1,
|
77
|
-
8, 8, 8, 1, 2, 2, 2, 1,
|
78
|
-
1, 0
|
79
|
-
]
|
80
|
-
|
81
72
|
class << self
|
82
73
|
attr_accessor :_json_string_trans_targs
|
83
74
|
private :_json_string_trans_targs, :_json_string_trans_targs=
|
84
75
|
end
|
85
76
|
self._json_string_trans_targs = [
|
86
|
-
2, 0,
|
87
|
-
|
77
|
+
2, 0, 8, 3, 0, 2, 2, 2,
|
78
|
+
2, 2, 2, 2, 2, 2, 4, 0,
|
79
|
+
5, 5, 5, 0, 6, 6, 6, 0,
|
80
|
+
7, 7, 7, 0, 2, 2, 2, 0,
|
81
|
+
0, 0
|
88
82
|
]
|
89
83
|
|
90
84
|
class << self
|
@@ -92,8 +86,11 @@ class << self
|
|
92
86
|
private :_json_string_trans_actions, :_json_string_trans_actions=
|
93
87
|
end
|
94
88
|
self._json_string_trans_actions = [
|
95
|
-
0, 0,
|
96
|
-
|
89
|
+
0, 0, 1, 21, 0, 3, 5, 9,
|
90
|
+
7, 11, 13, 15, 17, 19, 0, 0,
|
91
|
+
23, 23, 23, 0, 23, 23, 23, 0,
|
92
|
+
23, 23, 23, 0, 25, 25, 25, 0,
|
93
|
+
0, 0
|
97
94
|
]
|
98
95
|
|
99
96
|
class << self
|
@@ -115,12 +112,15 @@ end
|
|
115
112
|
self.json_string_en_main = 1;
|
116
113
|
|
117
114
|
|
118
|
-
# line
|
115
|
+
# line 36 "json_string.rl"
|
116
|
+
|
119
117
|
super
|
120
118
|
end
|
121
119
|
|
122
|
-
def
|
123
|
-
|
120
|
+
def parse
|
121
|
+
pe = :ignored
|
122
|
+
eof = :ignored
|
123
|
+
p = self.p
|
124
124
|
|
125
125
|
|
126
126
|
# line 127 "json_string.rb"
|
@@ -130,7 +130,7 @@ begin
|
|
130
130
|
cs = json_string_start
|
131
131
|
end
|
132
132
|
|
133
|
-
# line
|
133
|
+
# line 46 "json_string.rl"
|
134
134
|
|
135
135
|
# line 136 "json_string.rb"
|
136
136
|
begin
|
@@ -203,7 +203,6 @@ begin
|
|
203
203
|
_trans += _klen
|
204
204
|
end
|
205
205
|
end while false
|
206
|
-
_trans = _json_string_indicies[_trans]
|
207
206
|
cs = _json_string_trans_targs[_trans]
|
208
207
|
if _json_string_trans_actions[_trans] != 0
|
209
208
|
_acts = _json_string_trans_actions[_trans]
|
@@ -226,8 +225,52 @@ when 0 then
|
|
226
225
|
when 1 then
|
227
226
|
# line 7 "json_string.rl"
|
228
227
|
begin
|
229
|
-
|
230
|
-
|
228
|
+
y << [:char, [data[p]].pack("c*")] end
|
229
|
+
when 2 then
|
230
|
+
# line 13 "json_string.rl"
|
231
|
+
begin
|
232
|
+
y << :escaped_quotation_mark end
|
233
|
+
when 3 then
|
234
|
+
# line 14 "json_string.rl"
|
235
|
+
begin
|
236
|
+
y << :escaped_reverse_solidus end
|
237
|
+
when 4 then
|
238
|
+
# line 15 "json_string.rl"
|
239
|
+
begin
|
240
|
+
y << :escaped_solidus end
|
241
|
+
when 5 then
|
242
|
+
# line 16 "json_string.rl"
|
243
|
+
begin
|
244
|
+
y << :escaped_backspace end
|
245
|
+
when 6 then
|
246
|
+
# line 17 "json_string.rl"
|
247
|
+
begin
|
248
|
+
y << :escaped_formfeed end
|
249
|
+
when 7 then
|
250
|
+
# line 18 "json_string.rl"
|
251
|
+
begin
|
252
|
+
y << :escaped_newline end
|
253
|
+
when 8 then
|
254
|
+
# line 19 "json_string.rl"
|
255
|
+
begin
|
256
|
+
y << :escaped_carriage_return end
|
257
|
+
when 9 then
|
258
|
+
# line 20 "json_string.rl"
|
259
|
+
begin
|
260
|
+
y << :escaped_horizontal_tab end
|
261
|
+
when 10 then
|
262
|
+
# line 23 "json_string.rl"
|
263
|
+
begin
|
264
|
+
unicode_sequence = "" end
|
265
|
+
when 11 then
|
266
|
+
# line 23 "json_string.rl"
|
267
|
+
begin
|
268
|
+
unicode_sequence << [data[p]].pack("c*") end
|
269
|
+
when 12 then
|
270
|
+
# line 23 "json_string.rl"
|
271
|
+
begin
|
272
|
+
y << [:escaped_unicode, unicode_sequence.to_s] end
|
273
|
+
# line 274 "json_string.rb"
|
231
274
|
end # action switch
|
232
275
|
end
|
233
276
|
end
|
@@ -254,7 +297,7 @@ when 1 then
|
|
254
297
|
end
|
255
298
|
end
|
256
299
|
|
257
|
-
# line
|
300
|
+
# line 47 "json_string.rl"
|
258
301
|
|
259
302
|
if cs >= json_string_first_final
|
260
303
|
p + 1
|
@@ -4,11 +4,23 @@
|
|
4
4
|
|
5
5
|
action exit { fhold; fbreak; }
|
6
6
|
|
7
|
-
action char {
|
7
|
+
action char { y << [:char, [data[p]].pack("c*")] }
|
8
|
+
action unicode { y << [:unicode, data[(p-4)..p].pack("c*")] }
|
8
9
|
|
9
10
|
character = ^([\"\\] | 0..0x1f) >char;
|
10
|
-
|
11
|
-
|
11
|
+
|
12
|
+
sequence = '\\' (
|
13
|
+
'"' >{ y << :escaped_quotation_mark } |
|
14
|
+
'\\' >{ y << :escaped_reverse_solidus } |
|
15
|
+
'/' >{ y << :escaped_solidus } |
|
16
|
+
'b' >{ y << :escaped_backspace } |
|
17
|
+
'f' >{ y << :escaped_formfeed } |
|
18
|
+
'n' >{ y << :escaped_newline } |
|
19
|
+
'r' >{ y << :escaped_carriage_return } |
|
20
|
+
't' >{ y << :escaped_horizontal_tab }
|
21
|
+
);
|
22
|
+
|
23
|
+
unicode = '\\u' >{ unicode_sequence = "" } [0-9a-fA-F]{4} ${ unicode_sequence << [data[p]].pack("c*") } @{ y << [:escaped_unicode, unicode_sequence.to_s] };
|
12
24
|
|
13
25
|
main := '"' (
|
14
26
|
character | sequence | unicode
|
@@ -18,14 +30,17 @@
|
|
18
30
|
|
19
31
|
class Jiffy
|
20
32
|
module Parsers
|
21
|
-
|
33
|
+
class JsonString < Parser
|
22
34
|
def initialize(*args)
|
23
35
|
%% write data;
|
36
|
+
|
24
37
|
super
|
25
38
|
end
|
26
39
|
|
27
|
-
def
|
28
|
-
|
40
|
+
def parse
|
41
|
+
pe = :ignored
|
42
|
+
eof = :ignored
|
43
|
+
p = self.p
|
29
44
|
|
30
45
|
%% write init;
|
31
46
|
%% write exec;
|