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