fc73810dd6a8e6efb194ae20c9682f1ae0dbf4dc
[packages/precise/mcollective.git] / lib / mcollective / vendor / json / ext / json / ext / parser / parser.h
1 #ifndef _PARSER_H_
2 #define _PARSER_H_
3
4 #include "ruby.h"
5
6 #if HAVE_RE_H
7 #include "re.h"
8 #endif
9
10 #ifdef HAVE_RUBY_ENCODING_H
11 #include "ruby/encoding.h"
12 #define FORCE_UTF8(obj) ((obj) = rb_enc_associate(rb_str_dup(obj), rb_utf8_encoding()))
13 #else
14 #define FORCE_UTF8(obj)
15 #endif
16 #ifdef HAVE_RUBY_ST_H
17 #include "ruby/st.h"
18 #else
19 #include "st.h"
20 #endif
21
22 #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
23
24 /* unicode */
25
26 typedef unsigned long UTF32;  /* at least 32 bits */
27 typedef unsigned short UTF16; /* at least 16 bits */
28 typedef unsigned char UTF8;   /* typically 8 bits */
29
30 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
31 #define UNI_SUR_HIGH_START  (UTF32)0xD800
32 #define UNI_SUR_HIGH_END    (UTF32)0xDBFF
33 #define UNI_SUR_LOW_START   (UTF32)0xDC00
34 #define UNI_SUR_LOW_END     (UTF32)0xDFFF
35
36 typedef struct JSON_ParserStruct {
37     VALUE Vsource;
38     char *source;
39     long len;
40     char *memo;
41     VALUE create_id;
42     int max_nesting;
43     int current_nesting;
44     int allow_nan;
45     int parsing_name;
46     int symbolize_names;
47     int quirks_mode;
48     VALUE object_class;
49     VALUE array_class;
50     int create_additions;
51     VALUE match_string;
52 } JSON_Parser;
53
54 #define GET_PARSER                          \
55     GET_PARSER_INIT;                        \
56     if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
57 #define GET_PARSER_INIT                     \
58     JSON_Parser *json;                      \
59     Data_Get_Struct(self, JSON_Parser, json)
60
61 #define MinusInfinity "-Infinity"
62 #define EVIL 0x666
63
64 static UTF32 unescape_unicode(const unsigned char *p);
65 static int convert_UTF32_to_UTF8(char *buf, UTF32 ch);
66 static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
67 static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result);
68 static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
69 static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
70 static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result);
71 static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd);
72 static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
73 static VALUE convert_encoding(VALUE source);
74 static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
75 static VALUE cParser_parse(VALUE self);
76 static JSON_Parser *JSON_allocate();
77 static void JSON_mark(JSON_Parser *json);
78 static void JSON_free(JSON_Parser *json);
79 static VALUE cJSON_parser_s_allocate(VALUE klass);
80 static VALUE cParser_source(VALUE self);
81
82 #endif