groonga-command-parser 1.0.9 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +12 -0
- data/lib/groonga/command/parser.rb +8 -12
- data/lib/groonga/command/parser/command/groonga-command-convert-format.rb +1 -0
- data/lib/groonga/command/parser/load-values-parser.rb +11 -2
- data/lib/groonga/command/parser/version.rb +1 -1
- data/test/test-load-value-parser.rb +16 -2
- data/test/test-parser.rb +76 -46
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2f5dd8bb9f225dd59a1441b1ee4ba18fc7b1d74
|
4
|
+
data.tar.gz: f202a12f7824fbdfd1bdf7dd31fc1542464d5868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b056beeb0f6dd1971ba3e2688d0a623e57f88c7d9389df817b81e09583626adf3d596c98434f21e88b6d28c1aded38125dd8e08ba1550eb41a0e818d6ec80050
|
7
|
+
data.tar.gz: 66c6b6d7739e3889f1e205054ed600f830dcd9ecb1816f33a72af916fadd46d5a8037200e31b8536c4405d94d48804aa3ac56df0a3130fae5e014184dcecc01d
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
+
## 1.1.0: 2017-10-30
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* `groonga-command-convert-format`: Stopped to require the last
|
8
|
+
newline.
|
9
|
+
|
10
|
+
### Fixes
|
11
|
+
|
12
|
+
* Fixed a bug that commands after `load` are ignored on `String`
|
13
|
+
parse mode.
|
14
|
+
|
3
15
|
## 1.0.9: 2017-01-18
|
4
16
|
|
5
17
|
### Improvements
|
@@ -1,6 +1,4 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011-2015 Kouhei Sutou <kou@clear-code.com>
|
1
|
+
# Copyright (C) 2011-2017 Kouhei Sutou <kou@clear-code.com>
|
4
2
|
#
|
5
3
|
# This library is free software; you can redistribute it and/or
|
6
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -59,8 +57,8 @@ module Groonga
|
|
59
57
|
parser.on_load_start do |command|
|
60
58
|
yield(:on_load_start, command)
|
61
59
|
end
|
62
|
-
parser.on_load_columns do |command,
|
63
|
-
yield(:on_load_columns, command,
|
60
|
+
parser.on_load_columns do |command, columns|
|
61
|
+
yield(:on_load_columns, command, columns)
|
64
62
|
end
|
65
63
|
parser.on_load_value do |command, value|
|
66
64
|
yield(:on_load_value, command, value)
|
@@ -221,9 +219,7 @@ module Groonga
|
|
221
219
|
|
222
220
|
def consume_load_values(tag)
|
223
221
|
throw(tag) if @buffer.empty?
|
224
|
-
@command.original_source << @buffer
|
225
222
|
@load_values_parser << @buffer
|
226
|
-
@buffer.clear
|
227
223
|
end
|
228
224
|
|
229
225
|
def consume_line(tag)
|
@@ -361,14 +357,14 @@ module Groonga
|
|
361
357
|
on_load_value(@command, value)
|
362
358
|
end
|
363
359
|
end
|
360
|
+
@load_values_parser.on_consumed = lambda do |consumed|
|
361
|
+
@command.original_source << consumed if @loading
|
362
|
+
end
|
364
363
|
@load_values_parser.on_end = lambda do |rest|
|
365
|
-
|
366
|
-
original_source_size = @command.original_source.size
|
367
|
-
@command.original_source.slice!(original_source_size - rest.size,
|
368
|
-
rest.size)
|
369
|
-
end
|
364
|
+
loading = @loading
|
370
365
|
on_load_complete(@command)
|
371
366
|
reset
|
367
|
+
@buffer << rest if loading and rest
|
372
368
|
end
|
373
369
|
end
|
374
370
|
end
|
@@ -21,10 +21,12 @@ module Groonga
|
|
21
21
|
class Parser
|
22
22
|
class LoadValuesParser
|
23
23
|
attr_writer :on_value
|
24
|
+
attr_writer :on_consumed
|
24
25
|
attr_writer :on_end
|
25
26
|
def initialize
|
26
27
|
initialize_parser
|
27
28
|
@on_value = nil
|
29
|
+
@on_consumed = nil
|
28
30
|
@on_end = nil
|
29
31
|
@containers = []
|
30
32
|
@keys = []
|
@@ -49,9 +51,16 @@ module Groonga
|
|
49
51
|
:continue
|
50
52
|
end
|
51
53
|
|
54
|
+
pos = @parser.pos
|
55
|
+
consumed = pos - before_pos
|
56
|
+
if consumed > 0
|
57
|
+
if consumed < data_size
|
58
|
+
@on_consumed.call(data[0, consumed])
|
59
|
+
else
|
60
|
+
@on_consumed.call(data)
|
61
|
+
end
|
62
|
+
end
|
52
63
|
if status == :done
|
53
|
-
pos = @parser.pos
|
54
|
-
consumed = pos - before_pos
|
55
64
|
if consumed < data_size
|
56
65
|
@on_end.call(data[consumed..-1])
|
57
66
|
else
|
@@ -21,7 +21,12 @@ class LoadValuesParserTest < Test::Unit::TestCase
|
|
21
21
|
@parser.on_value = lambda do |value|
|
22
22
|
@values << value
|
23
23
|
end
|
24
|
+
@parse_consumed = []
|
25
|
+
@parser.on_consumed = lambda do |consumed|
|
26
|
+
@parse_consumed << consumed
|
27
|
+
end
|
24
28
|
@parse_done = false
|
29
|
+
@parse_rest = nil
|
25
30
|
@parser.on_end = lambda do |rest|
|
26
31
|
@parse_done = true
|
27
32
|
@parse_rest = rest
|
@@ -186,8 +191,17 @@ class LoadValuesParserTest < Test::Unit::TestCase
|
|
186
191
|
}
|
187
192
|
]garbage
|
188
193
|
JSON
|
189
|
-
|
190
|
-
|
194
|
+
consumed = [
|
195
|
+
"[\n",
|
196
|
+
" {\n",
|
197
|
+
" \"object\": {\n",
|
198
|
+
" \"string\": \"abc\"\n",
|
199
|
+
" }\n",
|
200
|
+
" }\n",
|
201
|
+
"]",
|
202
|
+
]
|
203
|
+
assert_equal([true, consumed, "garbage\n"],
|
204
|
+
[@parse_done, @parse_consumed, @parse_rest])
|
191
205
|
end
|
192
206
|
end
|
193
207
|
end
|
data/test/test-parser.rb
CHANGED
@@ -253,108 +253,138 @@ status
|
|
253
253
|
class MultiLineTest < self
|
254
254
|
class BracketTest < self
|
255
255
|
def test_have_columns
|
256
|
-
@parser << <<-
|
256
|
+
@parser << <<-COMMAND
|
257
257
|
load --table Users --columns "_key, name"
|
258
258
|
[
|
259
259
|
["alice", "Alice"]
|
260
260
|
]
|
261
|
-
|
261
|
+
COMMAND
|
262
|
+
|
262
263
|
expected_events = []
|
263
|
-
expected_events << [:load_start, <<-
|
264
|
+
expected_events << [:load_start, <<-COMMAND.chomp]
|
264
265
|
load --table Users --columns "_key, name"
|
265
|
-
|
266
|
-
expected_events << [:load_columns, <<-
|
266
|
+
COMMAND
|
267
|
+
expected_events << [:load_columns, <<-COMMAND.chomp, ["_key", "name"]]
|
267
268
|
load --table Users --columns "_key, name"
|
268
|
-
|
269
|
-
expected_events << [:load_value, <<-
|
269
|
+
COMMAND
|
270
|
+
expected_events << [:load_value, <<-COMMAND, ["alice", "Alice"]]
|
270
271
|
load --table Users --columns "_key, name"
|
271
|
-
|
272
|
-
[
|
273
|
-
]
|
274
|
-
EOC
|
275
|
-
expected_events << [:load_complete, <<-EOC.chomp]
|
272
|
+
COMMAND
|
273
|
+
expected_events << [:load_complete, <<-COMMAND.chomp]
|
276
274
|
load --table Users --columns "_key, name"
|
277
275
|
[
|
278
276
|
["alice", "Alice"]
|
279
277
|
]
|
280
|
-
|
278
|
+
COMMAND
|
281
279
|
assert_equal(expected_events, @events)
|
282
280
|
end
|
283
281
|
|
284
282
|
def test_no_columns
|
285
|
-
@parser << <<-
|
283
|
+
@parser << <<-COMMAND
|
286
284
|
load --table Users
|
287
285
|
[
|
288
286
|
["_key", "name"],
|
289
287
|
["alice", "Alice"]
|
290
288
|
]
|
291
|
-
|
289
|
+
COMMAND
|
290
|
+
|
292
291
|
expected_events = []
|
293
|
-
expected_events << [:load_start, <<-
|
292
|
+
expected_events << [:load_start, <<-COMMAND.chomp]
|
294
293
|
load --table Users
|
295
|
-
|
296
|
-
expected_events << [:load_columns, <<-
|
294
|
+
COMMAND
|
295
|
+
expected_events << [:load_columns, <<-COMMAND, ["_key", "name"]]
|
297
296
|
load --table Users
|
298
|
-
|
299
|
-
["
|
300
|
-
["alice", "Alice"]
|
301
|
-
]
|
302
|
-
EOC
|
303
|
-
expected_events << [:load_value, <<-EOC, ["alice", "Alice"]]
|
297
|
+
COMMAND
|
298
|
+
expected_events << [:load_value, <<-COMMAND, ["alice", "Alice"]]
|
304
299
|
load --table Users
|
305
|
-
|
306
|
-
[
|
307
|
-
["alice", "Alice"]
|
308
|
-
]
|
309
|
-
EOC
|
310
|
-
expected_events << [:load_complete, <<-EOC.chomp]
|
300
|
+
COMMAND
|
301
|
+
expected_events << [:load_complete, <<-COMMAND.chomp]
|
311
302
|
load --table Users
|
312
303
|
[
|
313
304
|
["_key", "name"],
|
314
305
|
["alice", "Alice"]
|
315
306
|
]
|
316
|
-
|
307
|
+
COMMAND
|
317
308
|
assert_equal(expected_events, @events)
|
318
309
|
end
|
319
310
|
end
|
320
311
|
|
321
312
|
def test_brace
|
322
|
-
@parser << <<-
|
313
|
+
@parser << <<-COMMAND
|
323
314
|
load --table Users
|
324
315
|
[
|
325
316
|
{"_key": "alice", "name": "Alice"},
|
326
317
|
{"_key": "bob", "name": "Bob"}
|
327
318
|
]
|
328
|
-
|
319
|
+
COMMAND
|
320
|
+
|
329
321
|
expected_events = []
|
330
|
-
expected_events << [:load_start, <<-
|
322
|
+
expected_events << [:load_start, <<-COMMAND.chomp]
|
331
323
|
load --table Users
|
332
|
-
|
324
|
+
COMMAND
|
333
325
|
value = {"_key" => "alice", "name" => "Alice"}
|
334
|
-
expected_events << [:load_value, <<-
|
326
|
+
expected_events << [:load_value, <<-COMMAND, value]
|
327
|
+
load --table Users
|
328
|
+
COMMAND
|
329
|
+
value = {"_key" => "bob", "name" => "Bob"}
|
330
|
+
expected_events << [:load_value, <<-COMMAND, value]
|
331
|
+
load --table Users
|
332
|
+
COMMAND
|
333
|
+
expected_events << [:load_complete, <<-COMMAND.chomp]
|
335
334
|
load --table Users
|
336
335
|
[
|
337
336
|
{"_key": "alice", "name": "Alice"},
|
338
337
|
{"_key": "bob", "name": "Bob"}
|
339
338
|
]
|
340
|
-
|
341
|
-
|
342
|
-
|
339
|
+
COMMAND
|
340
|
+
assert_equal(expected_events, @events)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_multiple
|
345
|
+
@parser << <<-COMMANDS
|
346
|
+
load --table Users
|
347
|
+
[
|
348
|
+
{"_key": "alice", "name": "Alice"}
|
349
|
+
]
|
350
|
+
|
343
351
|
load --table Users
|
344
352
|
[
|
345
|
-
{"_key": "alice", "name": "Alice"},
|
346
353
|
{"_key": "bob", "name": "Bob"}
|
347
354
|
]
|
348
|
-
|
349
|
-
|
355
|
+
COMMANDS
|
356
|
+
|
357
|
+
expected_events = []
|
358
|
+
|
359
|
+
expected_events << [:load_start, <<-SOURCE.chomp]
|
360
|
+
load --table Users
|
361
|
+
SOURCE
|
362
|
+
value = {"_key" => "alice", "name" => "Alice"}
|
363
|
+
expected_events << [:load_value, <<-SOURCE, value]
|
364
|
+
load --table Users
|
365
|
+
SOURCE
|
366
|
+
expected_events << [:load_complete, <<-SOURCE.chomp]
|
367
|
+
load --table Users
|
368
|
+
[
|
369
|
+
{"_key": "alice", "name": "Alice"}
|
370
|
+
]
|
371
|
+
SOURCE
|
372
|
+
|
373
|
+
expected_events << [:load_start, <<-SOURCE.chomp]
|
374
|
+
load --table Users
|
375
|
+
SOURCE
|
376
|
+
value = {"_key" => "bob", "name" => "Bob"}
|
377
|
+
expected_events << [:load_value, <<-SOURCE, value]
|
378
|
+
load --table Users
|
379
|
+
SOURCE
|
380
|
+
expected_events << [:load_complete, <<-SOURCE.chomp]
|
350
381
|
load --table Users
|
351
382
|
[
|
352
|
-
{"_key": "alice", "name": "Alice"},
|
353
383
|
{"_key": "bob", "name": "Bob"}
|
354
384
|
]
|
355
|
-
|
356
|
-
|
357
|
-
|
385
|
+
SOURCE
|
386
|
+
|
387
|
+
assert_equal(expected_events, @events)
|
358
388
|
end
|
359
389
|
|
360
390
|
class ErrorTest < self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-command-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: groonga-command
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.5.2
|
189
|
+
rubygems_version: 2.5.2.1
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Groonga-command-parser is a Ruby library to parses [groonga](http://groonga.org/)'s
|