jx_parse.h File Reference

Parse JSON strings and files into JX expressions. More...

#include "jx.h"
#include "link.h"
#include <stdio.h>

Go to the source code of this file.

Functions

struct jxjx_parse_string (const char *str)
 Parse a JSON string to a JX expression.
struct jxjx_parse_stream (FILE *file)
 Parse a standard IO stream to a JX expression.
struct jxjx_parse_file (const char *name)
 Parse a file to a JX expression.
struct jxjx_parse_link (struct link *l, time_t stoptime)
 Parse a network link to a JX expression.
struct jx_parser * jx_parser_create ()
 Create a JX parser object.
void jx_parser_read_stream (struct jx_parser *p, FILE *file)
 Attach parser to a file.
void jx_parser_read_string (struct jx_parser *p, const char *str)
 Attach parser to a string.
void jx_parser_read_link (struct jx_parser *p, struct link *l, time_t stoptime)
 Attach parser to a link.
struct jxjx_parser_yield (struct jx_parser *p)
 Parse and return a single value.
struct jxjx_parse (struct jx_parser *p)
 Parse a JX expression.
int jx_parser_errors (struct jx_parser *p)
 Return number of parse errors.
const char * jx_parser_error_string (struct jx_parser *p)
 Return text of parse error.
void jx_parser_delete (struct jx_parser *p)
 Delete a parser.

Detailed Description

Parse JSON strings and files into JX expressions.

This module parses arbirary JSON expressions according to the definition at json.org, with the following exceptions:

  1. Atomic values are limited to 4KB in size.
  2. Bare identifiers are permitted, to enable expression evaluation.

Function Documentation

struct jx* jx_parse_string ( const char *  str  )  [read]

Parse a JSON string to a JX expression.

Parameters:
str A C string containing JSON data.
Returns:
A JX expression which must be deleted with jx_delete. If the parse fails or no JSON value is present, null is returned.
struct jx* jx_parse_stream ( FILE *  file  )  [read]

Parse a standard IO stream to a JX expression.

Parameters:
file A stream containing JSON data.
Returns:
A JX expression which must be deleted with jx_delete. If the parse fails or no JSON value is present, null is returned.
struct jx* jx_parse_file ( const char *  name  )  [read]

Parse a file to a JX expression.

Parameters:
name The name of a file containing JSON data.
Returns:
A JX expression which must be deleted with jx_delete. If the parse fails or no JSON value is present, null is returned.
struct jx* jx_parse_link ( struct link *  l,
time_t  stoptime 
) [read]

Parse a network link to a JX expression.

Parameters:
l A link object.
stoptime The absolute time at which to stop.
Returns:
A JX expression which must be deleted with jx_delete. If the parse fails or no JSON value is present, null is returned.
struct jx_parser* jx_parser_create (  )  [read]

Create a JX parser object.

Returns:
A parser object.
void jx_parser_read_stream ( struct jx_parser *  p,
FILE *  file 
)

Attach parser to a file.

Parameters:
p A parser object.
file A standard IO stream.
void jx_parser_read_string ( struct jx_parser *  p,
const char *  str 
)

Attach parser to a string.

Parameters:
p A parser object.
str A JSON string to parse.
void jx_parser_read_link ( struct jx_parser *  p,
struct link *  l,
time_t  stoptime 
)

Attach parser to a link.

Parameters:
p A parser object.
l A link object.
stoptime The absolute time at which to stop.
struct jx* jx_parser_yield ( struct jx_parser *  p  )  [read]

Parse and return a single value.

This function is useful for streaming multiple independent values from a single source.

Parameters:
p A parser object
Returns:
A JX expression which must be deleted with jx_delete. If the parse fails or no JSON value is present, null is returned.
struct jx* jx_parse ( struct jx_parser *  p  )  [read]

Parse a JX expression.

Note that in the event of a parse error, this function can return a partial result, reflecting the text that was parseable. You must call jx_parser_errors to determine if the parse was successul.

Parameters:
p A parser created by jx_parser_create.
Returns:
A JX expression, or null if nothing was parsed.
int jx_parser_errors ( struct jx_parser *  p  ) 

Return number of parse errors.

Parameters:
p A parser object.
Returns:
Number of parse errors encountered.
const char* jx_parser_error_string ( struct jx_parser *  p  ) 

Return text of parse error.

Parameters:
p A parser object.
Returns:
Error string, if available, null otherwise.
void jx_parser_delete ( struct jx_parser *  p  ) 

Delete a parser.

Parameters:
p The parser to delete.

Generated on 3 Nov 2016 for cctools by  doxygen 1.6.1