1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io> 3 | * 4 | * Permission to use, copy, modify, and/or distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /** 18 | * A JSON text lexical analyzer. 19 | * 20 | * Common and shared declarations for the lexer. 21 | **/ 22 | 23 | #ifndef __YAJL_LEX_H__ 24 | #define __YAJL_LEX_H__ 25 | 26 | #include "yajl/yajl_common.h" 27 | 28 | typedef enum { 29 | yajl_tok_bool, 30 | yajl_tok_colon, 31 | yajl_tok_comma, 32 | yajl_tok_eof, 33 | yajl_tok_error, 34 | yajl_tok_left_brace, 35 | yajl_tok_left_bracket, 36 | yajl_tok_null, 37 | yajl_tok_right_brace, 38 | yajl_tok_right_bracket, 39 | 40 | /*+ we differentiate between integers and doubles to allow the 41 | * parser to interpret the number without re-scanning +*/ 42 | yajl_tok_integer, 43 | yajl_tok_double, 44 | 45 | /*+ we differentiate between strings which require further processing, 46 | * and strings that do not +*/ 47 | yajl_tok_string, 48 | yajl_tok_string_with_escapes, 49 | 50 | /*+ comment tokens are not currently returned to the parser, ever +*/ 51 | yajl_tok_comment 52 | } yajl_tok; 53 | 54 | typedef struct yajl_lexer_t * yajl_lexer; 55 | 56 | yajl_lexer yajl_lex_alloc(yajl_alloc_funcs * alloc, 57 | /* bool */ int allowComments, 58 | /* bool */ int validateUTF8); 59 | void yajl_lex_free(yajl_lexer lexer); 60 | yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText, 61 | size_t jsonTextLen, size_t * offset, 62 | const unsigned char ** outBuf, size_t * outLen); 63 | yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText, 64 | size_t jsonTextLen, size_t offset); 65 | 66 | 67 | typedef enum { 68 | yajl_lex_e_ok = 0, 69 | yajl_lex_string_invalid_utf8, 70 | yajl_lex_string_invalid_escaped_char, 71 | yajl_lex_string_invalid_json_char, 72 | yajl_lex_string_invalid_hex_char, 73 | yajl_lex_invalid_char, 74 | yajl_lex_invalid_string, 75 | yajl_lex_missing_integer_after_decimal, 76 | yajl_lex_missing_integer_after_exponent, 77 | yajl_lex_missing_integer_after_minus, 78 | yajl_lex_unallowed_comment 79 | } yajl_lex_error; 80 | 81 | const char * yajl_lex_error_to_string(yajl_lex_error error); 82 | yajl_lex_error yajl_lex_get_error(yajl_lexer lexer); 83 | size_t yajl_lex_current_line(yajl_lexer lexer); 84 | size_t yajl_lex_current_char(yajl_lexer lexer); 85 | 86 | #endif