yajl - JSON library working with the compiler. URL: http://lloyd.github.com/yajl/

Dependencies:   mbed

Committer:
rolf
Date:
Wed Nov 18 17:56:51 2009 +0000
Revision:
0:34f4a53d4ca3

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rolf 0:34f4a53d4ca3 1 /*
rolf 0:34f4a53d4ca3 2 * Copyright 2007-2009, Lloyd Hilaiel.
rolf 0:34f4a53d4ca3 3 *
rolf 0:34f4a53d4ca3 4 * Redistribution and use in source and binary forms, with or without
rolf 0:34f4a53d4ca3 5 * modification, are permitted provided that the following conditions are
rolf 0:34f4a53d4ca3 6 * met:
rolf 0:34f4a53d4ca3 7 *
rolf 0:34f4a53d4ca3 8 * 1. Redistributions of source code must retain the above copyright
rolf 0:34f4a53d4ca3 9 * notice, this list of conditions and the following disclaimer.
rolf 0:34f4a53d4ca3 10 *
rolf 0:34f4a53d4ca3 11 * 2. Redistributions in binary form must reproduce the above copyright
rolf 0:34f4a53d4ca3 12 * notice, this list of conditions and the following disclaimer in
rolf 0:34f4a53d4ca3 13 * the documentation and/or other materials provided with the
rolf 0:34f4a53d4ca3 14 * distribution.
rolf 0:34f4a53d4ca3 15 *
rolf 0:34f4a53d4ca3 16 * 3. Neither the name of Lloyd Hilaiel nor the names of its
rolf 0:34f4a53d4ca3 17 * contributors may be used to endorse or promote products derived
rolf 0:34f4a53d4ca3 18 * from this software without specific prior written permission.
rolf 0:34f4a53d4ca3 19 *
rolf 0:34f4a53d4ca3 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
rolf 0:34f4a53d4ca3 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
rolf 0:34f4a53d4ca3 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
rolf 0:34f4a53d4ca3 23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
rolf 0:34f4a53d4ca3 24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
rolf 0:34f4a53d4ca3 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
rolf 0:34f4a53d4ca3 26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
rolf 0:34f4a53d4ca3 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
rolf 0:34f4a53d4ca3 28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
rolf 0:34f4a53d4ca3 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
rolf 0:34f4a53d4ca3 30 * POSSIBILITY OF SUCH DAMAGE.
rolf 0:34f4a53d4ca3 31 */
rolf 0:34f4a53d4ca3 32
rolf 0:34f4a53d4ca3 33 #ifndef __YAJL_LEX_H__
rolf 0:34f4a53d4ca3 34 #define __YAJL_LEX_H__
rolf 0:34f4a53d4ca3 35
rolf 0:34f4a53d4ca3 36 #ifdef __cplusplus
rolf 0:34f4a53d4ca3 37 extern "C" {
rolf 0:34f4a53d4ca3 38 #endif
rolf 0:34f4a53d4ca3 39
rolf 0:34f4a53d4ca3 40 #include "yajl/yajl_common.h"
rolf 0:34f4a53d4ca3 41
rolf 0:34f4a53d4ca3 42 typedef enum {
rolf 0:34f4a53d4ca3 43 yajl_tok_bool,
rolf 0:34f4a53d4ca3 44 yajl_tok_colon,
rolf 0:34f4a53d4ca3 45 yajl_tok_comma,
rolf 0:34f4a53d4ca3 46 yajl_tok_eof,
rolf 0:34f4a53d4ca3 47 yajl_tok_error,
rolf 0:34f4a53d4ca3 48 yajl_tok_left_brace,
rolf 0:34f4a53d4ca3 49 yajl_tok_left_bracket,
rolf 0:34f4a53d4ca3 50 yajl_tok_null,
rolf 0:34f4a53d4ca3 51 yajl_tok_right_brace,
rolf 0:34f4a53d4ca3 52 yajl_tok_right_bracket,
rolf 0:34f4a53d4ca3 53
rolf 0:34f4a53d4ca3 54 /* we differentiate between integers and doubles to allow the
rolf 0:34f4a53d4ca3 55 * parser to interpret the number without re-scanning */
rolf 0:34f4a53d4ca3 56 yajl_tok_integer,
rolf 0:34f4a53d4ca3 57 yajl_tok_double,
rolf 0:34f4a53d4ca3 58
rolf 0:34f4a53d4ca3 59 /* we differentiate between strings which require further processing,
rolf 0:34f4a53d4ca3 60 * and strings that do not */
rolf 0:34f4a53d4ca3 61 yajl_tok_string,
rolf 0:34f4a53d4ca3 62 yajl_tok_string_with_escapes,
rolf 0:34f4a53d4ca3 63
rolf 0:34f4a53d4ca3 64 /* comment tokens are not currently returned to the parser, ever */
rolf 0:34f4a53d4ca3 65 yajl_tok_comment
rolf 0:34f4a53d4ca3 66 } yajl_tok;
rolf 0:34f4a53d4ca3 67
rolf 0:34f4a53d4ca3 68 typedef struct yajl_lexer_t * yajl_lexer;
rolf 0:34f4a53d4ca3 69
rolf 0:34f4a53d4ca3 70 yajl_lexer yajl_lex_alloc(yajl_alloc_funcs * alloc,
rolf 0:34f4a53d4ca3 71 unsigned int allowComments,
rolf 0:34f4a53d4ca3 72 unsigned int validateUTF8);
rolf 0:34f4a53d4ca3 73
rolf 0:34f4a53d4ca3 74 void yajl_lex_free(yajl_lexer lexer);
rolf 0:34f4a53d4ca3 75
rolf 0:34f4a53d4ca3 76 /**
rolf 0:34f4a53d4ca3 77 * run/continue a lex. "offset" is an input/output parameter.
rolf 0:34f4a53d4ca3 78 * It should be initialized to zero for a
rolf 0:34f4a53d4ca3 79 * new chunk of target text, and upon subsetquent calls with the same
rolf 0:34f4a53d4ca3 80 * target text should passed with the value of the previous invocation.
rolf 0:34f4a53d4ca3 81 *
rolf 0:34f4a53d4ca3 82 * the client may be interested in the value of offset when an error is
rolf 0:34f4a53d4ca3 83 * returned from the lexer. This allows the client to render useful
rolf 0:34f4a53d4ca3 84 n * error messages.
rolf 0:34f4a53d4ca3 85 *
rolf 0:34f4a53d4ca3 86 * When you pass the next chunk of data, context should be reinitialized
rolf 0:34f4a53d4ca3 87 * to zero.
rolf 0:34f4a53d4ca3 88 *
rolf 0:34f4a53d4ca3 89 * Finally, the output buffer is usually just a pointer into the jsonText,
rolf 0:34f4a53d4ca3 90 * however in cases where the entity being lexed spans multiple chunks,
rolf 0:34f4a53d4ca3 91 * the lexer will buffer the entity and the data returned will be
rolf 0:34f4a53d4ca3 92 * a pointer into that buffer.
rolf 0:34f4a53d4ca3 93 *
rolf 0:34f4a53d4ca3 94 * This behavior is abstracted from client code except for the performance
rolf 0:34f4a53d4ca3 95 * implications which require that the client choose a reasonable chunk
rolf 0:34f4a53d4ca3 96 * size to get adequate performance.
rolf 0:34f4a53d4ca3 97 */
rolf 0:34f4a53d4ca3 98 yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
rolf 0:34f4a53d4ca3 99 unsigned int jsonTextLen, unsigned int * offset,
rolf 0:34f4a53d4ca3 100 const unsigned char ** outBuf, unsigned int * outLen);
rolf 0:34f4a53d4ca3 101
rolf 0:34f4a53d4ca3 102 /** have a peek at the next token, but don't move the lexer forward */
rolf 0:34f4a53d4ca3 103 yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText,
rolf 0:34f4a53d4ca3 104 unsigned int jsonTextLen, unsigned int offset);
rolf 0:34f4a53d4ca3 105
rolf 0:34f4a53d4ca3 106
rolf 0:34f4a53d4ca3 107 typedef enum {
rolf 0:34f4a53d4ca3 108 yajl_lex_e_ok = 0,
rolf 0:34f4a53d4ca3 109 yajl_lex_string_invalid_utf8,
rolf 0:34f4a53d4ca3 110 yajl_lex_string_invalid_escaped_char,
rolf 0:34f4a53d4ca3 111 yajl_lex_string_invalid_json_char,
rolf 0:34f4a53d4ca3 112 yajl_lex_string_invalid_hex_char,
rolf 0:34f4a53d4ca3 113 yajl_lex_invalid_char,
rolf 0:34f4a53d4ca3 114 yajl_lex_invalid_string,
rolf 0:34f4a53d4ca3 115 yajl_lex_missing_integer_after_decimal,
rolf 0:34f4a53d4ca3 116 yajl_lex_missing_integer_after_exponent,
rolf 0:34f4a53d4ca3 117 yajl_lex_missing_integer_after_minus,
rolf 0:34f4a53d4ca3 118 yajl_lex_unallowed_comment
rolf 0:34f4a53d4ca3 119 } yajl_lex_error;
rolf 0:34f4a53d4ca3 120
rolf 0:34f4a53d4ca3 121 const char * yajl_lex_error_to_string(yajl_lex_error error);
rolf 0:34f4a53d4ca3 122
rolf 0:34f4a53d4ca3 123 /** allows access to more specific information about the lexical
rolf 0:34f4a53d4ca3 124 * error when yajl_lex_lex returns yajl_tok_error. */
rolf 0:34f4a53d4ca3 125 yajl_lex_error yajl_lex_get_error(yajl_lexer lexer);
rolf 0:34f4a53d4ca3 126
rolf 0:34f4a53d4ca3 127 /** get the current offset into the most recently lexed json string. */
rolf 0:34f4a53d4ca3 128 unsigned int yajl_lex_current_offset(yajl_lexer lexer);
rolf 0:34f4a53d4ca3 129
rolf 0:34f4a53d4ca3 130 /** get the number of lines lexed by this lexer instance */
rolf 0:34f4a53d4ca3 131 unsigned int yajl_lex_current_line(yajl_lexer lexer);
rolf 0:34f4a53d4ca3 132
rolf 0:34f4a53d4ca3 133 /** get the number of chars lexed by this lexer instance since the last
rolf 0:34f4a53d4ca3 134 * \n or \r */
rolf 0:34f4a53d4ca3 135 unsigned int yajl_lex_current_char(yajl_lexer lexer);
rolf 0:34f4a53d4ca3 136
rolf 0:34f4a53d4ca3 137 #ifdef __cplusplus
rolf 0:34f4a53d4ca3 138 }
rolf 0:34f4a53d4ca3 139 #endif
rolf 0:34f4a53d4ca3 140
rolf 0:34f4a53d4ca3 141 #endif