00001 #ifndef _PARSER_H_
00002 #define _PARSER_H_
00003
00004 #include "ruby.h"
00005
00006 #if HAVE_RE_H
00007 #include "re.h"
00008 #endif
00009
00010 #ifdef HAVE_RUBY_ENCODING_H
00011 #include "ruby/encoding.h"
00012 #define FORCE_UTF8(obj) ((obj) = rb_enc_associate(rb_str_dup(obj), rb_utf8_encoding()))
00013 #else
00014 #define FORCE_UTF8(obj)
00015 #endif
00016 #ifdef HAVE_RUBY_ST_H
00017 #include "ruby/st.h"
00018 #else
00019 #include "st.h"
00020 #endif
00021
00022 #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
00023
00024
00025
00026 typedef unsigned long UTF32;
00027 typedef unsigned short UTF16;
00028 typedef unsigned char UTF8;
00029
00030 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
00031 #define UNI_SUR_HIGH_START (UTF32)0xD800
00032 #define UNI_SUR_HIGH_END (UTF32)0xDBFF
00033 #define UNI_SUR_LOW_START (UTF32)0xDC00
00034 #define UNI_SUR_LOW_END (UTF32)0xDFFF
00035
00036 typedef struct JSON_ParserStruct {
00037 VALUE Vsource;
00038 char *source;
00039 long len;
00040 char *memo;
00041 VALUE create_id;
00042 int max_nesting;
00043 int current_nesting;
00044 int allow_nan;
00045 int parsing_name;
00046 int symbolize_names;
00047 int quirks_mode;
00048 VALUE object_class;
00049 VALUE array_class;
00050 int create_additions;
00051 VALUE match_string;
00052 } JSON_Parser;
00053
00054 #define GET_PARSER \
00055 GET_PARSER_INIT; \
00056 if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
00057 #define GET_PARSER_INIT \
00058 JSON_Parser *json; \
00059 Data_Get_Struct(self, JSON_Parser, json)
00060
00061 #define MinusInfinity "-Infinity"
00062 #define EVIL 0x666
00063
00064 static UTF32 unescape_unicode(const unsigned char *p);
00065 static int convert_UTF32_to_UTF8(char *buf, UTF32 ch);
00066 static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
00067 static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result);
00068 static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
00069 static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
00070 static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result);
00071 static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd);
00072 static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
00073 static VALUE convert_encoding(VALUE source);
00074 static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
00075 static VALUE cParser_parse(VALUE self);
00076 static JSON_Parser *JSON_allocate();
00077 static void JSON_mark(JSON_Parser *json);
00078 static void JSON_free(JSON_Parser *json);
00079 static VALUE cJSON_parser_s_allocate(VALUE klass);
00080 static VALUE cParser_source(VALUE self);
00081
00082 #endif
00083