2013-06-16 08:25:12 -05:00
|
|
|
#ifndef _JQ_H_
|
|
|
|
#define _JQ_H_
|
2012-09-18 22:17:13 +01:00
|
|
|
|
2013-11-30 02:05:42 -06:00
|
|
|
#include <stdio.h>
|
2013-06-16 08:25:12 -05:00
|
|
|
#include <jv.h>
|
2013-05-06 14:21:00 +01:00
|
|
|
|
2013-05-05 23:12:10 +01:00
|
|
|
enum {JQ_DEBUG_TRACE = 1};
|
2013-04-28 18:33:45 -05:00
|
|
|
|
2013-06-16 08:25:12 -05:00
|
|
|
typedef struct jq_state jq_state;
|
2013-11-30 02:05:42 -06:00
|
|
|
typedef void (*jq_err_cb)(void *, jv);
|
|
|
|
|
2013-06-06 17:26:15 -05:00
|
|
|
jq_state *jq_init(void);
|
2013-11-30 02:05:42 -06:00
|
|
|
void jq_set_error_cb(jq_state *, jq_err_cb, void *);
|
|
|
|
void jq_get_error_cb(jq_state *, jq_err_cb *, void **);
|
2013-06-06 17:26:15 -05:00
|
|
|
void jq_set_nomem_handler(jq_state *, void (*)(void *), void *);
|
2014-08-11 17:25:09 -05:00
|
|
|
jv jq_format_error(jv msg);
|
|
|
|
void jq_report_error(jq_state *, jv);
|
2014-08-10 16:52:03 -05:00
|
|
|
int jq_compile(jq_state *, const char*);
|
|
|
|
int jq_compile_args(jq_state *, const char*, jv);
|
2013-06-16 08:25:12 -05:00
|
|
|
void jq_dump_disassembly(jq_state *, int);
|
2014-08-10 16:52:03 -05:00
|
|
|
void jq_start(jq_state *, jv value, int);
|
2013-04-28 18:33:45 -05:00
|
|
|
jv jq_next(jq_state *);
|
|
|
|
void jq_teardown(jq_state **);
|
2012-09-18 22:17:13 +01:00
|
|
|
|
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
$
2014-12-22 23:06:27 -06:00
|
|
|
typedef jv (*jq_input_cb)(jq_state *, void *);
|
|
|
|
void jq_set_input_cb(jq_state *, jq_input_cb, void *);
|
|
|
|
void jq_get_input_cb(jq_state *, jq_input_cb *, void **);
|
|
|
|
|
2014-08-10 16:52:03 -05:00
|
|
|
void jq_set_attrs(jq_state *, jv);
|
|
|
|
jv jq_get_attrs(jq_state *);
|
2014-11-24 17:58:34 -06:00
|
|
|
jv jq_get_jq_origin(jq_state *);
|
|
|
|
jv jq_get_prog_origin(jq_state *);
|
2014-07-09 00:55:20 -04:00
|
|
|
jv jq_get_lib_dirs(jq_state *);
|
2014-08-10 16:52:03 -05:00
|
|
|
void jq_set_attr(jq_state *, jv, jv);
|
|
|
|
jv jq_get_attr(jq_state *, jv);
|
2013-06-16 08:25:12 -05:00
|
|
|
#endif /* !_JQ_H_ */
|