psych 2.0.14-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +18 -0
- data/.gemtest +0 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.rdoc +576 -0
- data/Manifest.txt +114 -0
- data/README.rdoc +71 -0
- data/Rakefile +123 -0
- data/ext/psych/depend +3 -0
- data/ext/psych/extconf.rb +38 -0
- data/ext/psych/psych.c +34 -0
- data/ext/psych/psych.h +20 -0
- data/ext/psych/psych_emitter.c +555 -0
- data/ext/psych/psych_emitter.h +8 -0
- data/ext/psych/psych_parser.c +597 -0
- data/ext/psych/psych_parser.h +6 -0
- data/ext/psych/psych_to_ruby.c +43 -0
- data/ext/psych/psych_to_ruby.h +8 -0
- data/ext/psych/psych_yaml_tree.c +24 -0
- data/ext/psych/psych_yaml_tree.h +8 -0
- data/ext/psych/yaml/LICENSE +19 -0
- data/ext/psych/yaml/api.c +1415 -0
- data/ext/psych/yaml/config.h +10 -0
- data/ext/psych/yaml/dumper.c +394 -0
- data/ext/psych/yaml/emitter.c +2329 -0
- data/ext/psych/yaml/loader.c +459 -0
- data/ext/psych/yaml/parser.c +1370 -0
- data/ext/psych/yaml/reader.c +469 -0
- data/ext/psych/yaml/scanner.c +3576 -0
- data/ext/psych/yaml/writer.c +141 -0
- data/ext/psych/yaml/yaml.h +1971 -0
- data/ext/psych/yaml/yaml_private.h +664 -0
- data/lib/psych.jar +0 -0
- data/lib/psych.rb +504 -0
- data/lib/psych/class_loader.rb +101 -0
- data/lib/psych/coder.rb +94 -0
- data/lib/psych/core_ext.rb +35 -0
- data/lib/psych/deprecated.rb +85 -0
- data/lib/psych/exception.rb +13 -0
- data/lib/psych/handler.rb +249 -0
- data/lib/psych/handlers/document_stream.rb +22 -0
- data/lib/psych/handlers/recorder.rb +39 -0
- data/lib/psych/json/ruby_events.rb +19 -0
- data/lib/psych/json/stream.rb +16 -0
- data/lib/psych/json/tree_builder.rb +12 -0
- data/lib/psych/json/yaml_events.rb +29 -0
- data/lib/psych/nodes.rb +77 -0
- data/lib/psych/nodes/alias.rb +18 -0
- data/lib/psych/nodes/document.rb +60 -0
- data/lib/psych/nodes/mapping.rb +56 -0
- data/lib/psych/nodes/node.rb +55 -0
- data/lib/psych/nodes/scalar.rb +67 -0
- data/lib/psych/nodes/sequence.rb +81 -0
- data/lib/psych/nodes/stream.rb +37 -0
- data/lib/psych/omap.rb +4 -0
- data/lib/psych/parser.rb +51 -0
- data/lib/psych/scalar_scanner.rb +149 -0
- data/lib/psych/set.rb +4 -0
- data/lib/psych/stream.rb +37 -0
- data/lib/psych/streaming.rb +27 -0
- data/lib/psych/syntax_error.rb +21 -0
- data/lib/psych/tree_builder.rb +96 -0
- data/lib/psych/versions.rb +3 -0
- data/lib/psych/visitors.rb +6 -0
- data/lib/psych/visitors/depth_first.rb +26 -0
- data/lib/psych/visitors/emitter.rb +51 -0
- data/lib/psych/visitors/json_tree.rb +24 -0
- data/lib/psych/visitors/to_ruby.rb +404 -0
- data/lib/psych/visitors/visitor.rb +19 -0
- data/lib/psych/visitors/yaml_tree.rb +605 -0
- data/lib/psych/y.rb +9 -0
- data/lib/psych_jars.rb +5 -0
- data/test/psych/handlers/test_recorder.rb +25 -0
- data/test/psych/helper.rb +121 -0
- data/test/psych/json/test_stream.rb +109 -0
- data/test/psych/nodes/test_enumerable.rb +43 -0
- data/test/psych/test_alias_and_anchor.rb +96 -0
- data/test/psych/test_array.rb +57 -0
- data/test/psych/test_boolean.rb +36 -0
- data/test/psych/test_class.rb +36 -0
- data/test/psych/test_coder.rb +206 -0
- data/test/psych/test_date_time.rb +38 -0
- data/test/psych/test_deprecated.rb +214 -0
- data/test/psych/test_document.rb +46 -0
- data/test/psych/test_emitter.rb +93 -0
- data/test/psych/test_encoding.rb +259 -0
- data/test/psych/test_exception.rb +157 -0
- data/test/psych/test_hash.rb +94 -0
- data/test/psych/test_json_tree.rb +65 -0
- data/test/psych/test_merge_keys.rb +180 -0
- data/test/psych/test_nil.rb +18 -0
- data/test/psych/test_null.rb +19 -0
- data/test/psych/test_numeric.rb +45 -0
- data/test/psych/test_object.rb +44 -0
- data/test/psych/test_object_references.rb +71 -0
- data/test/psych/test_omap.rb +75 -0
- data/test/psych/test_parser.rb +339 -0
- data/test/psych/test_psych.rb +168 -0
- data/test/psych/test_safe_load.rb +97 -0
- data/test/psych/test_scalar.rb +11 -0
- data/test/psych/test_scalar_scanner.rb +106 -0
- data/test/psych/test_serialize_subclasses.rb +38 -0
- data/test/psych/test_set.rb +49 -0
- data/test/psych/test_stream.rb +93 -0
- data/test/psych/test_string.rb +226 -0
- data/test/psych/test_struct.rb +49 -0
- data/test/psych/test_symbol.rb +25 -0
- data/test/psych/test_tainted.rb +130 -0
- data/test/psych/test_to_yaml_properties.rb +63 -0
- data/test/psych/test_tree_builder.rb +79 -0
- data/test/psych/test_yaml.rb +1292 -0
- data/test/psych/test_yamldbm.rb +193 -0
- data/test/psych/test_yamlstore.rb +85 -0
- data/test/psych/visitors/test_depth_first.rb +49 -0
- data/test/psych/visitors/test_emitter.rb +144 -0
- data/test/psych/visitors/test_to_ruby.rb +333 -0
- data/test/psych/visitors/test_yaml_tree.rb +173 -0
- metadata +240 -0
@@ -0,0 +1,664 @@
|
|
1
|
+
#ifdef RUBY_EXTCONF_H
|
2
|
+
#include RUBY_EXTCONF_H
|
3
|
+
#endif
|
4
|
+
|
5
|
+
#if HAVE_CONFIG_H
|
6
|
+
#include <config.h>
|
7
|
+
#endif
|
8
|
+
|
9
|
+
#include <yaml.h>
|
10
|
+
|
11
|
+
#include <assert.h>
|
12
|
+
#include <limits.h>
|
13
|
+
#include <stddef.h>
|
14
|
+
|
15
|
+
#ifndef _MSC_VER
|
16
|
+
#include <stdint.h>
|
17
|
+
#else
|
18
|
+
#ifdef _WIN64
|
19
|
+
#define PTRDIFF_MAX _I64_MAX
|
20
|
+
#else
|
21
|
+
#define PTRDIFF_MAX INT_MAX
|
22
|
+
#endif
|
23
|
+
#endif
|
24
|
+
|
25
|
+
/*
|
26
|
+
* Memory management.
|
27
|
+
*/
|
28
|
+
|
29
|
+
YAML_DECLARE(void *)
|
30
|
+
yaml_malloc(size_t size);
|
31
|
+
|
32
|
+
YAML_DECLARE(void *)
|
33
|
+
yaml_realloc(void *ptr, size_t size);
|
34
|
+
|
35
|
+
YAML_DECLARE(void)
|
36
|
+
yaml_free(void *ptr);
|
37
|
+
|
38
|
+
YAML_DECLARE(yaml_char_t *)
|
39
|
+
yaml_strdup(const yaml_char_t *);
|
40
|
+
|
41
|
+
/*
|
42
|
+
* Reader: Ensure that the buffer contains at least `length` characters.
|
43
|
+
*/
|
44
|
+
|
45
|
+
YAML_DECLARE(int)
|
46
|
+
yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
|
47
|
+
|
48
|
+
/*
|
49
|
+
* Scanner: Ensure that the token stack contains at least one token ready.
|
50
|
+
*/
|
51
|
+
|
52
|
+
YAML_DECLARE(int)
|
53
|
+
yaml_parser_fetch_more_tokens(yaml_parser_t *parser);
|
54
|
+
|
55
|
+
/*
|
56
|
+
* The size of the input raw buffer.
|
57
|
+
*/
|
58
|
+
|
59
|
+
#define INPUT_RAW_BUFFER_SIZE 16384
|
60
|
+
|
61
|
+
/*
|
62
|
+
* The size of the input buffer.
|
63
|
+
*
|
64
|
+
* It should be possible to decode the whole raw buffer.
|
65
|
+
*/
|
66
|
+
|
67
|
+
#define INPUT_BUFFER_SIZE (INPUT_RAW_BUFFER_SIZE*3)
|
68
|
+
|
69
|
+
/*
|
70
|
+
* The size of the output buffer.
|
71
|
+
*/
|
72
|
+
|
73
|
+
#define OUTPUT_BUFFER_SIZE 16384
|
74
|
+
|
75
|
+
/*
|
76
|
+
* The size of the output raw buffer.
|
77
|
+
*
|
78
|
+
* It should be possible to encode the whole output buffer.
|
79
|
+
*/
|
80
|
+
|
81
|
+
#define OUTPUT_RAW_BUFFER_SIZE (OUTPUT_BUFFER_SIZE*2+2)
|
82
|
+
|
83
|
+
/*
|
84
|
+
* The size of other stacks and queues.
|
85
|
+
*/
|
86
|
+
|
87
|
+
#define INITIAL_STACK_SIZE 16
|
88
|
+
#define INITIAL_QUEUE_SIZE 16
|
89
|
+
#define INITIAL_STRING_SIZE 16
|
90
|
+
|
91
|
+
/*
|
92
|
+
* Buffer management.
|
93
|
+
*/
|
94
|
+
|
95
|
+
#define BUFFER_INIT(context,buffer,size) \
|
96
|
+
(((buffer).start = yaml_malloc(size)) ? \
|
97
|
+
((buffer).last = (buffer).pointer = (buffer).start, \
|
98
|
+
(buffer).end = (buffer).start+(size), \
|
99
|
+
1) : \
|
100
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
101
|
+
0))
|
102
|
+
|
103
|
+
#define BUFFER_DEL(context,buffer) \
|
104
|
+
(yaml_free((buffer).start), \
|
105
|
+
(buffer).start = (buffer).pointer = (buffer).end = 0)
|
106
|
+
|
107
|
+
/*
|
108
|
+
* String management.
|
109
|
+
*/
|
110
|
+
|
111
|
+
typedef struct {
|
112
|
+
yaml_char_t *start;
|
113
|
+
yaml_char_t *end;
|
114
|
+
yaml_char_t *pointer;
|
115
|
+
} yaml_string_t;
|
116
|
+
|
117
|
+
YAML_DECLARE(int)
|
118
|
+
yaml_string_extend(yaml_char_t **start,
|
119
|
+
yaml_char_t **pointer, yaml_char_t **end);
|
120
|
+
|
121
|
+
YAML_DECLARE(int)
|
122
|
+
yaml_string_join(
|
123
|
+
yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
|
124
|
+
yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end);
|
125
|
+
|
126
|
+
#define NULL_STRING { NULL, NULL, NULL }
|
127
|
+
|
128
|
+
#define STRING(string,length) { (string), (string)+(length), (string) }
|
129
|
+
|
130
|
+
#define STRING_ASSIGN(value,string,length) \
|
131
|
+
((value).start = (string), \
|
132
|
+
(value).end = (string)+(length), \
|
133
|
+
(value).pointer = (string))
|
134
|
+
|
135
|
+
#define STRING_INIT(context,string,size) \
|
136
|
+
(((string).start = yaml_malloc(size)) ? \
|
137
|
+
((string).pointer = (string).start, \
|
138
|
+
(string).end = (string).start+(size), \
|
139
|
+
memset((string).start, 0, (size)), \
|
140
|
+
1) : \
|
141
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
142
|
+
0))
|
143
|
+
|
144
|
+
#define STRING_DEL(context,string) \
|
145
|
+
(yaml_free((string).start), \
|
146
|
+
(string).start = (string).pointer = (string).end = 0)
|
147
|
+
|
148
|
+
#define STRING_EXTEND(context,string) \
|
149
|
+
((((string).pointer+5 < (string).end) \
|
150
|
+
|| yaml_string_extend(&(string).start, \
|
151
|
+
&(string).pointer, &(string).end)) ? \
|
152
|
+
1 : \
|
153
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
154
|
+
0))
|
155
|
+
|
156
|
+
#define CLEAR(context,string) \
|
157
|
+
((string).pointer = (string).start, \
|
158
|
+
memset((string).start, 0, (string).end-(string).start))
|
159
|
+
|
160
|
+
#define JOIN(context,string_a,string_b) \
|
161
|
+
((yaml_string_join(&(string_a).start, &(string_a).pointer, \
|
162
|
+
&(string_a).end, &(string_b).start, \
|
163
|
+
&(string_b).pointer, &(string_b).end)) ? \
|
164
|
+
((string_b).pointer = (string_b).start, \
|
165
|
+
1) : \
|
166
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
167
|
+
0))
|
168
|
+
|
169
|
+
/*
|
170
|
+
* String check operations.
|
171
|
+
*/
|
172
|
+
|
173
|
+
/*
|
174
|
+
* Check the octet at the specified position.
|
175
|
+
*/
|
176
|
+
|
177
|
+
#define CHECK_AT(string,octet,offset) \
|
178
|
+
((string).pointer[offset] == (yaml_char_t)(octet))
|
179
|
+
|
180
|
+
/*
|
181
|
+
* Check the current octet in the buffer.
|
182
|
+
*/
|
183
|
+
|
184
|
+
#define CHECK(string,octet) CHECK_AT((string),(octet),0)
|
185
|
+
|
186
|
+
/*
|
187
|
+
* Check if the character at the specified position is an alphabetical
|
188
|
+
* character, a digit, '_', or '-'.
|
189
|
+
*/
|
190
|
+
|
191
|
+
#define IS_ALPHA_AT(string,offset) \
|
192
|
+
(((string).pointer[offset] >= (yaml_char_t) '0' && \
|
193
|
+
(string).pointer[offset] <= (yaml_char_t) '9') || \
|
194
|
+
((string).pointer[offset] >= (yaml_char_t) 'A' && \
|
195
|
+
(string).pointer[offset] <= (yaml_char_t) 'Z') || \
|
196
|
+
((string).pointer[offset] >= (yaml_char_t) 'a' && \
|
197
|
+
(string).pointer[offset] <= (yaml_char_t) 'z') || \
|
198
|
+
(string).pointer[offset] == '_' || \
|
199
|
+
(string).pointer[offset] == '-')
|
200
|
+
|
201
|
+
#define IS_ALPHA(string) IS_ALPHA_AT((string),0)
|
202
|
+
|
203
|
+
/*
|
204
|
+
* Check if the character at the specified position is a digit.
|
205
|
+
*/
|
206
|
+
|
207
|
+
#define IS_DIGIT_AT(string,offset) \
|
208
|
+
(((string).pointer[offset] >= (yaml_char_t) '0' && \
|
209
|
+
(string).pointer[offset] <= (yaml_char_t) '9'))
|
210
|
+
|
211
|
+
#define IS_DIGIT(string) IS_DIGIT_AT((string),0)
|
212
|
+
|
213
|
+
/*
|
214
|
+
* Get the value of a digit.
|
215
|
+
*/
|
216
|
+
|
217
|
+
#define AS_DIGIT_AT(string,offset) \
|
218
|
+
((string).pointer[offset] - (yaml_char_t) '0')
|
219
|
+
|
220
|
+
#define AS_DIGIT(string) AS_DIGIT_AT((string),0)
|
221
|
+
|
222
|
+
/*
|
223
|
+
* Check if the character at the specified position is a hex-digit.
|
224
|
+
*/
|
225
|
+
|
226
|
+
#define IS_HEX_AT(string,offset) \
|
227
|
+
(((string).pointer[offset] >= (yaml_char_t) '0' && \
|
228
|
+
(string).pointer[offset] <= (yaml_char_t) '9') || \
|
229
|
+
((string).pointer[offset] >= (yaml_char_t) 'A' && \
|
230
|
+
(string).pointer[offset] <= (yaml_char_t) 'F') || \
|
231
|
+
((string).pointer[offset] >= (yaml_char_t) 'a' && \
|
232
|
+
(string).pointer[offset] <= (yaml_char_t) 'f'))
|
233
|
+
|
234
|
+
#define IS_HEX(string) IS_HEX_AT((string),0)
|
235
|
+
|
236
|
+
/*
|
237
|
+
* Get the value of a hex-digit.
|
238
|
+
*/
|
239
|
+
|
240
|
+
#define AS_HEX_AT(string,offset) \
|
241
|
+
(((string).pointer[offset] >= (yaml_char_t) 'A' && \
|
242
|
+
(string).pointer[offset] <= (yaml_char_t) 'F') ? \
|
243
|
+
((string).pointer[offset] - (yaml_char_t) 'A' + 10) : \
|
244
|
+
((string).pointer[offset] >= (yaml_char_t) 'a' && \
|
245
|
+
(string).pointer[offset] <= (yaml_char_t) 'f') ? \
|
246
|
+
((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \
|
247
|
+
((string).pointer[offset] - (yaml_char_t) '0'))
|
248
|
+
|
249
|
+
#define AS_HEX(string) AS_HEX_AT((string),0)
|
250
|
+
|
251
|
+
/*
|
252
|
+
* Check if the character is ASCII.
|
253
|
+
*/
|
254
|
+
|
255
|
+
#define IS_ASCII_AT(string,offset) \
|
256
|
+
((string).pointer[offset] <= (yaml_char_t) '\x7F')
|
257
|
+
|
258
|
+
#define IS_ASCII(string) IS_ASCII_AT((string),0)
|
259
|
+
|
260
|
+
/*
|
261
|
+
* Check if the character can be printed unescaped.
|
262
|
+
*/
|
263
|
+
|
264
|
+
#define IS_PRINTABLE_AT(string,offset) \
|
265
|
+
(((string).pointer[offset] == 0x0A) /* . == #x0A */ \
|
266
|
+
|| ((string).pointer[offset] >= 0x20 /* #x20 <= . <= #x7E */ \
|
267
|
+
&& (string).pointer[offset] <= 0x7E) \
|
268
|
+
|| ((string).pointer[offset] == 0xC2 /* #0xA0 <= . <= #xD7FF */ \
|
269
|
+
&& (string).pointer[offset+1] >= 0xA0) \
|
270
|
+
|| ((string).pointer[offset] > 0xC2 \
|
271
|
+
&& (string).pointer[offset] < 0xED) \
|
272
|
+
|| ((string).pointer[offset] == 0xED \
|
273
|
+
&& (string).pointer[offset+1] < 0xA0) \
|
274
|
+
|| ((string).pointer[offset] == 0xEE) \
|
275
|
+
|| ((string).pointer[offset] == 0xEF /* #xE000 <= . <= #xFFFD */ \
|
276
|
+
&& !((string).pointer[offset+1] == 0xBB /* && . != #xFEFF */ \
|
277
|
+
&& (string).pointer[offset+2] == 0xBF) \
|
278
|
+
&& !((string).pointer[offset+1] == 0xBF \
|
279
|
+
&& ((string).pointer[offset+2] == 0xBE \
|
280
|
+
|| (string).pointer[offset+2] == 0xBF))))
|
281
|
+
|
282
|
+
#define IS_PRINTABLE(string) IS_PRINTABLE_AT((string),0)
|
283
|
+
|
284
|
+
/*
|
285
|
+
* Check if the character at the specified position is NUL.
|
286
|
+
*/
|
287
|
+
|
288
|
+
#define IS_Z_AT(string,offset) CHECK_AT((string),'\0',(offset))
|
289
|
+
|
290
|
+
#define IS_Z(string) IS_Z_AT((string),0)
|
291
|
+
|
292
|
+
/*
|
293
|
+
* Check if the character at the specified position is BOM.
|
294
|
+
*/
|
295
|
+
|
296
|
+
#define IS_BOM_AT(string,offset) \
|
297
|
+
(CHECK_AT((string),'\xEF',(offset)) \
|
298
|
+
&& CHECK_AT((string),'\xBB',(offset)+1) \
|
299
|
+
&& CHECK_AT((string),'\xBF',(offset)+2)) /* BOM (#xFEFF) */
|
300
|
+
|
301
|
+
#define IS_BOM(string) IS_BOM_AT(string,0)
|
302
|
+
|
303
|
+
/*
|
304
|
+
* Check if the character at the specified position is space.
|
305
|
+
*/
|
306
|
+
|
307
|
+
#define IS_SPACE_AT(string,offset) CHECK_AT((string),' ',(offset))
|
308
|
+
|
309
|
+
#define IS_SPACE(string) IS_SPACE_AT((string),0)
|
310
|
+
|
311
|
+
/*
|
312
|
+
* Check if the character at the specified position is tab.
|
313
|
+
*/
|
314
|
+
|
315
|
+
#define IS_TAB_AT(string,offset) CHECK_AT((string),'\t',(offset))
|
316
|
+
|
317
|
+
#define IS_TAB(string) IS_TAB_AT((string),0)
|
318
|
+
|
319
|
+
/*
|
320
|
+
* Check if the character at the specified position is blank (space or tab).
|
321
|
+
*/
|
322
|
+
|
323
|
+
#define IS_BLANK_AT(string,offset) \
|
324
|
+
(IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset)))
|
325
|
+
|
326
|
+
#define IS_BLANK(string) IS_BLANK_AT((string),0)
|
327
|
+
|
328
|
+
/*
|
329
|
+
* Check if the character at the specified position is a line break.
|
330
|
+
*/
|
331
|
+
|
332
|
+
#define IS_BREAK_AT(string,offset) \
|
333
|
+
(CHECK_AT((string),'\r',(offset)) /* CR (#xD)*/ \
|
334
|
+
|| CHECK_AT((string),'\n',(offset)) /* LF (#xA) */ \
|
335
|
+
|| (CHECK_AT((string),'\xC2',(offset)) \
|
336
|
+
&& CHECK_AT((string),'\x85',(offset)+1)) /* NEL (#x85) */ \
|
337
|
+
|| (CHECK_AT((string),'\xE2',(offset)) \
|
338
|
+
&& CHECK_AT((string),'\x80',(offset)+1) \
|
339
|
+
&& CHECK_AT((string),'\xA8',(offset)+2)) /* LS (#x2028) */ \
|
340
|
+
|| (CHECK_AT((string),'\xE2',(offset)) \
|
341
|
+
&& CHECK_AT((string),'\x80',(offset)+1) \
|
342
|
+
&& CHECK_AT((string),'\xA9',(offset)+2))) /* PS (#x2029) */
|
343
|
+
|
344
|
+
#define IS_BREAK(string) IS_BREAK_AT((string),0)
|
345
|
+
|
346
|
+
#define IS_CRLF_AT(string,offset) \
|
347
|
+
(CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1))
|
348
|
+
|
349
|
+
#define IS_CRLF(string) IS_CRLF_AT((string),0)
|
350
|
+
|
351
|
+
/*
|
352
|
+
* Check if the character is a line break or NUL.
|
353
|
+
*/
|
354
|
+
|
355
|
+
#define IS_BREAKZ_AT(string,offset) \
|
356
|
+
(IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset)))
|
357
|
+
|
358
|
+
#define IS_BREAKZ(string) IS_BREAKZ_AT((string),0)
|
359
|
+
|
360
|
+
/*
|
361
|
+
* Check if the character is a line break, space, or NUL.
|
362
|
+
*/
|
363
|
+
|
364
|
+
#define IS_SPACEZ_AT(string,offset) \
|
365
|
+
(IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
|
366
|
+
|
367
|
+
#define IS_SPACEZ(string) IS_SPACEZ_AT((string),0)
|
368
|
+
|
369
|
+
/*
|
370
|
+
* Check if the character is a line break, space, tab, or NUL.
|
371
|
+
*/
|
372
|
+
|
373
|
+
#define IS_BLANKZ_AT(string,offset) \
|
374
|
+
(IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset)))
|
375
|
+
|
376
|
+
#define IS_BLANKZ(string) IS_BLANKZ_AT((string),0)
|
377
|
+
|
378
|
+
/*
|
379
|
+
* Determine the width of the character.
|
380
|
+
*/
|
381
|
+
|
382
|
+
#define WIDTH_AT(string,offset) \
|
383
|
+
(((string).pointer[offset] & 0x80) == 0x00 ? 1 : \
|
384
|
+
((string).pointer[offset] & 0xE0) == 0xC0 ? 2 : \
|
385
|
+
((string).pointer[offset] & 0xF0) == 0xE0 ? 3 : \
|
386
|
+
((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0)
|
387
|
+
|
388
|
+
#define WIDTH(string) WIDTH_AT((string),0)
|
389
|
+
|
390
|
+
/*
|
391
|
+
* Move the string pointer to the next character.
|
392
|
+
*/
|
393
|
+
|
394
|
+
#define MOVE(string) ((string).pointer += WIDTH((string)))
|
395
|
+
|
396
|
+
/*
|
397
|
+
* Copy a character and move the pointers of both strings.
|
398
|
+
*/
|
399
|
+
|
400
|
+
#define COPY(string_a,string_b) \
|
401
|
+
((*(string_b).pointer & 0x80) == 0x00 ? \
|
402
|
+
(*((string_a).pointer++) = *((string_b).pointer++)) : \
|
403
|
+
(*(string_b).pointer & 0xE0) == 0xC0 ? \
|
404
|
+
(*((string_a).pointer++) = *((string_b).pointer++), \
|
405
|
+
*((string_a).pointer++) = *((string_b).pointer++)) : \
|
406
|
+
(*(string_b).pointer & 0xF0) == 0xE0 ? \
|
407
|
+
(*((string_a).pointer++) = *((string_b).pointer++), \
|
408
|
+
*((string_a).pointer++) = *((string_b).pointer++), \
|
409
|
+
*((string_a).pointer++) = *((string_b).pointer++)) : \
|
410
|
+
(*(string_b).pointer & 0xF8) == 0xF0 ? \
|
411
|
+
(*((string_a).pointer++) = *((string_b).pointer++), \
|
412
|
+
*((string_a).pointer++) = *((string_b).pointer++), \
|
413
|
+
*((string_a).pointer++) = *((string_b).pointer++), \
|
414
|
+
*((string_a).pointer++) = *((string_b).pointer++)) : 0)
|
415
|
+
|
416
|
+
/*
|
417
|
+
* Stack and queue management.
|
418
|
+
*/
|
419
|
+
|
420
|
+
YAML_DECLARE(int)
|
421
|
+
yaml_stack_extend(void **start, void **top, void **end);
|
422
|
+
|
423
|
+
YAML_DECLARE(int)
|
424
|
+
yaml_queue_extend(void **start, void **head, void **tail, void **end);
|
425
|
+
|
426
|
+
#define STACK_INIT(context,stack,size) \
|
427
|
+
(((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ? \
|
428
|
+
((stack).top = (stack).start, \
|
429
|
+
(stack).end = (stack).start+(size), \
|
430
|
+
1) : \
|
431
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
432
|
+
0))
|
433
|
+
|
434
|
+
#define STACK_DEL(context,stack) \
|
435
|
+
(yaml_free((stack).start), \
|
436
|
+
(stack).start = (stack).top = (stack).end = 0)
|
437
|
+
|
438
|
+
#define STACK_EMPTY(context,stack) \
|
439
|
+
((void)(context), \
|
440
|
+
((stack).start == (stack).top))
|
441
|
+
|
442
|
+
#define STACK_LIMIT(context,stack,size) \
|
443
|
+
((stack).top - (stack).start < (size) ? \
|
444
|
+
1 : \
|
445
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
446
|
+
0))
|
447
|
+
|
448
|
+
#define PUSH(context,stack,value) \
|
449
|
+
(((stack).top != (stack).end \
|
450
|
+
|| yaml_stack_extend((void **)&(stack).start, \
|
451
|
+
(void **)&(stack).top, (void **)&(stack).end)) ? \
|
452
|
+
(*((stack).top++) = value, \
|
453
|
+
1) : \
|
454
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
455
|
+
0))
|
456
|
+
|
457
|
+
#define POP(context,stack) \
|
458
|
+
(*(--(stack).top))
|
459
|
+
|
460
|
+
#define QUEUE_INIT(context,queue,size) \
|
461
|
+
(((queue).start = yaml_malloc((size)*sizeof(*(queue).start))) ? \
|
462
|
+
((queue).head = (queue).tail = (queue).start, \
|
463
|
+
(queue).end = (queue).start+(size), \
|
464
|
+
1) : \
|
465
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
466
|
+
0))
|
467
|
+
|
468
|
+
#define QUEUE_DEL(context,queue) \
|
469
|
+
(yaml_free((queue).start), \
|
470
|
+
(queue).start = (queue).head = (queue).tail = (queue).end = 0)
|
471
|
+
|
472
|
+
#define QUEUE_EMPTY(context,queue) \
|
473
|
+
((queue).head == (queue).tail)
|
474
|
+
|
475
|
+
#define ENQUEUE(context,queue,value) \
|
476
|
+
(((queue).tail != (queue).end \
|
477
|
+
|| yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
|
478
|
+
(void **)&(queue).tail, (void **)&(queue).end)) ? \
|
479
|
+
(*((queue).tail++) = value, \
|
480
|
+
1) : \
|
481
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
482
|
+
0))
|
483
|
+
|
484
|
+
#define DEQUEUE(context,queue) \
|
485
|
+
(*((queue).head++))
|
486
|
+
|
487
|
+
#define QUEUE_INSERT(context,queue,index,value) \
|
488
|
+
(((queue).tail != (queue).end \
|
489
|
+
|| yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
|
490
|
+
(void **)&(queue).tail, (void **)&(queue).end)) ? \
|
491
|
+
(memmove((queue).head+(index)+1,(queue).head+(index), \
|
492
|
+
((queue).tail-(queue).head-(index))*sizeof(*(queue).start)), \
|
493
|
+
*((queue).head+(index)) = value, \
|
494
|
+
(queue).tail++, \
|
495
|
+
1) : \
|
496
|
+
((context)->error = YAML_MEMORY_ERROR, \
|
497
|
+
0))
|
498
|
+
|
499
|
+
/*
|
500
|
+
* Token initializers.
|
501
|
+
*/
|
502
|
+
|
503
|
+
#define TOKEN_INIT(token,token_type,token_start_mark,token_end_mark) \
|
504
|
+
(memset(&(token), 0, sizeof(yaml_token_t)), \
|
505
|
+
(token).type = (token_type), \
|
506
|
+
(token).start_mark = (token_start_mark), \
|
507
|
+
(token).end_mark = (token_end_mark))
|
508
|
+
|
509
|
+
#define STREAM_START_TOKEN_INIT(token,token_encoding,start_mark,end_mark) \
|
510
|
+
(TOKEN_INIT((token),YAML_STREAM_START_TOKEN,(start_mark),(end_mark)), \
|
511
|
+
(token).data.stream_start.encoding = (token_encoding))
|
512
|
+
|
513
|
+
#define STREAM_END_TOKEN_INIT(token,start_mark,end_mark) \
|
514
|
+
(TOKEN_INIT((token),YAML_STREAM_END_TOKEN,(start_mark),(end_mark)))
|
515
|
+
|
516
|
+
#define ALIAS_TOKEN_INIT(token,token_value,start_mark,end_mark) \
|
517
|
+
(TOKEN_INIT((token),YAML_ALIAS_TOKEN,(start_mark),(end_mark)), \
|
518
|
+
(token).data.alias.value = (token_value))
|
519
|
+
|
520
|
+
#define ANCHOR_TOKEN_INIT(token,token_value,start_mark,end_mark) \
|
521
|
+
(TOKEN_INIT((token),YAML_ANCHOR_TOKEN,(start_mark),(end_mark)), \
|
522
|
+
(token).data.anchor.value = (token_value))
|
523
|
+
|
524
|
+
#define TAG_TOKEN_INIT(token,token_handle,token_suffix,start_mark,end_mark) \
|
525
|
+
(TOKEN_INIT((token),YAML_TAG_TOKEN,(start_mark),(end_mark)), \
|
526
|
+
(token).data.tag.handle = (token_handle), \
|
527
|
+
(token).data.tag.suffix = (token_suffix))
|
528
|
+
|
529
|
+
#define SCALAR_TOKEN_INIT(token,token_value,token_length,token_style,start_mark,end_mark) \
|
530
|
+
(TOKEN_INIT((token),YAML_SCALAR_TOKEN,(start_mark),(end_mark)), \
|
531
|
+
(token).data.scalar.value = (token_value), \
|
532
|
+
(token).data.scalar.length = (token_length), \
|
533
|
+
(token).data.scalar.style = (token_style))
|
534
|
+
|
535
|
+
#define VERSION_DIRECTIVE_TOKEN_INIT(token,token_major,token_minor,start_mark,end_mark) \
|
536
|
+
(TOKEN_INIT((token),YAML_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \
|
537
|
+
(token).data.version_directive.major = (token_major), \
|
538
|
+
(token).data.version_directive.minor = (token_minor))
|
539
|
+
|
540
|
+
#define TAG_DIRECTIVE_TOKEN_INIT(token,token_handle,token_prefix,start_mark,end_mark) \
|
541
|
+
(TOKEN_INIT((token),YAML_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \
|
542
|
+
(token).data.tag_directive.handle = (token_handle), \
|
543
|
+
(token).data.tag_directive.prefix = (token_prefix))
|
544
|
+
|
545
|
+
/*
|
546
|
+
* Event initializers.
|
547
|
+
*/
|
548
|
+
|
549
|
+
#define EVENT_INIT(event,event_type,event_start_mark,event_end_mark) \
|
550
|
+
(memset(&(event), 0, sizeof(yaml_event_t)), \
|
551
|
+
(event).type = (event_type), \
|
552
|
+
(event).start_mark = (event_start_mark), \
|
553
|
+
(event).end_mark = (event_end_mark))
|
554
|
+
|
555
|
+
#define STREAM_START_EVENT_INIT(event,event_encoding,start_mark,end_mark) \
|
556
|
+
(EVENT_INIT((event),YAML_STREAM_START_EVENT,(start_mark),(end_mark)), \
|
557
|
+
(event).data.stream_start.encoding = (event_encoding))
|
558
|
+
|
559
|
+
#define STREAM_END_EVENT_INIT(event,start_mark,end_mark) \
|
560
|
+
(EVENT_INIT((event),YAML_STREAM_END_EVENT,(start_mark),(end_mark)))
|
561
|
+
|
562
|
+
#define DOCUMENT_START_EVENT_INIT(event,event_version_directive, \
|
563
|
+
event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \
|
564
|
+
(EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)), \
|
565
|
+
(event).data.document_start.version_directive = (event_version_directive), \
|
566
|
+
(event).data.document_start.tag_directives.start = (event_tag_directives_start), \
|
567
|
+
(event).data.document_start.tag_directives.end = (event_tag_directives_end), \
|
568
|
+
(event).data.document_start.implicit = (event_implicit))
|
569
|
+
|
570
|
+
#define DOCUMENT_END_EVENT_INIT(event,event_implicit,start_mark,end_mark) \
|
571
|
+
(EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)), \
|
572
|
+
(event).data.document_end.implicit = (event_implicit))
|
573
|
+
|
574
|
+
#define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark) \
|
575
|
+
(EVENT_INIT((event),YAML_ALIAS_EVENT,(start_mark),(end_mark)), \
|
576
|
+
(event).data.alias.anchor = (event_anchor))
|
577
|
+
|
578
|
+
#define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value,event_length, \
|
579
|
+
event_plain_implicit, event_quoted_implicit,event_style,start_mark,end_mark) \
|
580
|
+
(EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)), \
|
581
|
+
(event).data.scalar.anchor = (event_anchor), \
|
582
|
+
(event).data.scalar.tag = (event_tag), \
|
583
|
+
(event).data.scalar.value = (event_value), \
|
584
|
+
(event).data.scalar.length = (event_length), \
|
585
|
+
(event).data.scalar.plain_implicit = (event_plain_implicit), \
|
586
|
+
(event).data.scalar.quoted_implicit = (event_quoted_implicit), \
|
587
|
+
(event).data.scalar.style = (event_style))
|
588
|
+
|
589
|
+
#define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag, \
|
590
|
+
event_implicit,event_style,start_mark,end_mark) \
|
591
|
+
(EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)), \
|
592
|
+
(event).data.sequence_start.anchor = (event_anchor), \
|
593
|
+
(event).data.sequence_start.tag = (event_tag), \
|
594
|
+
(event).data.sequence_start.implicit = (event_implicit), \
|
595
|
+
(event).data.sequence_start.style = (event_style))
|
596
|
+
|
597
|
+
#define SEQUENCE_END_EVENT_INIT(event,start_mark,end_mark) \
|
598
|
+
(EVENT_INIT((event),YAML_SEQUENCE_END_EVENT,(start_mark),(end_mark)))
|
599
|
+
|
600
|
+
#define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag, \
|
601
|
+
event_implicit,event_style,start_mark,end_mark) \
|
602
|
+
(EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)), \
|
603
|
+
(event).data.mapping_start.anchor = (event_anchor), \
|
604
|
+
(event).data.mapping_start.tag = (event_tag), \
|
605
|
+
(event).data.mapping_start.implicit = (event_implicit), \
|
606
|
+
(event).data.mapping_start.style = (event_style))
|
607
|
+
|
608
|
+
#define MAPPING_END_EVENT_INIT(event,start_mark,end_mark) \
|
609
|
+
(EVENT_INIT((event),YAML_MAPPING_END_EVENT,(start_mark),(end_mark)))
|
610
|
+
|
611
|
+
/*
|
612
|
+
* Document initializer.
|
613
|
+
*/
|
614
|
+
|
615
|
+
#define DOCUMENT_INIT(document,document_nodes_start,document_nodes_end, \
|
616
|
+
document_version_directive,document_tag_directives_start, \
|
617
|
+
document_tag_directives_end,document_start_implicit, \
|
618
|
+
document_end_implicit,document_start_mark,document_end_mark) \
|
619
|
+
(memset(&(document), 0, sizeof(yaml_document_t)), \
|
620
|
+
(document).nodes.start = (document_nodes_start), \
|
621
|
+
(document).nodes.end = (document_nodes_end), \
|
622
|
+
(document).nodes.top = (document_nodes_start), \
|
623
|
+
(document).version_directive = (document_version_directive), \
|
624
|
+
(document).tag_directives.start = (document_tag_directives_start), \
|
625
|
+
(document).tag_directives.end = (document_tag_directives_end), \
|
626
|
+
(document).start_implicit = (document_start_implicit), \
|
627
|
+
(document).end_implicit = (document_end_implicit), \
|
628
|
+
(document).start_mark = (document_start_mark), \
|
629
|
+
(document).end_mark = (document_end_mark))
|
630
|
+
|
631
|
+
/*
|
632
|
+
* Node initializers.
|
633
|
+
*/
|
634
|
+
|
635
|
+
#define NODE_INIT(node,node_type,node_tag,node_start_mark,node_end_mark) \
|
636
|
+
(memset(&(node), 0, sizeof(yaml_node_t)), \
|
637
|
+
(node).type = (node_type), \
|
638
|
+
(node).tag = (node_tag), \
|
639
|
+
(node).start_mark = (node_start_mark), \
|
640
|
+
(node).end_mark = (node_end_mark))
|
641
|
+
|
642
|
+
#define SCALAR_NODE_INIT(node,node_tag,node_value,node_length, \
|
643
|
+
node_style,start_mark,end_mark) \
|
644
|
+
(NODE_INIT((node),YAML_SCALAR_NODE,(node_tag),(start_mark),(end_mark)), \
|
645
|
+
(node).data.scalar.value = (node_value), \
|
646
|
+
(node).data.scalar.length = (node_length), \
|
647
|
+
(node).data.scalar.style = (node_style))
|
648
|
+
|
649
|
+
#define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end, \
|
650
|
+
node_style,start_mark,end_mark) \
|
651
|
+
(NODE_INIT((node),YAML_SEQUENCE_NODE,(node_tag),(start_mark),(end_mark)), \
|
652
|
+
(node).data.sequence.items.start = (node_items_start), \
|
653
|
+
(node).data.sequence.items.end = (node_items_end), \
|
654
|
+
(node).data.sequence.items.top = (node_items_start), \
|
655
|
+
(node).data.sequence.style = (node_style))
|
656
|
+
|
657
|
+
#define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end, \
|
658
|
+
node_style,start_mark,end_mark) \
|
659
|
+
(NODE_INIT((node),YAML_MAPPING_NODE,(node_tag),(start_mark),(end_mark)), \
|
660
|
+
(node).data.mapping.pairs.start = (node_pairs_start), \
|
661
|
+
(node).data.mapping.pairs.end = (node_pairs_end), \
|
662
|
+
(node).data.mapping.pairs.top = (node_pairs_start), \
|
663
|
+
(node).data.mapping.style = (node_style))
|
664
|
+
|