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