Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
parser.h
Go to the documentation of this file.
1#ifndef _PARSER_H_
2#define _PARSER_H_
3
4#include "ruby.h"
5
6#ifndef HAVE_RUBY_RE_H
7#include "re.h"
8#endif
9
10#ifdef HAVE_RUBY_ST_H
11#include "ruby/st.h"
12#else
13#include "st.h"
14#endif
15
16#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
17
18/* unicode */
19
20typedef unsigned long UTF32; /* at least 32 bits */
21typedef unsigned short UTF16; /* at least 16 bits */
22typedef unsigned char UTF8; /* typically 8 bits */
23
24#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
25#define UNI_SUR_HIGH_START (UTF32)0xD800
26#define UNI_SUR_HIGH_END (UTF32)0xDBFF
27#define UNI_SUR_LOW_START (UTF32)0xDC00
28#define UNI_SUR_LOW_END (UTF32)0xDFFF
29
30typedef struct JSON_ParserStruct {
32 char *source;
33 long len;
34 char *memo;
40 int freeze;
48
49#define GET_PARSER \
50 GET_PARSER_INIT; \
51 if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
52#define GET_PARSER_INIT \
53 JSON_Parser *json; \
54 TypedData_Get_Struct(self, JSON_Parser, &JSON_Parser_type, json)
55
56#define MinusInfinity "-Infinity"
57#define EVIL 0x666
58
59static UTF32 unescape_unicode(const unsigned char *p);
60static int convert_UTF32_to_UTF8(char *buf, UTF32 ch);
61static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
62static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
63static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
64static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
65static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting);
66static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd);
67static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
68static VALUE convert_encoding(VALUE source);
69static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
70static VALUE cParser_parse(VALUE self);
71static void JSON_mark(void *json);
72static void JSON_free(void *json);
73static VALUE cJSON_parser_s_allocate(VALUE klass);
74static VALUE cParser_source(VALUE self);
75#ifndef ZALLOC
76#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
77static inline void *ruby_zalloc(size_t n)
78{
79 void *p = ruby_xmalloc(n);
80 memset(p, 0, n);
81 return p;
82}
83#endif
84#ifdef TypedData_Make_Struct
85static const rb_data_type_t JSON_Parser_type;
86#define NEW_TYPEDDATA_WRAPPER 1
87#else
88#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, JSON_free, json)
89#define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json)
90#endif
91
92#endif
void * ruby_xmalloc(size_t size)
Allocates a storage instance.
Definition: gc.c:12795
unsigned long UTF32
Definition: generator.h:29
voidpf void * buf
Definition: ioapi.h:138
unsigned long UTF32
Definition: parser.h:20
unsigned short UTF16
Definition: parser.h:21
struct JSON_ParserStruct JSON_Parser
unsigned char UTF8
Definition: parser.h:22
int argc
Definition: ruby.c:240
char ** argv
Definition: ruby.c:241
VALUE decimal_class
Definition: parser.h:43
VALUE create_id
Definition: parser.h:35
int parsing_name
Definition: parser.h:38
FBuffer * fbuffer
Definition: parser.h:46
int create_additions
Definition: parser.h:44
VALUE match_string
Definition: parser.h:45
char * memo
Definition: parser.h:34
char * source
Definition: parser.h:32
VALUE array_class
Definition: parser.h:42
int symbolize_names
Definition: parser.h:39
VALUE object_class
Definition: parser.h:41
VALUE Vsource
Definition: parser.h:31
unsigned long VALUE
Definition: value.h:38