candle 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/VERSION +1 -0
- data/bin/candle +21 -0
- data/lib/candle.rb +68 -0
- data/lib/candle/command.rb +27 -0
- data/lib/candle/generators/actions.rb +183 -0
- data/lib/candle/generators/blank.rb +127 -0
- data/lib/candle/generators/cli.rb +55 -0
- data/lib/candle/generators/help.rb +47 -0
- data/lib/candle/generators/jam.rb +80 -0
- data/lib/candle/generators/lua/scripts/AppDelegate.lua +36 -0
- data/lib/candle/generators/lua/scripts/tests/init.lua +6 -0
- data/lib/candle/generators/lua/scripts/tests/someTest.lua +12 -0
- data/lib/candle/generators/lua/wax/ProtocolLoader.h +12 -0
- data/lib/candle/generators/lua/wax/bin/hammer +157 -0
- data/lib/candle/generators/lua/wax/bin/update-xibs +131 -0
- data/lib/candle/generators/lua/wax/bin/waxsim +0 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/compile-stdlib.sh +14 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/copy-scripts.sh +58 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/luac.lua +80 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.m +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.m +251 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.h +14 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.m +240 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.h +54 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.m +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.h +9 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.m +273 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/Rakefile +10 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.c +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.h +11 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl-1.0.9.tar.gz +0 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl.c +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.c +65 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.c +119 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.h +73 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_bytestack.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.c +188 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.c +322 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.c +737 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.h +133 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.c +448 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.c +1087 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.h +16 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.c +652 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.h +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lbaselib.c +653 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.c +839 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.h +76 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldblib.c +397 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.c +638 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.h +33 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.c +518 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.h +57 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldump.c +164 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.c +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.h +34 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.c +711 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.h +110 -0
- data/lib/candle/generators/lua/wax/lib/lua/linit.c +38 -0
- data/lib/candle/generators/lua/wax/lib/lua/liolib.c +553 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.c +461 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.h +81 -0
- data/lib/candle/generators/lua/wax/lib/lua/llimits.h +128 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmathlib.c +263 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.c +86 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.h +49 -0
- data/lib/candle/generators/lua/wax/lib/lua/loadlib.c +666 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.h +381 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.c +102 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.h +268 -0
- data/lib/candle/generators/lua/wax/lib/lua/loslib.c +243 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.c +1339 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.h +169 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.c +111 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.h +31 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstrlib.c +869 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.c +588 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.h +40 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltablib.c +287 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.c +75 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.h +54 -0
- data/lib/candle/generators/lua/wax/lib/lua/lua.h +388 -0
- data/lib/candle/generators/lua/wax/lib/lua/luaconf.h +753 -0
- data/lib/candle/generators/lua/wax/lib/lua/lualib.h +53 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.c +227 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.c +763 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.c +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.h +67 -0
- data/lib/candle/generators/lua/wax/lib/lua/print.c +227 -0
- data/lib/candle/generators/lua/wax/lib/project.rake +159 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/enums.lua +396 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/http.lua +43 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/init.lua +4 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/number.lua +21 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/string.lua +97 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/table.lua +165 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/WaxServer.lua +49 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/autoload.lua +10 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/base64.lua +64 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/bit.lua +274 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/cache.lua +73 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/callback.lua +22 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/frame.lua +76 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/init.lua +78 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/pickView.lua +54 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/time.lua +102 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/init.lua +18 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/init.lua +2 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luamock.lua +84 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luaspec.lua +377 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/repl.lua +9 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/structs.lua +11 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/waxClass.lua +42 -0
- data/lib/candle/generators/lua/wax/lib/wax.h +16 -0
- data/lib/candle/generators/lua/wax/lib/wax.m +260 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.h +18 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.m +190 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.h +20 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.m +56 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.h +102 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.m +870 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.h +34 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.m +810 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.h +47 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.m +252 -0
- data/lib/candle/generators/lua/wax/lib/wax_stdlib.h +3 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.h +26 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.m +335 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.pbxproj +836 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/WaxApplication.xcscheme +86 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default-568h@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/ProtocolLoader.h +12 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Info.plist.tt +38 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Prefix.pch.tt +14 -0
- data/lib/candle/generators/templates/blank/WaxApplication/en.lproj/InfoPlist.strings +2 -0
- data/lib/candle/generators/templates/blank/WaxApplication/main.m.tt +20 -0
- data/lib/candle/tasks.rb +22 -0
- data/lib/candle/utility.rb +30 -0
- data/lib/candle/version.rb +9 -0
- data/lib/candle/view.rb +48 -0
- metadata +582 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are
|
6
|
+
* met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived
|
18
|
+
* from this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
24
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
28
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
#ifndef __YAJL_LEX_H__
|
34
|
+
#define __YAJL_LEX_H__
|
35
|
+
|
36
|
+
#include "api/yajl_common.h"
|
37
|
+
|
38
|
+
typedef enum {
|
39
|
+
yajl_tok_bool,
|
40
|
+
yajl_tok_colon,
|
41
|
+
yajl_tok_comma,
|
42
|
+
yajl_tok_eof,
|
43
|
+
yajl_tok_error,
|
44
|
+
yajl_tok_left_brace,
|
45
|
+
yajl_tok_left_bracket,
|
46
|
+
yajl_tok_null,
|
47
|
+
yajl_tok_right_brace,
|
48
|
+
yajl_tok_right_bracket,
|
49
|
+
|
50
|
+
/* we differentiate between integers and doubles to allow the
|
51
|
+
* parser to interpret the number without re-scanning */
|
52
|
+
yajl_tok_integer,
|
53
|
+
yajl_tok_double,
|
54
|
+
|
55
|
+
/* we differentiate between strings which require further processing,
|
56
|
+
* and strings that do not */
|
57
|
+
yajl_tok_string,
|
58
|
+
yajl_tok_string_with_escapes,
|
59
|
+
|
60
|
+
/* comment tokens are not currently returned to the parser, ever */
|
61
|
+
yajl_tok_comment
|
62
|
+
} yajl_tok;
|
63
|
+
|
64
|
+
typedef struct yajl_lexer_t * yajl_lexer;
|
65
|
+
|
66
|
+
yajl_lexer yajl_lex_alloc(yajl_alloc_funcs * alloc,
|
67
|
+
unsigned int allowComments,
|
68
|
+
unsigned int validateUTF8);
|
69
|
+
|
70
|
+
void yajl_lex_free(yajl_lexer lexer);
|
71
|
+
|
72
|
+
/**
|
73
|
+
* run/continue a lex. "offset" is an input/output parameter.
|
74
|
+
* It should be initialized to zero for a
|
75
|
+
* new chunk of target text, and upon subsetquent calls with the same
|
76
|
+
* target text should passed with the value of the previous invocation.
|
77
|
+
*
|
78
|
+
* the client may be interested in the value of offset when an error is
|
79
|
+
* returned from the lexer. This allows the client to render useful
|
80
|
+
n * error messages.
|
81
|
+
*
|
82
|
+
* When you pass the next chunk of data, context should be reinitialized
|
83
|
+
* to zero.
|
84
|
+
*
|
85
|
+
* Finally, the output buffer is usually just a pointer into the jsonText,
|
86
|
+
* however in cases where the entity being lexed spans multiple chunks,
|
87
|
+
* the lexer will buffer the entity and the data returned will be
|
88
|
+
* a pointer into that buffer.
|
89
|
+
*
|
90
|
+
* This behavior is abstracted from client code except for the performance
|
91
|
+
* implications which require that the client choose a reasonable chunk
|
92
|
+
* size to get adequate performance.
|
93
|
+
*/
|
94
|
+
yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
|
95
|
+
unsigned int jsonTextLen, unsigned int * offset,
|
96
|
+
const unsigned char ** outBuf, unsigned int * outLen);
|
97
|
+
|
98
|
+
/** have a peek at the next token, but don't move the lexer forward */
|
99
|
+
yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText,
|
100
|
+
unsigned int jsonTextLen, unsigned int offset);
|
101
|
+
|
102
|
+
|
103
|
+
typedef enum {
|
104
|
+
yajl_lex_e_ok = 0,
|
105
|
+
yajl_lex_string_invalid_utf8,
|
106
|
+
yajl_lex_string_invalid_escaped_char,
|
107
|
+
yajl_lex_string_invalid_json_char,
|
108
|
+
yajl_lex_string_invalid_hex_char,
|
109
|
+
yajl_lex_invalid_char,
|
110
|
+
yajl_lex_invalid_string,
|
111
|
+
yajl_lex_missing_integer_after_decimal,
|
112
|
+
yajl_lex_missing_integer_after_exponent,
|
113
|
+
yajl_lex_missing_integer_after_minus,
|
114
|
+
yajl_lex_unallowed_comment
|
115
|
+
} yajl_lex_error;
|
116
|
+
|
117
|
+
const char * yajl_lex_error_to_string(yajl_lex_error error);
|
118
|
+
|
119
|
+
/** allows access to more specific information about the lexical
|
120
|
+
* error when yajl_lex_lex returns yajl_tok_error. */
|
121
|
+
yajl_lex_error yajl_lex_get_error(yajl_lexer lexer);
|
122
|
+
|
123
|
+
/** get the current offset into the most recently lexed json string. */
|
124
|
+
unsigned int yajl_lex_current_offset(yajl_lexer lexer);
|
125
|
+
|
126
|
+
/** get the number of lines lexed by this lexer instance */
|
127
|
+
unsigned int yajl_lex_current_line(yajl_lexer lexer);
|
128
|
+
|
129
|
+
/** get the number of chars lexed by this lexer instance since the last
|
130
|
+
* \n or \r */
|
131
|
+
unsigned int yajl_lex_current_char(yajl_lexer lexer);
|
132
|
+
|
133
|
+
#endif
|
@@ -0,0 +1,193 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are
|
6
|
+
* met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived
|
18
|
+
* from this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
24
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
28
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
/**
|
34
|
+
* \file yajl_parse.h
|
35
|
+
* Interface to YAJL's JSON parsing facilities.
|
36
|
+
*/
|
37
|
+
|
38
|
+
#include "yajl_common.h"
|
39
|
+
|
40
|
+
#ifndef __YAJL_PARSE_H__
|
41
|
+
#define __YAJL_PARSE_H__
|
42
|
+
|
43
|
+
#ifdef __cplusplus
|
44
|
+
extern "C" {
|
45
|
+
#endif
|
46
|
+
/** error codes returned from this interface */
|
47
|
+
typedef enum {
|
48
|
+
/** no error was encountered */
|
49
|
+
yajl_status_ok,
|
50
|
+
/** a client callback returned zero, stopping the parse */
|
51
|
+
yajl_status_client_canceled,
|
52
|
+
/** The parse cannot yet complete because more json input text
|
53
|
+
* is required, call yajl_parse with the next buffer of input text.
|
54
|
+
* (pertinent only when stream parsing) */
|
55
|
+
yajl_status_insufficient_data,
|
56
|
+
/** An error occured during the parse. Call yajl_get_error for
|
57
|
+
* more information about the encountered error */
|
58
|
+
yajl_status_error
|
59
|
+
} yajl_status;
|
60
|
+
|
61
|
+
/** attain a human readable, english, string for an error */
|
62
|
+
YAJL_API const char * yajl_status_to_string(yajl_status code);
|
63
|
+
|
64
|
+
/** an opaque handle to a parser */
|
65
|
+
typedef struct yajl_handle_t * yajl_handle;
|
66
|
+
|
67
|
+
/** yajl is an event driven parser. this means as json elements are
|
68
|
+
* parsed, you are called back to do something with the data. The
|
69
|
+
* functions in this table indicate the various events for which
|
70
|
+
* you will be called back. Each callback accepts a "context"
|
71
|
+
* pointer, this is a void * that is passed into the yajl_parse
|
72
|
+
* function which the client code may use to pass around context.
|
73
|
+
*
|
74
|
+
* All callbacks return an integer. If non-zero, the parse will
|
75
|
+
* continue. If zero, the parse will be canceled and
|
76
|
+
* yajl_status_client_canceled will be returned from the parse.
|
77
|
+
*
|
78
|
+
* Note about handling of numbers:
|
79
|
+
* yajl will only convert numbers that can be represented in a double
|
80
|
+
* or a long int. All other numbers will be passed to the client
|
81
|
+
* in string form using the yajl_number callback. Furthermore, if
|
82
|
+
* yajl_number is not NULL, it will always be used to return numbers,
|
83
|
+
* that is yajl_integer and yajl_double will be ignored. If
|
84
|
+
* yajl_number is NULL but one of yajl_integer or yajl_double are
|
85
|
+
* defined, parsing of a number larger than is representable
|
86
|
+
* in a double or long int will result in a parse error.
|
87
|
+
*/
|
88
|
+
typedef struct {
|
89
|
+
int (* yajl_null)(void * ctx);
|
90
|
+
int (* yajl_boolean)(void * ctx, int boolVal);
|
91
|
+
int (* yajl_integer)(void * ctx, long integerVal);
|
92
|
+
int (* yajl_double)(void * ctx, double doubleVal);
|
93
|
+
/** A callback which passes the string representation of the number
|
94
|
+
* back to the client. Will be used for all numbers when present */
|
95
|
+
int (* yajl_number)(void * ctx, const char * numberVal,
|
96
|
+
unsigned int numberLen);
|
97
|
+
|
98
|
+
/** strings are returned as pointers into the JSON text when,
|
99
|
+
* possible, as a result, they are _not_ null padded */
|
100
|
+
int (* yajl_string)(void * ctx, const unsigned char * stringVal,
|
101
|
+
unsigned int stringLen);
|
102
|
+
|
103
|
+
int (* yajl_start_map)(void * ctx);
|
104
|
+
int (* yajl_map_key)(void * ctx, const unsigned char * key,
|
105
|
+
unsigned int stringLen);
|
106
|
+
int (* yajl_end_map)(void * ctx);
|
107
|
+
|
108
|
+
int (* yajl_start_array)(void * ctx);
|
109
|
+
int (* yajl_end_array)(void * ctx);
|
110
|
+
} yajl_callbacks;
|
111
|
+
|
112
|
+
/** configuration structure for the generator */
|
113
|
+
typedef struct {
|
114
|
+
/** if nonzero, javascript style comments will be allowed in
|
115
|
+
* the json input, both slash star and slash slash */
|
116
|
+
unsigned int allowComments;
|
117
|
+
/** if nonzero, invalid UTF8 strings will cause a parse
|
118
|
+
* error */
|
119
|
+
unsigned int checkUTF8;
|
120
|
+
} yajl_parser_config;
|
121
|
+
|
122
|
+
/** allocate a parser handle
|
123
|
+
* \param callbacks a yajl callbacks structure specifying the
|
124
|
+
* functions to call when different JSON entities
|
125
|
+
* are encountered in the input text. May be NULL,
|
126
|
+
* which is only useful for validation.
|
127
|
+
* \param config configuration parameters for the parse.
|
128
|
+
* \param ctx a context pointer that will be passed to callbacks.
|
129
|
+
*/
|
130
|
+
YAJL_API yajl_handle yajl_alloc(const yajl_callbacks * callbacks,
|
131
|
+
const yajl_parser_config * config,
|
132
|
+
const yajl_alloc_funcs * allocFuncs,
|
133
|
+
void * ctx);
|
134
|
+
|
135
|
+
/** free a parser handle */
|
136
|
+
YAJL_API void yajl_free(yajl_handle handle);
|
137
|
+
|
138
|
+
/** Parse some json!
|
139
|
+
* \param hand - a handle to the json parser allocated with yajl_alloc
|
140
|
+
* \param jsonText - a pointer to the UTF8 json text to be parsed
|
141
|
+
* \param jsonTextLength - the length, in bytes, of input text
|
142
|
+
*/
|
143
|
+
YAJL_API yajl_status yajl_parse(yajl_handle hand,
|
144
|
+
const unsigned char * jsonText,
|
145
|
+
unsigned int jsonTextLength);
|
146
|
+
|
147
|
+
/** Parse any remaining buffered json.
|
148
|
+
* Since yajl is a stream-based parser, without an explicit end of
|
149
|
+
* input, yajl sometimes can't decide if content at the end of the
|
150
|
+
* stream is valid or not. For example, if "1" has been fed in,
|
151
|
+
* yajl can't know whether another digit is next or some character
|
152
|
+
* that would terminate the integer token.
|
153
|
+
*
|
154
|
+
* \param hand - a handle to the json parser allocated with yajl_alloc
|
155
|
+
*/
|
156
|
+
YAJL_API yajl_status yajl_parse_complete(yajl_handle hand);
|
157
|
+
|
158
|
+
/** get an error string describing the state of the
|
159
|
+
* parse.
|
160
|
+
*
|
161
|
+
* If verbose is non-zero, the message will include the JSON
|
162
|
+
* text where the error occured, along with an arrow pointing to
|
163
|
+
* the specific char.
|
164
|
+
*
|
165
|
+
* \returns A dynamically allocated string will be returned which should
|
166
|
+
* be freed with yajl_free_error
|
167
|
+
*/
|
168
|
+
YAJL_API unsigned char * yajl_get_error(yajl_handle hand, int verbose,
|
169
|
+
const unsigned char * jsonText,
|
170
|
+
unsigned int jsonTextLength);
|
171
|
+
|
172
|
+
/**
|
173
|
+
* get the amount of data consumed from the last chunk passed to YAJL.
|
174
|
+
*
|
175
|
+
* In the case of a successful parse this can help you understand if
|
176
|
+
* the entire buffer was consumed (which will allow you to handle
|
177
|
+
* "junk at end of input".
|
178
|
+
*
|
179
|
+
* In the event an error is encountered during parsing, this function
|
180
|
+
* affords the client a way to get the offset into the most recent
|
181
|
+
* chunk where the error occured. 0 will be returned if no error
|
182
|
+
* was encountered.
|
183
|
+
*/
|
184
|
+
YAJL_API unsigned int yajl_get_bytes_consumed(yajl_handle hand);
|
185
|
+
|
186
|
+
/** free an error returned from yajl_get_error */
|
187
|
+
YAJL_API void yajl_free_error(yajl_handle hand, unsigned char * str);
|
188
|
+
|
189
|
+
#ifdef __cplusplus
|
190
|
+
}
|
191
|
+
#endif
|
192
|
+
|
193
|
+
#endif
|
@@ -0,0 +1,448 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are
|
6
|
+
* met:
|
7
|
+
*
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
*
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in
|
13
|
+
* the documentation and/or other materials provided with the
|
14
|
+
* distribution.
|
15
|
+
*
|
16
|
+
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived
|
18
|
+
* from this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
24
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
28
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
#include "yajl_lex.h"
|
34
|
+
#include "yajl_parser.h"
|
35
|
+
#include "yajl_encode.h"
|
36
|
+
#include "yajl_bytestack.h"
|
37
|
+
|
38
|
+
#include <stdlib.h>
|
39
|
+
#include <limits.h>
|
40
|
+
#include <errno.h>
|
41
|
+
#include <stdio.h>
|
42
|
+
#include <string.h>
|
43
|
+
#include <ctype.h>
|
44
|
+
#include <assert.h>
|
45
|
+
#include <math.h>
|
46
|
+
|
47
|
+
unsigned char *
|
48
|
+
yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
|
49
|
+
unsigned int jsonTextLen, int verbose)
|
50
|
+
{
|
51
|
+
unsigned int offset = hand->bytesConsumed;
|
52
|
+
unsigned char * str;
|
53
|
+
const char * errorType = NULL;
|
54
|
+
const char * errorText = NULL;
|
55
|
+
char text[72];
|
56
|
+
const char * arrow = " (right here) ------^\n";
|
57
|
+
|
58
|
+
if (yajl_bs_current(hand->stateStack) == yajl_state_parse_error) {
|
59
|
+
errorType = "parse";
|
60
|
+
errorText = hand->parseError;
|
61
|
+
} else if (yajl_bs_current(hand->stateStack) == yajl_state_lexical_error) {
|
62
|
+
errorType = "lexical";
|
63
|
+
errorText = yajl_lex_error_to_string(yajl_lex_get_error(hand->lexer));
|
64
|
+
} else {
|
65
|
+
errorType = "unknown";
|
66
|
+
}
|
67
|
+
|
68
|
+
{
|
69
|
+
unsigned int memneeded = 0;
|
70
|
+
memneeded += strlen(errorType);
|
71
|
+
memneeded += strlen(" error");
|
72
|
+
if (errorText != NULL) {
|
73
|
+
memneeded += strlen(": ");
|
74
|
+
memneeded += strlen(errorText);
|
75
|
+
}
|
76
|
+
str = (unsigned char *) YA_MALLOC(&(hand->alloc), memneeded + 2);
|
77
|
+
str[0] = 0;
|
78
|
+
strcat((char *) str, errorType);
|
79
|
+
strcat((char *) str, " error");
|
80
|
+
if (errorText != NULL) {
|
81
|
+
strcat((char *) str, ": ");
|
82
|
+
strcat((char *) str, errorText);
|
83
|
+
}
|
84
|
+
strcat((char *) str, "\n");
|
85
|
+
}
|
86
|
+
|
87
|
+
/* now we append as many spaces as needed to make sure the error
|
88
|
+
* falls at char 41, if verbose was specified */
|
89
|
+
if (verbose) {
|
90
|
+
unsigned int start, end, i;
|
91
|
+
unsigned int spacesNeeded;
|
92
|
+
|
93
|
+
spacesNeeded = (offset < 30 ? 40 - offset : 10);
|
94
|
+
start = (offset >= 30 ? offset - 30 : 0);
|
95
|
+
end = (offset + 30 > jsonTextLen ? jsonTextLen : offset + 30);
|
96
|
+
|
97
|
+
for (i=0;i<spacesNeeded;i++) text[i] = ' ';
|
98
|
+
|
99
|
+
for (;start < end;start++, i++) {
|
100
|
+
if (jsonText[start] != '\n' && jsonText[start] != '\r')
|
101
|
+
{
|
102
|
+
text[i] = jsonText[start];
|
103
|
+
}
|
104
|
+
else
|
105
|
+
{
|
106
|
+
text[i] = ' ';
|
107
|
+
}
|
108
|
+
}
|
109
|
+
assert(i <= 71);
|
110
|
+
text[i++] = '\n';
|
111
|
+
text[i] = 0;
|
112
|
+
{
|
113
|
+
char * newStr = (char *)
|
114
|
+
YA_MALLOC(&(hand->alloc), (strlen((char *) str) +
|
115
|
+
strlen((char *) text) +
|
116
|
+
strlen(arrow) + 1));
|
117
|
+
newStr[0] = 0;
|
118
|
+
strcat((char *) newStr, (char *) str);
|
119
|
+
strcat((char *) newStr, text);
|
120
|
+
strcat((char *) newStr, arrow);
|
121
|
+
YA_FREE(&(hand->alloc), str);
|
122
|
+
str = (unsigned char *) newStr;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return str;
|
126
|
+
}
|
127
|
+
|
128
|
+
/* check for client cancelation */
|
129
|
+
#define _CC_CHK(x) \
|
130
|
+
if (!(x)) { \
|
131
|
+
yajl_bs_set(hand->stateStack, yajl_state_parse_error); \
|
132
|
+
hand->parseError = \
|
133
|
+
"client cancelled parse via callback return value"; \
|
134
|
+
return yajl_status_client_canceled; \
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
yajl_status
|
139
|
+
yajl_do_parse(yajl_handle hand, const unsigned char * jsonText,
|
140
|
+
unsigned int jsonTextLen)
|
141
|
+
{
|
142
|
+
yajl_tok tok;
|
143
|
+
const unsigned char * buf;
|
144
|
+
unsigned int bufLen;
|
145
|
+
unsigned int * offset = &(hand->bytesConsumed);
|
146
|
+
|
147
|
+
*offset = 0;
|
148
|
+
|
149
|
+
|
150
|
+
around_again:
|
151
|
+
switch (yajl_bs_current(hand->stateStack)) {
|
152
|
+
case yajl_state_parse_complete:
|
153
|
+
return yajl_status_ok;
|
154
|
+
case yajl_state_lexical_error:
|
155
|
+
case yajl_state_parse_error:
|
156
|
+
return yajl_status_error;
|
157
|
+
case yajl_state_start:
|
158
|
+
case yajl_state_map_need_val:
|
159
|
+
case yajl_state_array_need_val:
|
160
|
+
case yajl_state_array_start: {
|
161
|
+
/* for arrays and maps, we advance the state for this
|
162
|
+
* depth, then push the state of the next depth.
|
163
|
+
* If an error occurs during the parsing of the nesting
|
164
|
+
* enitity, the state at this level will not matter.
|
165
|
+
* a state that needs pushing will be anything other
|
166
|
+
* than state_start */
|
167
|
+
yajl_state stateToPush = yajl_state_start;
|
168
|
+
|
169
|
+
tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
|
170
|
+
offset, &buf, &bufLen);
|
171
|
+
|
172
|
+
switch (tok) {
|
173
|
+
case yajl_tok_eof:
|
174
|
+
return yajl_status_insufficient_data;
|
175
|
+
case yajl_tok_error:
|
176
|
+
yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
|
177
|
+
goto around_again;
|
178
|
+
case yajl_tok_string:
|
179
|
+
if (hand->callbacks && hand->callbacks->yajl_string) {
|
180
|
+
_CC_CHK(hand->callbacks->yajl_string(hand->ctx,
|
181
|
+
buf, bufLen));
|
182
|
+
}
|
183
|
+
break;
|
184
|
+
case yajl_tok_string_with_escapes:
|
185
|
+
if (hand->callbacks && hand->callbacks->yajl_string) {
|
186
|
+
yajl_buf_clear(hand->decodeBuf);
|
187
|
+
yajl_string_decode(hand->decodeBuf, buf, bufLen);
|
188
|
+
_CC_CHK(hand->callbacks->yajl_string(
|
189
|
+
hand->ctx, yajl_buf_data(hand->decodeBuf),
|
190
|
+
yajl_buf_len(hand->decodeBuf)));
|
191
|
+
}
|
192
|
+
break;
|
193
|
+
case yajl_tok_bool:
|
194
|
+
if (hand->callbacks && hand->callbacks->yajl_boolean) {
|
195
|
+
_CC_CHK(hand->callbacks->yajl_boolean(hand->ctx,
|
196
|
+
*buf == 't'));
|
197
|
+
}
|
198
|
+
break;
|
199
|
+
case yajl_tok_null:
|
200
|
+
if (hand->callbacks && hand->callbacks->yajl_null) {
|
201
|
+
_CC_CHK(hand->callbacks->yajl_null(hand->ctx));
|
202
|
+
}
|
203
|
+
break;
|
204
|
+
case yajl_tok_left_bracket:
|
205
|
+
if (hand->callbacks && hand->callbacks->yajl_start_map) {
|
206
|
+
_CC_CHK(hand->callbacks->yajl_start_map(hand->ctx));
|
207
|
+
}
|
208
|
+
stateToPush = yajl_state_map_start;
|
209
|
+
break;
|
210
|
+
case yajl_tok_left_brace:
|
211
|
+
if (hand->callbacks && hand->callbacks->yajl_start_array) {
|
212
|
+
_CC_CHK(hand->callbacks->yajl_start_array(hand->ctx));
|
213
|
+
}
|
214
|
+
stateToPush = yajl_state_array_start;
|
215
|
+
break;
|
216
|
+
case yajl_tok_integer:
|
217
|
+
/*
|
218
|
+
* note. strtol does not respect the length of
|
219
|
+
* the lexical token. in a corner case where the
|
220
|
+
* lexed number is a integer with a trailing zero,
|
221
|
+
* immediately followed by the end of buffer,
|
222
|
+
* sscanf could run off into oblivion and cause a
|
223
|
+
* crash. for this reason we copy the integer
|
224
|
+
* (and doubles), into our parse buffer (the same
|
225
|
+
* one used for unescaping strings), before
|
226
|
+
* calling strtol. yajl_buf ensures null padding,
|
227
|
+
* so we're safe.
|
228
|
+
*/
|
229
|
+
if (hand->callbacks) {
|
230
|
+
if (hand->callbacks->yajl_number) {
|
231
|
+
_CC_CHK(hand->callbacks->yajl_number(
|
232
|
+
hand->ctx,(const char *) buf, bufLen));
|
233
|
+
} else if (hand->callbacks->yajl_integer) {
|
234
|
+
long int i = 0;
|
235
|
+
yajl_buf_clear(hand->decodeBuf);
|
236
|
+
yajl_buf_append(hand->decodeBuf, buf, bufLen);
|
237
|
+
buf = yajl_buf_data(hand->decodeBuf);
|
238
|
+
i = strtol((const char *) buf, NULL, 10);
|
239
|
+
if ((i == LONG_MIN || i == LONG_MAX) &&
|
240
|
+
errno == ERANGE)
|
241
|
+
{
|
242
|
+
yajl_bs_set(hand->stateStack,
|
243
|
+
yajl_state_parse_error);
|
244
|
+
hand->parseError = "integer overflow" ;
|
245
|
+
/* try to restore error offset */
|
246
|
+
if (*offset >= bufLen) *offset -= bufLen;
|
247
|
+
else *offset = 0;
|
248
|
+
goto around_again;
|
249
|
+
}
|
250
|
+
_CC_CHK(hand->callbacks->yajl_integer(hand->ctx,
|
251
|
+
i));
|
252
|
+
}
|
253
|
+
}
|
254
|
+
break;
|
255
|
+
case yajl_tok_double:
|
256
|
+
if (hand->callbacks) {
|
257
|
+
if (hand->callbacks->yajl_number) {
|
258
|
+
_CC_CHK(hand->callbacks->yajl_number(
|
259
|
+
hand->ctx, (const char *) buf, bufLen));
|
260
|
+
} else if (hand->callbacks->yajl_double) {
|
261
|
+
double d = 0.0;
|
262
|
+
yajl_buf_clear(hand->decodeBuf);
|
263
|
+
yajl_buf_append(hand->decodeBuf, buf, bufLen);
|
264
|
+
buf = yajl_buf_data(hand->decodeBuf);
|
265
|
+
d = strtod((char *) buf, NULL);
|
266
|
+
if ((d == HUGE_VAL || d == -HUGE_VAL) &&
|
267
|
+
errno == ERANGE)
|
268
|
+
{
|
269
|
+
yajl_bs_set(hand->stateStack,
|
270
|
+
yajl_state_parse_error);
|
271
|
+
hand->parseError = "numeric (floating point) "
|
272
|
+
"overflow";
|
273
|
+
/* try to restore error offset */
|
274
|
+
if (*offset >= bufLen) *offset -= bufLen;
|
275
|
+
else *offset = 0;
|
276
|
+
goto around_again;
|
277
|
+
}
|
278
|
+
_CC_CHK(hand->callbacks->yajl_double(hand->ctx,
|
279
|
+
d));
|
280
|
+
}
|
281
|
+
}
|
282
|
+
break;
|
283
|
+
case yajl_tok_right_brace: {
|
284
|
+
if (yajl_bs_current(hand->stateStack) ==
|
285
|
+
yajl_state_array_start)
|
286
|
+
{
|
287
|
+
if (hand->callbacks &&
|
288
|
+
hand->callbacks->yajl_end_array)
|
289
|
+
{
|
290
|
+
_CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
|
291
|
+
}
|
292
|
+
yajl_bs_pop(hand->stateStack);
|
293
|
+
goto around_again;
|
294
|
+
}
|
295
|
+
/* intentional fall-through */
|
296
|
+
}
|
297
|
+
case yajl_tok_colon:
|
298
|
+
case yajl_tok_comma:
|
299
|
+
case yajl_tok_right_bracket:
|
300
|
+
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
|
301
|
+
hand->parseError =
|
302
|
+
"unallowed token at this point in JSON text";
|
303
|
+
goto around_again;
|
304
|
+
default:
|
305
|
+
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
|
306
|
+
hand->parseError = "invalid token, internal error";
|
307
|
+
goto around_again;
|
308
|
+
}
|
309
|
+
/* got a value. transition depends on the state we're in. */
|
310
|
+
{
|
311
|
+
yajl_state s = yajl_bs_current(hand->stateStack);
|
312
|
+
if (s == yajl_state_start) {
|
313
|
+
yajl_bs_set(hand->stateStack, yajl_state_parse_complete);
|
314
|
+
} else if (s == yajl_state_map_need_val) {
|
315
|
+
yajl_bs_set(hand->stateStack, yajl_state_map_got_val);
|
316
|
+
} else {
|
317
|
+
yajl_bs_set(hand->stateStack, yajl_state_array_got_val);
|
318
|
+
}
|
319
|
+
}
|
320
|
+
if (stateToPush != yajl_state_start) {
|
321
|
+
yajl_bs_push(hand->stateStack, stateToPush);
|
322
|
+
}
|
323
|
+
|
324
|
+
goto around_again;
|
325
|
+
}
|
326
|
+
case yajl_state_map_start:
|
327
|
+
case yajl_state_map_need_key: {
|
328
|
+
/* only difference between these two states is that in
|
329
|
+
* start '}' is valid, whereas in need_key, we've parsed
|
330
|
+
* a comma, and a string key _must_ follow */
|
331
|
+
tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
|
332
|
+
offset, &buf, &bufLen);
|
333
|
+
switch (tok) {
|
334
|
+
case yajl_tok_eof:
|
335
|
+
return yajl_status_insufficient_data;
|
336
|
+
case yajl_tok_error:
|
337
|
+
yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
|
338
|
+
goto around_again;
|
339
|
+
case yajl_tok_string_with_escapes:
|
340
|
+
if (hand->callbacks && hand->callbacks->yajl_map_key) {
|
341
|
+
yajl_buf_clear(hand->decodeBuf);
|
342
|
+
yajl_string_decode(hand->decodeBuf, buf, bufLen);
|
343
|
+
buf = yajl_buf_data(hand->decodeBuf);
|
344
|
+
bufLen = yajl_buf_len(hand->decodeBuf);
|
345
|
+
}
|
346
|
+
/* intentional fall-through */
|
347
|
+
case yajl_tok_string:
|
348
|
+
if (hand->callbacks && hand->callbacks->yajl_map_key) {
|
349
|
+
_CC_CHK(hand->callbacks->yajl_map_key(hand->ctx, buf,
|
350
|
+
bufLen));
|
351
|
+
}
|
352
|
+
yajl_bs_set(hand->stateStack, yajl_state_map_sep);
|
353
|
+
goto around_again;
|
354
|
+
case yajl_tok_right_bracket:
|
355
|
+
if (yajl_bs_current(hand->stateStack) ==
|
356
|
+
yajl_state_map_start)
|
357
|
+
{
|
358
|
+
if (hand->callbacks && hand->callbacks->yajl_end_map) {
|
359
|
+
_CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
|
360
|
+
}
|
361
|
+
yajl_bs_pop(hand->stateStack);
|
362
|
+
goto around_again;
|
363
|
+
}
|
364
|
+
default:
|
365
|
+
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
|
366
|
+
hand->parseError =
|
367
|
+
"invalid object key (must be a string)";
|
368
|
+
goto around_again;
|
369
|
+
}
|
370
|
+
}
|
371
|
+
case yajl_state_map_sep: {
|
372
|
+
tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
|
373
|
+
offset, &buf, &bufLen);
|
374
|
+
switch (tok) {
|
375
|
+
case yajl_tok_colon:
|
376
|
+
yajl_bs_set(hand->stateStack, yajl_state_map_need_val);
|
377
|
+
goto around_again;
|
378
|
+
case yajl_tok_eof:
|
379
|
+
return yajl_status_insufficient_data;
|
380
|
+
case yajl_tok_error:
|
381
|
+
yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
|
382
|
+
goto around_again;
|
383
|
+
default:
|
384
|
+
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
|
385
|
+
hand->parseError = "object key and value must "
|
386
|
+
"be separated by a colon (':')";
|
387
|
+
goto around_again;
|
388
|
+
}
|
389
|
+
}
|
390
|
+
case yajl_state_map_got_val: {
|
391
|
+
tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
|
392
|
+
offset, &buf, &bufLen);
|
393
|
+
switch (tok) {
|
394
|
+
case yajl_tok_right_bracket:
|
395
|
+
if (hand->callbacks && hand->callbacks->yajl_end_map) {
|
396
|
+
_CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
|
397
|
+
}
|
398
|
+
yajl_bs_pop(hand->stateStack);
|
399
|
+
goto around_again;
|
400
|
+
case yajl_tok_comma:
|
401
|
+
yajl_bs_set(hand->stateStack, yajl_state_map_need_key);
|
402
|
+
goto around_again;
|
403
|
+
case yajl_tok_eof:
|
404
|
+
return yajl_status_insufficient_data;
|
405
|
+
case yajl_tok_error:
|
406
|
+
yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
|
407
|
+
goto around_again;
|
408
|
+
default:
|
409
|
+
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
|
410
|
+
hand->parseError = "after key and value, inside map, "
|
411
|
+
"I expect ',' or '}'";
|
412
|
+
/* try to restore error offset */
|
413
|
+
if (*offset >= bufLen) *offset -= bufLen;
|
414
|
+
else *offset = 0;
|
415
|
+
goto around_again;
|
416
|
+
}
|
417
|
+
}
|
418
|
+
case yajl_state_array_got_val: {
|
419
|
+
tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
|
420
|
+
offset, &buf, &bufLen);
|
421
|
+
switch (tok) {
|
422
|
+
case yajl_tok_right_brace:
|
423
|
+
if (hand->callbacks && hand->callbacks->yajl_end_array) {
|
424
|
+
_CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
|
425
|
+
}
|
426
|
+
yajl_bs_pop(hand->stateStack);
|
427
|
+
goto around_again;
|
428
|
+
case yajl_tok_comma:
|
429
|
+
yajl_bs_set(hand->stateStack, yajl_state_array_need_val);
|
430
|
+
goto around_again;
|
431
|
+
case yajl_tok_eof:
|
432
|
+
return yajl_status_insufficient_data;
|
433
|
+
case yajl_tok_error:
|
434
|
+
yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
|
435
|
+
goto around_again;
|
436
|
+
default:
|
437
|
+
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
|
438
|
+
hand->parseError =
|
439
|
+
"after array element, I expect ',' or ']'";
|
440
|
+
goto around_again;
|
441
|
+
}
|
442
|
+
}
|
443
|
+
}
|
444
|
+
|
445
|
+
abort();
|
446
|
+
return yajl_status_error;
|
447
|
+
}
|
448
|
+
|