diff options
author | Nicolas Williams <nico@cryptonector.com> | 2014-12-22 23:06:27 -0600 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2014-12-26 23:05:56 -0600 |
commit | 5bfb9781f7e5ba2ad99b71150bccc559d53b928f (patch) | |
tree | a6c1a446f802ebdaa7c505340d2573d888402f73 /execute.c | |
parent | 906d2537b9d0384985ed6259ef77ca1bd3d503ed (diff) |
Add Streaming parser (--stream)
Streaming means that outputs are produced as soon as possible. With the
`foreach` syntax one can write programs which reduce portions of the
streaming parse of a large input (reduce into proper JSON values, for
example), and discard the rest, processing incrementally.
This:
$ jq -c --stream .
should produce the same output as this:
$ jq -c '. as $dot | path(..) as $p | $dot | getpath($p) | [$p,.]'
The output of `jq --stream .` should be a sequence of`[[<path>],<leaf>]`
and `[[<path>]]` values. The latter indicate that the array/object at
that path ended.
Scalars and empty arrays and objects are leaf values for this purpose.
For example, a truncated input produces a path as soon as possible, then
later the error:
$ printf '[0,\n'|./jq -c --stream .
[[0],0]
parse error: Unfinished JSON term at EOF at line 3, column 0
$
Diffstat (limited to 'execute.c')
-rw-r--r-- | execute.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -39,6 +39,8 @@ struct jq_state { int initial_execution; jv attrs; + jq_input_cb input_cb; + void *input_cb_data; }; struct closure { @@ -1037,3 +1039,13 @@ jv jq_get_attr(jq_state *jq, jv attr) { void jq_dump_disassembly(jq_state *jq, int indent) { dump_disassembly(indent, jq->bc); } + +void jq_set_input_cb(jq_state *jq, jq_input_cb cb, void *data) { + jq->input_cb = cb; + jq->input_cb_data = data; +} + +void jq_get_input_cb(jq_state *jq, jq_input_cb *cb, void **data) { + *cb = jq->input_cb; + *data = jq->input_cb_data; +} |