Changeset 263
- Timestamp:
- 12/27/07 07:05:17 (4 years ago)
- Location:
- libyaml/trunk
- Files:
-
- 10 modified
-
src/api.c (modified) (4 diffs)
-
src/dumper.c (modified) (2 diffs)
-
src/emitter.c (modified) (91 diffs)
-
src/loader.c (modified) (2 diffs)
-
src/parser.c (modified) (30 diffs)
-
src/reader.c (modified) (18 diffs)
-
src/scanner.c (modified) (131 diffs)
-
src/writer.c (modified) (9 diffs)
-
src/yaml_private.h (modified) (10 diffs)
-
tests/run-scanner.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/src/api.c
r261 r263 173 173 174 174 memset(parser, 0, sizeof(yaml_parser_t)); 175 if (! BUFFER_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY))175 if (!STRING_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY)) 176 176 goto error; 177 if (! BUFFER_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY))177 if (!STRING_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY)) 178 178 goto error; 179 179 if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_CAPACITY)) … … 207 207 assert(parser); /* Non-NULL parser object expected. */ 208 208 209 BUFFER_DEL(parser, parser->raw_input);210 BUFFER_DEL(parser, parser->input);209 STRING_DEL(parser, parser->raw_input); 210 STRING_DEL(parser, parser->input); 211 211 while (!QUEUE_EMPTY(parser, parser->tokens)) { 212 212 yaml_token_destroy(&DEQUEUE(parser, parser->tokens)); … … 358 358 359 359 memset(emitter, 0, sizeof(yaml_emitter_t)); 360 if (! BUFFER_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY))360 if (!STRING_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY)) 361 361 goto error; 362 if (! BUFFER_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY))362 if (!STRING_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY)) 363 363 goto error; 364 364 if (!STACK_INIT(emitter, emitter->states, INITIAL_STACK_CAPACITY)) … … 388 388 assert(emitter); /* Non-NULL emitter object expected. */ 389 389 390 BUFFER_DEL(emitter, emitter->output);391 BUFFER_DEL(emitter, emitter->raw_output);390 STRING_DEL(emitter, emitter->output); 391 STRING_DEL(emitter, emitter->raw_output); 392 392 STACK_DEL(emitter, emitter->states); 393 393 while (!QUEUE_EMPTY(emitter, emitter->events)) { -
libyaml/trunk/src/dumper.c
r238 r263 1 1 2 2 #include "yaml_private.h" 3 4 #if 0 3 5 4 6 /* … … 393 395 } 394 396 397 #endif 398 -
libyaml/trunk/src/emitter.c
r241 r263 7 7 8 8 #define FLUSH(emitter) \ 9 ((emitter-> buffer.pointer+5 < emitter->buffer.end)\9 ((emitter->output.pointer+5 < emitter->output.capacity) \ 10 10 || yaml_emitter_flush(emitter)) 11 11 … … 16 16 #define PUT(emitter,value) \ 17 17 (FLUSH(emitter) \ 18 && ( *(emitter->buffer.pointer++) = (yaml_char_t)(value),\18 && (JOIN_OCTET(emitter->output,(yaml_char_t)(value)), \ 19 19 emitter->column ++, \ 20 20 1)) … … 27 27 (FLUSH(emitter) \ 28 28 && ((emitter->line_break == YAML_CR_BREAK ? \ 29 (*(emitter->buffer.pointer++) = (yaml_char_t) '\r') :\29 JOIN_OCTET(emitter->output, (yaml_char_t) '\r') : \ 30 30 emitter->line_break == YAML_LN_BREAK ? \ 31 (*(emitter->buffer.pointer++) = (yaml_char_t) '\n') :\31 JOIN_OCTET(emitter->output, (yaml_char_t) '\n') : \ 32 32 emitter->line_break == YAML_CRLN_BREAK ? \ 33 ( *(emitter->buffer.pointer++) = (yaml_char_t) '\r',\34 *(emitter->buffer.pointer++) = (yaml_char_t) '\n') : 0),\33 (JOIN_OCTET(emitter->output, (yaml_char_t) '\r'), \ 34 JOIN_OCTET(emitter->output, (yaml_char_t) '\n')) : 0), \ 35 35 emitter->column = 0, \ 36 36 emitter->line ++, \ … … 43 43 #define WRITE(emitter,string) \ 44 44 (FLUSH(emitter) \ 45 && (COPY(emitter-> buffer,string), \45 && (COPY(emitter->output,string), \ 46 46 emitter->column ++, \ 47 47 1)) … … 57 57 string.pointer ++, \ 58 58 1) : \ 59 (COPY(emitter-> buffer,string), \59 (COPY(emitter->output,string), \ 60 60 emitter->column = 0, \ 61 61 emitter->line ++, \ … … 74 74 75 75 static int 76 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem);77 78 static int79 76 yaml_emitter_need_more_events(yaml_emitter_t *emitter); 80 77 … … 136 133 static int 137 134 yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 138 int root, int sequence, int mapping, intsimple_key);135 int is_root, int is_sequence, int is_mapping, int is_simple_key); 139 136 140 137 static int … … 262 259 263 260 /* 264 * Set an emitter error and return 0.265 */266 267 static int268 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem)269 {270 emitter->error = YAML_EMITTER_ERROR;271 emitter->problem = problem;272 273 return 0;274 }275 276 /*277 261 * Emit an event. 278 262 */ … … 287 271 288 272 while (!yaml_emitter_need_more_events(emitter)) { 289 if (!yaml_emitter_analyze_event(emitter, emitter->events.head)) 290 return 0; 291 if (!yaml_emitter_state_machine(emitter, emitter->events.head)) 273 if (!yaml_emitter_analyze_event(emitter, 274 emitter->events.list + emitter->events.head)) 275 return 0; 276 if (!yaml_emitter_state_machine(emitter, 277 emitter->events.list + emitter->events.head)) 292 278 return 0; 293 279 yaml_event_delete(&DEQUEUE(emitter, emitter->events)); … … 311 297 int level = 0; 312 298 int accumulate = 0; 313 yaml_event_t *event;299 size_t idx; 314 300 315 301 if (QUEUE_EMPTY(emitter, emitter->events)) 316 302 return 1; 317 303 318 switch (emitter->events. head->type) {304 switch (emitter->events.list[emitter->events.head].type) { 319 305 case YAML_DOCUMENT_START_EVENT: 320 306 accumulate = 1; … … 333 319 return 0; 334 320 335 for (event = emitter->events.head; event != emitter->events.tail; event ++) { 321 for (idx = emitter->events.head; idx < emitter->events.tail; idx ++) { 322 yaml_event_t *event = emitter->events.list+idx; 336 323 switch (event->type) { 337 324 case YAML_STREAM_START_EVENT: … … 365 352 yaml_tag_directive_t value, int allow_duplicates) 366 353 { 367 yaml_tag_directive_t *tag_directive;354 int idx; 368 355 yaml_tag_directive_t copy = { NULL, NULL }; 369 356 370 for ( tag_directive = emitter->tag_directives.start;371 tag_directive != emitter->tag_directives.top; tag_directive ++) {357 for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 358 yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 372 359 if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { 373 360 if (allow_duplicates) 374 361 return 1; 375 return yaml_emitter_set_emitter_error(emitter, 376 "duplicate %TAG directive"); 362 return EMITTER_ERROR_INIT(emitter, "duplicate %TAG directive"); 377 363 } 378 364 } … … 381 367 copy.prefix = yaml_strdup(value.prefix); 382 368 if (!copy.handle || !copy.prefix) { 383 emitter->error = YAML_MEMORY_ERROR;369 MEMORY_ERROR_INIT(emitter); 384 370 goto error; 385 371 } … … 478 464 479 465 case YAML_EMIT_END_STATE: 480 return yaml_emitter_set_emitter_error(emitter,466 return EMITTER_ERROR_INIT(emitter, 481 467 "expected nothing after STREAM-END"); 482 468 … … 527 513 emitter->line = 0; 528 514 emitter->column = 0; 529 emitter-> whitespace = 1;530 emitter->i ndention = 1;515 emitter->is_whitespace = 1; 516 emitter->is_indention = 1; 531 517 532 518 if (emitter->encoding != YAML_UTF8_ENCODING) { … … 540 526 } 541 527 542 return yaml_emitter_set_emitter_error(emitter, 543 "expected STREAM-START"); 528 return EMITTER_ERROR_INIT(emitter, "expected STREAM-START"); 544 529 } 545 530 … … 560 545 }; 561 546 yaml_tag_directive_t *tag_directive; 562 int implicit; 547 int is_implicit; 548 int idx; 563 549 564 550 if (event->data.document_start.version_directive) { … … 568 554 } 569 555 570 for (tag_directive = event->data.document_start.tag_directives.start; 571 tag_directive != event->data.document_start.tag_directives.end; 572 tag_directive ++) { 556 for (idx = 0; idx < event->data.document_start.tag_directives.length; idx++) { 557 tag_directive = event->data.document_start.tag_directives.list+idx; 573 558 if (!yaml_emitter_analyze_tag_directive(emitter, *tag_directive)) 574 559 return 0; … … 583 568 } 584 569 585 i mplicit = event->data.document_start.implicit;586 if (!first || emitter-> canonical) {587 i mplicit = 0;570 is_implicit = event->data.document_start.is_implicit; 571 if (!first || emitter->is_canonical) { 572 is_implicit = 0; 588 573 } 589 574 590 575 if (event->data.document_start.version_directive) { 591 i mplicit = 0;576 is_implicit = 0; 592 577 if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0)) 593 578 return 0; … … 598 583 } 599 584 600 if (event->data.document_start.tag_directives.start 601 != event->data.document_start.tag_directives.end) { 602 implicit = 0; 603 for (tag_directive = event->data.document_start.tag_directives.start; 604 tag_directive != event->data.document_start.tag_directives.end; 605 tag_directive ++) { 585 if (event->data.document_start.tag_directives.length) { 586 is_implicit = 0; 587 for (idx = 0; idx < event->data.document_start.tag_directives.length; 588 idx++) { 589 tag_directive = event->data.document_start.tag_directives.list+idx; 606 590 if (!yaml_emitter_write_indicator(emitter, "%TAG", 1, 0, 0)) 607 591 return 0; … … 618 602 619 603 if (yaml_emitter_check_empty_document(emitter)) { 620 i mplicit = 0;621 } 622 623 if (!i mplicit) {604 is_implicit = 0; 605 } 606 607 if (!is_implicit) { 624 608 if (!yaml_emitter_write_indent(emitter)) 625 609 return 0; 626 610 if (!yaml_emitter_write_indicator(emitter, "---", 1, 0, 0)) 627 611 return 0; 628 if (emitter-> canonical) {612 if (emitter->is_canonical) { 629 613 if (!yaml_emitter_write_indent(emitter)) 630 614 return 0; … … 647 631 } 648 632 649 return yaml_emitter_set_emitter_error(emitter, 650 "expected DOCUMENT-START or STREAM-END"); 633 return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-START or STREAM-END"); 651 634 } 652 635 … … 677 660 if (!yaml_emitter_write_indent(emitter)) 678 661 return 0; 679 if (!event->data.document_end.i mplicit) {662 if (!event->data.document_end.is_implicit) { 680 663 if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) 681 664 return 0; … … 698 681 } 699 682 700 return yaml_emitter_set_emitter_error(emitter, 701 "expected DOCUMENT-END"); 683 return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-END"); 702 684 } 703 685 … … 724 706 emitter->flow_level --; 725 707 emitter->indent = POP(emitter, emitter->indents); 726 if (emitter-> canonical && !first) {708 if (emitter->is_canonical && !first) { 727 709 if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 728 710 return 0; … … 742 724 } 743 725 744 if (emitter-> canonical || emitter->column > emitter->best_width) {726 if (emitter->is_canonical || emitter->column > emitter->best_width) { 745 727 if (!yaml_emitter_write_indent(emitter)) 746 728 return 0; … … 773 755 emitter->flow_level --; 774 756 emitter->indent = POP(emitter, emitter->indents); 775 if (emitter-> canonical && !first) {757 if (emitter->is_canonical && !first) { 776 758 if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 777 759 return 0; … … 790 772 return 0; 791 773 } 792 if (emitter-> canonical || emitter->column > emitter->best_width) {774 if (emitter->is_canonical || emitter->column > emitter->best_width) { 793 775 if (!yaml_emitter_write_indent(emitter)) 794 776 return 0; 795 777 } 796 778 797 if (!emitter-> canonical && yaml_emitter_check_simple_key(emitter))779 if (!emitter->is_canonical && yaml_emitter_check_simple_key(emitter)) 798 780 { 799 781 if (!PUSH(emitter, emitter->states, … … 828 810 } 829 811 else { 830 if (emitter-> canonical || emitter->column > emitter->best_width) {812 if (emitter->is_canonical || emitter->column > emitter->best_width) { 831 813 if (!yaml_emitter_write_indent(emitter)) 832 814 return 0; … … 851 833 { 852 834 if (!yaml_emitter_increase_indent(emitter, 0, 853 (emitter-> mapping_context && !emitter->indention)))835 (emitter->is_mapping_context && !emitter->is_indention))) 854 836 return 0; 855 837 } … … 950 932 static int 951 933 yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 952 int root, int sequence, int mapping, intsimple_key)953 { 954 emitter-> root_context =root;955 emitter-> sequence_context =sequence;956 emitter-> mapping_context =mapping;957 emitter-> simple_key_context =simple_key;934 int is_root, int is_sequence, int is_mapping, int is_simple_key) 935 { 936 emitter->is_root_context = is_root; 937 emitter->is_sequence_context = is_sequence; 938 emitter->is_mapping_context = is_mapping; 939 emitter->is_simple_key_context = is_simple_key; 958 940 959 941 switch (event->type) … … 972 954 973 955 default: 974 return yaml_emitter_set_emitter_error(emitter,956 return EMITTER_ERROR_INIT(emitter, 975 957 "expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS"); 976 958 } … … 1028 1010 return 0; 1029 1011 1030 if (emitter->flow_level || emitter-> canonical1012 if (emitter->flow_level || emitter->is_canonical 1031 1013 || event->data.sequence_start.style == YAML_FLOW_SEQUENCE_STYLE 1032 1014 || yaml_emitter_check_empty_sequence(emitter)) { … … 1052 1034 return 0; 1053 1035 1054 if (emitter->flow_level || emitter-> canonical1036 if (emitter->flow_level || emitter->is_canonical 1055 1037 || event->data.mapping_start.style == YAML_FLOW_MAPPING_STYLE 1056 1038 || yaml_emitter_check_empty_mapping(emitter)) { … … 1084 1066 return 0; 1085 1067 1086 return (emitter->events.head[0].type == YAML_SEQUENCE_START_EVENT 1087 && emitter->events.head[1].type == YAML_SEQUENCE_END_EVENT); 1068 return (emitter->events.list[emitter->events.head].type 1069 == YAML_SEQUENCE_START_EVENT && 1070 emitter->events.list[emitter->events.head+1].type 1071 == YAML_SEQUENCE_END_EVENT); 1088 1072 } 1089 1073 … … 1098 1082 return 0; 1099 1083 1100 return (emitter->events.head[0].type == YAML_MAPPING_START_EVENT 1101 && emitter->events.head[1].type == YAML_MAPPING_END_EVENT); 1084 return (emitter->events.list[emitter->events.head].type 1085 == YAML_MAPPING_START_EVENT && 1086 emitter->events.list[emitter->events.head+1].type 1087 == YAML_MAPPING_END_EVENT); 1102 1088 } 1103 1089 … … 1109 1095 yaml_emitter_check_simple_key(yaml_emitter_t *emitter) 1110 1096 { 1111 yaml_event_t *event = emitter->events. head;1097 yaml_event_t *event = emitter->events.list + emitter->events.head; 1112 1098 size_t length = 0; 1113 1099 … … 1119 1105 1120 1106 case YAML_SCALAR_EVENT: 1121 if (emitter->scalar_data. multiline)1107 if (emitter->scalar_data.is_multiline) 1122 1108 return 0; 1123 1109 length += emitter->anchor_data.anchor_length … … 1163 1149 int no_tag = (!emitter->tag_data.handle && !emitter->tag_data.suffix); 1164 1150 1165 if (no_tag && !event->data.scalar. plain_implicit1166 && !event->data.scalar. quoted_implicit) {1167 return yaml_emitter_set_emitter_error(emitter,1151 if (no_tag && !event->data.scalar.is_plain_implicit 1152 && !event->data.scalar.is_quoted_implicit) { 1153 return EMITTER_ERROR_INIT(emitter, 1168 1154 "neither tag nor implicit flags are specified"); 1169 1155 } … … 1172 1158 style = YAML_PLAIN_SCALAR_STYLE; 1173 1159 1174 if (emitter-> canonical)1160 if (emitter->is_canonical) 1175 1161 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1176 1162 1177 if (emitter-> simple_key_context && emitter->scalar_data.multiline)1163 if (emitter->is_simple_key_context && emitter->scalar_data.is_multiline) 1178 1164 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1179 1165 1180 1166 if (style == YAML_PLAIN_SCALAR_STYLE) 1181 1167 { 1182 if ((emitter->flow_level && !emitter->scalar_data. flow_plain_allowed)1183 || (!emitter->flow_level && !emitter->scalar_data. block_plain_allowed))1168 if ((emitter->flow_level && !emitter->scalar_data.is_flow_plain_allowed) 1169 || (!emitter->flow_level && !emitter->scalar_data.is_block_plain_allowed)) 1184 1170 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1185 1171 if (!emitter->scalar_data.length 1186 && (emitter->flow_level || emitter-> simple_key_context))1172 && (emitter->flow_level || emitter->is_simple_key_context)) 1187 1173 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1188 if (no_tag && !event->data.scalar. plain_implicit)1174 if (no_tag && !event->data.scalar.is_plain_implicit) 1189 1175 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1190 1176 } … … 1192 1178 if (style == YAML_SINGLE_QUOTED_SCALAR_STYLE) 1193 1179 { 1194 if (!emitter->scalar_data. single_quoted_allowed)1180 if (!emitter->scalar_data.is_single_quoted_allowed) 1195 1181 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1196 1182 } … … 1198 1184 if (style == YAML_LITERAL_SCALAR_STYLE || style == YAML_FOLDED_SCALAR_STYLE) 1199 1185 { 1200 if (!emitter->scalar_data. block_allowed1201 || emitter->flow_level || emitter-> simple_key_context)1186 if (!emitter->scalar_data.is_block_allowed 1187 || emitter->flow_level || emitter->is_simple_key_context) 1202 1188 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1203 1189 } 1204 1190 1205 if (no_tag && !event->data.scalar. quoted_implicit1191 if (no_tag && !event->data.scalar.is_quoted_implicit 1206 1192 && style != YAML_PLAIN_SCALAR_STYLE) 1207 1193 { … … 1226 1212 1227 1213 if (!yaml_emitter_write_indicator(emitter, 1228 (emitter->anchor_data. alias ? "*" : "&"), 1, 0, 0))1214 (emitter->anchor_data.is_alias ? "*" : "&"), 1, 0, 0)) 1229 1215 return 0; 1230 1216 … … 1280 1266 return yaml_emitter_write_plain_scalar(emitter, 1281 1267 emitter->scalar_data.value, emitter->scalar_data.length, 1282 !emitter-> simple_key_context);1268 !emitter->is_simple_key_context); 1283 1269 1284 1270 case YAML_SINGLE_QUOTED_SCALAR_STYLE: 1285 1271 return yaml_emitter_write_single_quoted_scalar(emitter, 1286 1272 emitter->scalar_data.value, emitter->scalar_data.length, 1287 !emitter-> simple_key_context);1273 !emitter->is_simple_key_context); 1288 1274 1289 1275 case YAML_DOUBLE_QUOTED_SCALAR_STYLE: 1290 1276 return yaml_emitter_write_double_quoted_scalar(emitter, 1291 1277 emitter->scalar_data.value, emitter->scalar_data.length, 1292 !emitter-> simple_key_context);1278 !emitter->is_simple_key_context); 1293 1279 1294 1280 case YAML_LITERAL_SCALAR_STYLE: … … 1316 1302 { 1317 1303 if (version_directive.major != 1 || version_directive.minor != 1) { 1318 return yaml_emitter_set_emitter_error(emitter, 1319 "incompatible %YAML directive"); 1304 return EMITTER_ERROR_INIT(emitter, "incompatible %YAML directive"); 1320 1305 } 1321 1306 … … 1336 1321 strlen((char *)tag_directive.prefix)); 1337 1322 1338 if (handle.start == handle.end) { 1339 return yaml_emitter_set_emitter_error(emitter, 1340 "tag handle must not be empty"); 1341 } 1342 1343 if (handle.start[0] != '!') { 1344 return yaml_emitter_set_emitter_error(emitter, 1345 "tag handle must start with '!'"); 1346 } 1347 1348 if (handle.end[-1] != '!') { 1349 return yaml_emitter_set_emitter_error(emitter, 1350 "tag handle must end with '!'"); 1323 if (!handle.capacity) { 1324 return EMITTER_ERROR_INIT(emitter, "tag handle must not be empty"); 1325 } 1326 1327 if (handle.buffer[0] != '!') { 1328 return EMITTER_ERROR_INIT(emitter, "tag handle must start with '!'"); 1329 } 1330 1331 if (handle.buffer[handle.capacity-1] != '!') { 1332 return EMITTER_ERROR_INIT(emitter, "tag handle must end with '!'"); 1351 1333 } 1352 1334 1353 1335 handle.pointer ++; 1354 1336 1355 while (handle.pointer < handle. end-1) {1337 while (handle.pointer < handle.capacity-1) { 1356 1338 if (!IS_ALPHA(handle)) { 1357 return yaml_emitter_set_emitter_error(emitter,1339 return EMITTER_ERROR_INIT(emitter, 1358 1340 "tag handle must contain alphanumerical characters only"); 1359 1341 } … … 1361 1343 } 1362 1344 1363 if (prefix.start == prefix.end) { 1364 return yaml_emitter_set_emitter_error(emitter, 1365 "tag prefix must not be empty"); 1345 if (!prefix.capacity) { 1346 return EMITTER_ERROR_INIT(emitter, "tag prefix must not be empty"); 1366 1347 } 1367 1348 … … 1375 1356 static int 1376 1357 yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, 1377 yaml_char_t *anchor, int alias)1358 yaml_char_t *anchor, int is_alias) 1378 1359 { 1379 1360 yaml_string_t string = STRING(anchor, strlen((char *)anchor)); 1380 1361 1381 if ( string.start == string.end) {1382 return yaml_emitter_set_emitter_error(emitter,alias ?1362 if (!string.capacity) { 1363 return EMITTER_ERROR_INIT(emitter, is_alias ? 1383 1364 "alias value must not be empty" : 1384 1365 "anchor value must not be empty"); 1385 1366 } 1386 1367 1387 while (string.pointer != string.end) {1368 while (string.pointer < string.capacity) { 1388 1369 if (!IS_ALPHA(string)) { 1389 return yaml_emitter_set_emitter_error(emitter,alias ?1370 return EMITTER_ERROR_INIT(emitter, is_alias ? 1390 1371 "alias value must contain alphanumerical characters only" : 1391 1372 "anchor value must contain alphanumerical characters only"); … … 1394 1375 } 1395 1376 1396 emitter->anchor_data.anchor = string. start;1397 emitter->anchor_data.anchor_length = string. end - string.start;1398 emitter->anchor_data. alias =alias;1377 emitter->anchor_data.anchor = string.buffer; 1378 emitter->anchor_data.anchor_length = string.capacity; 1379 emitter->anchor_data.is_alias = is_alias; 1399 1380 1400 1381 return 1; … … 1410 1391 { 1411 1392 yaml_string_t string = STRING(tag, strlen((char *)tag)); 1412 yaml_tag_directive_t *tag_directive; 1413 1414 if (string.start == string.end) { 1415 return yaml_emitter_set_emitter_error(emitter, 1416 "tag value must not be empty"); 1417 } 1418 1419 for (tag_directive = emitter->tag_directives.start; 1420 tag_directive != emitter->tag_directives.top; tag_directive ++) { 1393 size_t idx; 1394 1395 if (!string.capacity) { 1396 return EMITTER_ERROR_INIT(emitter, "tag value must not be empty"); 1397 } 1398 1399 for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 1400 yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 1421 1401 size_t prefix_length = strlen((char *)tag_directive->prefix); 1422 if (prefix_length < (size_t)(string.end - string.start)1423 && strncmp((char *)tag_directive->prefix, (char *)string. start,1402 if (prefix_length < string.capacity 1403 && strncmp((char *)tag_directive->prefix, (char *)string.buffer, 1424 1404 prefix_length) == 0) 1425 1405 { … … 1427 1407 emitter->tag_data.handle_length = 1428 1408 strlen((char *)tag_directive->handle); 1429 emitter->tag_data.suffix = string.start + prefix_length; 1430 emitter->tag_data.suffix_length = 1431 (string.end - string.start) - prefix_length; 1409 emitter->tag_data.suffix = string.buffer + prefix_length; 1410 emitter->tag_data.suffix_length = string.capacity - prefix_length; 1432 1411 return 1; 1433 1412 } 1434 1413 } 1435 1414 1436 emitter->tag_data.suffix = string. start;1437 emitter->tag_data.suffix_length = string. end - string.start;1415 emitter->tag_data.suffix = string.buffer; 1416 emitter->tag_data.suffix_length = string.capacity; 1438 1417 1439 1418 return 1; … … 1474 1453 emitter->scalar_data.length = length; 1475 1454 1476 if ( string.start == string.end)1477 { 1478 emitter->scalar_data. multiline = 0;1479 emitter->scalar_data. flow_plain_allowed = 0;1480 emitter->scalar_data. block_plain_allowed = 1;1481 emitter->scalar_data. single_quoted_allowed = 1;1482 emitter->scalar_data. block_allowed = 0;1455 if (!string.capacity) 1456 { 1457 emitter->scalar_data.is_multiline = 0; 1458 emitter->scalar_data.is_flow_plain_allowed = 0; 1459 emitter->scalar_data.is_block_plain_allowed = 1; 1460 emitter->scalar_data.is_single_quoted_allowed = 1; 1461 emitter->scalar_data.is_block_allowed = 0; 1483 1462 1484 1463 return 1; … … 1498 1477 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1499 1478 1500 while (string.pointer != string.end)1501 { 1502 if ( string.start ==string.pointer)1479 while (string.pointer < string.capacity) 1480 { 1481 if (!string.pointer) 1503 1482 { 1504 1483 if (CHECK(string, '#') || CHECK(string, ',') … … 1548 1527 1549 1528 if (!IS_PRINTABLE(string) 1550 || (!IS_ASCII(string) && !emitter-> unicode)) {1529 || (!IS_ASCII(string) && !emitter->is_unicode)) { 1551 1530 special_characters = 1; 1552 1531 } … … 1559 1538 { 1560 1539 spaces = 1; 1561 if ( string.start ==string.pointer) {1540 if (!string.pointer) { 1562 1541 leading = 1; 1563 1542 } … … 1570 1549 } 1571 1550 breaks = 1; 1572 if ( string.start ==string.pointer) {1551 if (!string.pointer) { 1573 1552 leading = 1; 1574 1553 } … … 1605 1584 } 1606 1585 1607 if ((spaces || breaks) && string.pointer == string. end-1)1586 if ((spaces || breaks) && string.pointer == string.capacity-1) 1608 1587 { 1609 1588 if (spaces && breaks) { … … 1626 1605 preceeded_by_space = IS_BLANKZ(string); 1627 1606 MOVE(string); 1628 if (string.pointer != string.end) {1607 if (string.pointer < string.capacity) { 1629 1608 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1630 1609 } 1631 1610 } 1632 1611 1633 emitter->scalar_data. multiline = line_breaks;1634 1635 emitter->scalar_data. flow_plain_allowed = 1;1636 emitter->scalar_data. block_plain_allowed = 1;1637 emitter->scalar_data. single_quoted_allowed = 1;1638 emitter->scalar_data. block_allowed = 1;1612 emitter->scalar_data.is_multiline = line_breaks; 1613 1614 emitter->scalar_data.is_flow_plain_allowed = 1; 1615 emitter->scalar_data.is_block_plain_allowed = 1; 1616 emitter->scalar_data.is_single_quoted_allowed = 1; 1617 emitter->scalar_data.is_block_allowed = 1; 1639 1618 1640 1619 if (leading_spaces || leading_breaks || trailing_spaces) { 1641 emitter->scalar_data. flow_plain_allowed = 0;1642 emitter->scalar_data. block_plain_allowed = 0;1643 emitter->scalar_data. block_allowed = 0;1620 emitter->scalar_data.is_flow_plain_allowed = 0; 1621 emitter->scalar_data.is_block_plain_allowed = 0; 1622 emitter->scalar_data.is_block_allowed = 0; 1644 1623 } 1645 1624 1646 1625 if (trailing_breaks) { 1647 emitter->scalar_data. flow_plain_allowed = 0;1648 emitter->scalar_data. block_plain_allowed = 0;1626 emitter->scalar_data.is_flow_plain_allowed = 0; 1627 emitter->scalar_data.is_block_plain_allowed = 0; 1649 1628 } 1650 1629 1651 1630 if (inline_breaks_spaces) { 1652 emitter->scalar_data. flow_plain_allowed = 0;1653 emitter->scalar_data. block_plain_allowed = 0;1654 emitter->scalar_data. single_quoted_allowed = 0;1631 emitter->scalar_data.is_flow_plain_allowed = 0; 1632 emitter->scalar_data.is_block_plain_allowed = 0; 1633 emitter->scalar_data.is_single_quoted_allowed = 0; 1655 1634 } 1656 1635 1657 1636 if (mixed_breaks_spaces || special_characters) { 1658 emitter->scalar_data. flow_plain_allowed = 0;1659 emitter->scalar_data. block_plain_allowed = 0;1660 emitter->scalar_data. single_quoted_allowed = 0;1661 emitter->scalar_data. block_allowed = 0;1637 emitter->scalar_data.is_flow_plain_allowed = 0; 1638 emitter->scalar_data.is_block_plain_allowed = 0; 1639 emitter->scalar_data.is_single_quoted_allowed = 0; 1640 emitter->scalar_data.is_block_allowed = 0; 1662 1641 } 1663 1642 1664 1643 if (line_breaks) { 1665 emitter->scalar_data. flow_plain_allowed = 0;1666 emitter->scalar_data. block_plain_allowed = 0;1644 emitter->scalar_data.is_flow_plain_allowed = 0; 1645 emitter->scalar_data.is_block_plain_allowed = 0; 1667 1646 } 1668 1647 1669 1648 if (flow_indicators) { 1670 emitter->scalar_data. flow_plain_allowed = 0;1649 emitter->scalar_data.is_flow_plain_allowed = 0; 1671 1650 } 1672 1651 1673 1652 if (block_indicators) { 1674 emitter->scalar_data. block_plain_allowed = 0;1653 emitter->scalar_data.is_block_plain_allowed = 0; 1675 1654 } 1676 1655 … … 1709 1688 return 0; 1710 1689 } 1711 if (event->data.scalar.tag && (emitter-> canonical ||1712 (!event->data.scalar. plain_implicit1713 && !event->data.scalar. quoted_implicit))) {1690 if (event->data.scalar.tag && (emitter->is_canonical || 1691 (!event->data.scalar.is_plain_implicit 1692 && !event->data.scalar.is_quoted_implicit))) { 1714 1693 if (!yaml_emitter_analyze_tag(emitter, event->data.scalar.tag)) 1715 1694 return 0; … … 1726 1705 return 0; 1727 1706 } 1728 if (event->data.sequence_start.tag && (emitter-> canonical ||1729 !event->data.sequence_start.i mplicit)) {1707 if (event->data.sequence_start.tag && (emitter->is_canonical || 1708 !event->data.sequence_start.is_implicit)) { 1730 1709 if (!yaml_emitter_analyze_tag(emitter, 1731 1710 event->data.sequence_start.tag)) … … 1740 1719 return 0; 1741 1720 } 1742 if (event->data.mapping_start.tag && (emitter-> canonical ||1743 !event->data.mapping_start.i mplicit)) {1721 if (event->data.mapping_start.tag && (emitter->is_canonical || 1722 !event->data.mapping_start.is_implicit)) { 1744 1723 if (!yaml_emitter_analyze_tag(emitter, 1745 1724 event->data.mapping_start.tag)) … … 1762 1741 if (!FLUSH(emitter)) return 0; 1763 1742 1764 *(emitter->buffer.pointer++) = (yaml_char_t) '\xEF';1765 *(emitter->buffer.pointer++) = (yaml_char_t) '\xBB';1766 *(emitter->buffer.pointer++) = (yaml_char_t) '\xBF';1743 JOIN_OCTET(emitter->output, (yaml_char_t) '\xEF'); 1744 JOIN_OCTET(emitter->output, (yaml_char_t) '\xBB'); 1745 JOIN_OCTET(emitter->output, (yaml_char_t) '\xBF'); 1767 1746 1768 1747 return 1; … … 1774 1753 int indent = (emitter->indent >= 0) ? emitter->indent : 0; 1775 1754 1776 if (!emitter->i ndention || emitter->column > indent1777 || (emitter->column == indent && !emitter-> whitespace)) {1755 if (!emitter->is_indention || emitter->column > indent 1756 || (emitter->column == indent && !emitter->is_whitespace)) { 1778 1757 if (!PUT_BREAK(emitter)) return 0; 1779 1758 } … … 1783 1762 } 1784 1763 1785 emitter-> whitespace = 1;1786 emitter->i ndention = 1;1764 emitter->is_whitespace = 1; 1765 emitter->is_indention = 1; 1787 1766 1788 1767 return 1; … … 1796 1775 yaml_string_t string = STRING((yaml_char_t *)indicator, strlen(indicator)); 1797 1776 1798 if (need_whitespace && !emitter-> whitespace) {1777 if (need_whitespace && !emitter->is_whitespace) { 1799 1778 if (!PUT(emitter, ' ')) return 0; 1800 1779 } 1801 1780 1802 while (string.pointer != string.end) {1781 while (string.pointer < string.capacity) { 1803 1782 if (!WRITE(emitter, string)) return 0; 1804 1783 } 1805 1784 1806 emitter-> whitespace = is_whitespace;1807 emitter->i ndention = (emitter->indention && is_indention);1785 emitter->is_whitespace = is_whitespace; 1786 emitter->is_indention = (emitter->is_indention && is_indention); 1808 1787 1809 1788 return 1; … … 1816 1795 yaml_string_t string = STRING(value, length); 1817 1796 1818 while (string.pointer != string.end) {1797 while (string.pointer < string.capacity) { 1819 1798 if (!WRITE(emitter, string)) return 0; 1820 1799 } 1821 1800 1822 emitter-> whitespace = 0;1823 emitter->i ndention = 0;1801 emitter->is_whitespace = 0; 1802 emitter->is_indention = 0; 1824 1803 1825 1804 return 1; … … 1832 1811 yaml_string_t string = STRING(value, length); 1833 1812 1834 if (!emitter-> whitespace) {1813 if (!emitter->is_whitespace) { 1835 1814 if (!PUT(emitter, ' ')) return 0; 1836 1815 } 1837 1816 1838 while (string.pointer != string.end) {1817 while (string.pointer < string.capacity) { 1839 1818 if (!WRITE(emitter, string)) return 0; 1840 1819 } 1841 1820 1842 emitter-> whitespace = 0;1843 emitter->i ndention = 0;1821 emitter->is_whitespace = 0; 1822 emitter->is_indention = 0; 1844 1823 1845 1824 return 1; … … 1853 1832 yaml_string_t string = STRING(value, length); 1854 1833 1855 if (need_whitespace && !emitter-> whitespace) {1834 if (need_whitespace && !emitter->is_whitespace) { 1856 1835 if (!PUT(emitter, ' ')) return 0; 1857 1836 } 1858 1837 1859 while (string.pointer != string.end) {1838 while (string.pointer < string.capacity) { 1860 1839 if (IS_ALPHA(string) 1861 1840 || CHECK(string, ';') || CHECK(string, '/') … … 1875 1854 unsigned int value; 1876 1855 while (width --) { 1877 value = *(string.pointer++); 1856 value = OCTET(string); 1857 string.pointer ++; 1878 1858 if (!PUT(emitter, '%')) return 0; 1879 1859 if (!PUT(emitter, (value >> 4) … … 1887 1867 } 1888 1868 1889 emitter-> whitespace = 0;1890 emitter->i ndention = 0;1869 emitter->is_whitespace = 0; 1870 emitter->is_indention = 0; 1891 1871 1892 1872 return 1; … … 1901 1881 int breaks = 0; 1902 1882 1903 if (!emitter-> whitespace) {1883 if (!emitter->is_whitespace) { 1904 1884 if (!PUT(emitter, ' ')) return 0; 1905 1885 } 1906 1886 1907 while (string.pointer != string.end)1887 while (string.pointer < string.capacity) 1908 1888 { 1909 1889 if (IS_SPACE(string)) … … 1926 1906 } 1927 1907 if (!WRITE_BREAK(emitter, string)) return 0; 1928 emitter->i ndention = 1;1908 emitter->is_indention = 1; 1929 1909 breaks = 1; 1930 1910 } … … 1935 1915 } 1936 1916 if (!WRITE(emitter, string)) return 0; 1937 emitter->i ndention = 0;1917 emitter->is_indention = 0; 1938 1918 spaces = 0; 1939 1919 breaks = 0; … … 1941 1921 } 1942 1922 1943 emitter-> whitespace = 0;1944 emitter->i ndention = 0;1923 emitter->is_whitespace = 0; 1924 emitter->is_indention = 0; 1945 1925 1946 1926 return 1; … … 1958 1938 return 0; 1959 1939 1960 while (string.pointer != string.end)1940 while (string.pointer < string.capacity) 1961 1941 { 1962 1942 if (IS_SPACE(string)) … … 1964 1944 if (allow_breaks && !spaces 1965 1945 && emitter->column > emitter->best_width 1966 && string.pointer != string.start1967 && string.pointer != string. end- 11946 && string.pointer != 0 1947 && string.pointer != string.capacity - 1 1968 1948 && !IS_SPACE_AT(string, 1)) { 1969 1949 if (!yaml_emitter_write_indent(emitter)) return 0; … … 1981 1961 } 1982 1962 if (!WRITE_BREAK(emitter, string)) return 0; 1983 emitter->i ndention = 1;1963 emitter->is_indention = 1; 1984 1964 breaks = 1; 1985 1965 } … … 1993 1973 } 1994 1974 if (!WRITE(emitter, string)) return 0; 1995 emitter->i ndention = 0;1975 emitter->is_indention = 0; 1996 1976 spaces = 0; 1997 1977 breaks = 0; … … 2002 1982 return 0; 2003 1983 2004 emitter-> whitespace = 0;2005 emitter->i ndention = 0;1984 emitter->is_whitespace = 0; 1985 emitter->is_indention = 0; 2006 1986 2007 1987 return 1; … … 2018 1998 return 0; 2019 1999 2020 while (string.pointer != string.end)2021 { 2022 if (!IS_PRINTABLE(string) || (!emitter-> unicode && !IS_ASCII(string))2000 while (string.pointer < string.capacity) 2001 { 2002 if (!IS_PRINTABLE(string) || (!emitter->is_unicode && !IS_ASCII(string)) 2023 2003 || IS_BOM(string) || IS_BREAK(string) 2024 2004 || CHECK(string, '"') || CHECK(string, '\\')) … … 2027 2007 unsigned int width; 2028 2008 unsigned int value; 2029 int k;2030 2031 octet = string.pointer[0];2009 int idx; 2010 2011 octet = OCTET(string); 2032 2012 width = (octet & 0x80) == 0x00 ? 1 : 2033 2013 (octet & 0xE0) == 0xC0 ? 2 : … … 2038 2018 (octet & 0xF0) == 0xE0 ? octet & 0x0F : 2039 2019 (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; 2040 for ( k = 1; k < (int)width; k++) {2041 octet = string.pointer[k];2020 for (idx = 1; idx < width; idx ++) { 2021 octet = OCTET_AT(string, idx); 2042 2022 value = (value << 6) + (octet & 0x3F); 2043 2023 } … … 2121 2101 width = 8; 2122 2102 } 2123 for ( k = (width-1)*4; k >= 0; k-= 4) {2124 int digit = (value >> k) & 0x0F;2103 for (idx = (width-1)*4; idx >= 0; idx -= 4) { 2104 int digit = (value >> idx) & 0x0F; 2125 2105 if (!PUT(emitter, digit + (digit < 10 ? '0' : 'A'-10))) 2126 2106 return 0; … … 2133 2113 if (allow_breaks && !spaces 2134 2114 && emitter->column > emitter->best_width 2135 && string.pointer != string.start2136 && string.pointer != string. end- 1) {2115 && string.pointer != 0 2116 && string.pointer != string.capacity - 1) { 2137 2117 if (!yaml_emitter_write_indent(emitter)) return 0; 2138 2118 if (IS_SPACE_AT(string, 1)) { … … 2156 2136 return 0; 2157 2137 2158 emitter-> whitespace = 0;2159 emitter->i ndention = 0;2138 emitter->is_whitespace = 0; 2139 emitter->is_indention = 0; 2160 2140 2161 2141 return 1; … … 2166 2146 yaml_string_t string) 2167 2147 { 2168 string.pointer = string. end;2169 if ( string.start ==string.pointer)2148 string.pointer = string.capacity; 2149 if (!string.pointer) 2170 2150 return -1; 2171 2151 do { 2172 2152 string.pointer --; 2173 } while (( *string.pointer& 0xC0) == 0x80);2153 } while ((OCTET(string) & 0xC0) == 0x80); 2174 2154 if (!IS_BREAK(string)) 2175 2155 return -1; 2176 if ( string.start ==string.pointer)2156 if (!string.pointer) 2177 2157 return 0; 2178 2158 do { 2179 2159 string.pointer --; 2180 } while (( *string.pointer& 0xC0) == 0x80);2160 } while ((OCTET(string) & 0xC0) == 0x80); 2181 2161 if (!IS_BREAK(string)) 2182 2162 return 0; … … 2199 2179 return 0; 2200 2180 2201 while (string.pointer != string.end)2181 while (string.pointer < string.capacity) 2202 2182 { 2203 2183 if (IS_BREAK(string)) 2204 2184 { 2205 2185 if (!WRITE_BREAK(emitter, string)) return 0; 2206 emitter->i ndention = 1;2186 emitter->is_indention = 1; 2207 2187 breaks = 1; 2208 2188 } … … 2213 2193 } 2214 2194 if (!WRITE(emitter, string)) return 0; 2215 emitter->i ndention = 0;2195 emitter->is_indention = 0; 2216 2196 breaks = 0; 2217 2197 } … … 2236 2216 return 0; 2237 2217 2238 while (string.pointer != string.end)2218 while (string.pointer < string.capacity) 2239 2219 { 2240 2220 if (IS_BREAK(string)) … … 2250 2230 } 2251 2231 if (!WRITE_BREAK(emitter, string)) return 0; 2252 emitter->i ndention = 1;2232 emitter->is_indention = 1; 2253 2233 breaks = 1; 2254 2234 } … … 2267 2247 if (!WRITE(emitter, string)) return 0; 2268 2248 } 2269 emitter->i ndention = 0;2249 emitter->is_indention = 0; 2270 2250 breaks = 0; 2271 2251 } -
libyaml/trunk/src/loader.c
r243 r263 1 1 2 2 #include "yaml_private.h" 3 4 #if 0 3 5 4 6 /* … … 429 431 } 430 432 433 #endif 434 -
libyaml/trunk/src/parser.c
r250 r263 47 47 48 48 #define PEEK_TOKEN(parser) \ 49 ((parser-> token_available || yaml_parser_fetch_more_tokens(parser)) ?\50 parser->tokens. head : NULL)49 ((parser->is_token_available || yaml_parser_fetch_more_tokens(parser)) ? \ 50 parser->tokens.list + parser->tokens.head : NULL) 51 51 52 52 /* … … 55 55 56 56 #define SKIP_TOKEN(parser) \ 57 (parser-> token_available = 0,\57 (parser->is_token_available = 0, \ 58 58 parser->tokens_parsed ++, \ 59 parser-> stream_end_produced =\60 (parser->tokens. head->type == YAML_STREAM_END_TOKEN),\59 parser->is_stream_end_produced = \ 60 (parser->tokens.list[parser->tokens.head].type == YAML_STREAM_END_TOKEN), \ 61 61 parser->tokens.head ++) 62 62 … … 69 69 70 70 /* 71 * Error handling.72 */73 74 static int75 yaml_parser_set_parser_error(yaml_parser_t *parser,76 const char *problem, yaml_mark_t problem_mark);77 78 static int79 yaml_parser_set_parser_error_context(yaml_parser_t *parser,80 const char *context, yaml_mark_t context_mark,81 const char *problem, yaml_mark_t problem_mark);82 83 /*84 71 * State functions. 85 72 */ … … 156 143 yaml_parser_process_directives(yaml_parser_t *parser, 157 144 yaml_version_directive_t **version_directive_ref, 158 yaml_tag_directive_t **tag_directives_start_ref, 159 yaml_tag_directive_t **tag_directives_end_ref); 145 yaml_tag_directive_t **tag_directives_list_ref, 146 size_t *tag_directives_length_ref, 147 size_t *tag_directives_capacity_ref); 160 148 161 149 static int … … 179 167 /* No events after the end of the stream or error. */ 180 168 181 if (parser-> stream_end_produced || parser->error ||182 parser->state == YAML_PARSE_END_STATE) {169 if (parser->is_stream_end_produced || parser->error.type 170 || parser->state == YAML_PARSE_END_STATE) { 183 171 return 1; 184 172 } … … 188 176 return yaml_parser_state_machine(parser, event); 189 177 } 190 191 /*192 * Set parser error.193 */194 195 static int196 yaml_parser_set_parser_error(yaml_parser_t *parser,197 const char *problem, yaml_mark_t problem_mark)198 {199 parser->error = YAML_PARSER_ERROR;200 parser->problem = problem;201 parser->problem_mark = problem_mark;202 203 return 0;204 }205 206 static int207 yaml_parser_set_parser_error_context(yaml_parser_t *parser,208 const char *context, yaml_mark_t context_mark,209 const char *problem, yaml_mark_t problem_mark)210 {211 parser->error = YAML_PARSER_ERROR;212 parser->context = context;213 parser->context_mark = context_mark;214 parser->problem = problem;215 parser->problem_mark = problem_mark;216 217 return 0;218 }219 220 178 221 179 /* … … 319 277 320 278 if (token->type != YAML_STREAM_START_TOKEN) { 321 return yaml_parser_set_parser_error(parser,279 return PARSER_ERROR_INIT(parser, 322 280 "did not found expected <stream-start>", token->start_mark); 323 281 } … … 346 304 yaml_version_directive_t *version_directive = NULL; 347 305 struct { 348 yaml_tag_directive_t *start; 349 yaml_tag_directive_t *end; 350 } tag_directives = { NULL, NULL }; 306 yaml_tag_directive_t *list; 307 size_t length; 308 size_t capacity; 309 } tag_directives = { NULL, 0, 0 }; 351 310 352 311 token = PEEK_TOKEN(parser); … … 371 330 token->type != YAML_STREAM_END_TOKEN) 372 331 { 373 if (!yaml_parser_process_directives(parser, NULL, NULL, NULL ))332 if (!yaml_parser_process_directives(parser, NULL, NULL, NULL, NULL)) 374 333 return 0; 375 334 if (!PUSH(parser, parser->states, YAML_PARSE_DOCUMENT_END_STATE)) 376 335 return 0; 377 336 parser->state = YAML_PARSE_BLOCK_NODE_STATE; 378 DOCUMENT_START_EVENT_INIT(*event, NULL, NULL, NULL, 1,337 DOCUMENT_START_EVENT_INIT(*event, NULL, NULL, 0, 0, 1, 379 338 token->start_mark, token->start_mark); 380 339 return 1; … … 388 347 start_mark = token->start_mark; 389 348 if (!yaml_parser_process_directives(parser, &version_directive, 390 &tag_directives.start, &tag_directives.end)) 349 &tag_directives.list, &tag_directives.length, 350 &tag_directives.capacity)) 391 351 return 0; 392 352 token = PEEK_TOKEN(parser); 393 353 if (!token) goto error; 394 354 if (token->type != YAML_DOCUMENT_START_TOKEN) { 395 yaml_parser_set_parser_error(parser,355 PARSER_ERROR_INIT(parser, 396 356 "did not found expected <document start>", token->start_mark); 397 357 goto error; … … 402 362 end_mark = token->end_mark; 403 363 DOCUMENT_START_EVENT_INIT(*event, version_directive, 404 tag_directives.start, tag_directives.end, 0, 364 tag_directives.list, tag_directives.length, 365 tag_directives.capacity, 0, 405 366 start_mark, end_mark); 406 367 SKIP_TOKEN(parser); 407 368 version_directive = NULL; 408 tag_directives.start = tag_directives.end = NULL; 369 tag_directives.list = NULL; 370 tag_directives.length = tag_directives.capacity = 0; 409 371 return 1; 410 372 } … … 422 384 error: 423 385 yaml_free(version_directive); 424 while ( tag_directives.start != tag_directives.end) {425 yaml_ free(tag_directives.end[-1].handle);426 yaml_free(tag_directive s.end[-1].prefix);427 tag_directives.end --;428 } 429 yaml_free(tag_directives.start);386 while (!STACK_EMPTY(parser, tag_directives)) { 387 yaml_tag_directive_t tag_directive = POP(parser, tag_directives); 388 yaml_free(tag_directive.handle); 389 yaml_free(tag_directive.prefix); 390 } 391 STACK_DEL(parser, tag_directives); 430 392 return 0; 431 393 } … … 599 561 } 600 562 else { 601 yaml_tag_directive_t *tag_directive; 602 for (tag_directive = parser->tag_directives.start; 603 tag_directive != parser->tag_directives.top; 604 tag_directive ++) { 563 int idx; 564 for (idx = 0; idx < parser->tag_directives.length; idx++) { 565 yaml_tag_directive_t *tag_directive = parser->tag_directives.list + idx; 605 566 if (strcmp((char *)tag_directive->handle, (char *)tag_handle) == 0) { 606 567 size_t prefix_len = strlen((char *)tag_directive->prefix); … … 608 569 tag = yaml_malloc(prefix_len+suffix_len+1); 609 570 if (!tag) { 610 parser->error = YAML_MEMORY_ERROR;571 MEMORY_ERROR_INIT(parser); 611 572 goto error; 612 573 } … … 621 582 } 622 583 if (!tag) { 623 yaml_parser_set_parser_error_context(parser,584 PARSER_ERROR_WITH_CONTEXT_INIT(parser, 624 585 "while parsing a node", start_mark, 625 586 "found undefined tag handle", tag_mark); … … 688 649 yaml_char_t *value = yaml_malloc(1); 689 650 if (!value) { 690 parser->error = YAML_MEMORY_ERROR;651 MEMORY_ERROR_INIT(parser); 691 652 goto error; 692 653 } … … 699 660 } 700 661 else { 701 yaml_parser_set_parser_error_context(parser,662 PARSER_ERROR_WITH_CONTEXT_INIT(parser, 702 663 (block ? "while parsing a block node" 703 664 : "while parsing a flow node"), start_mark, … … 770 731 else 771 732 { 772 return yaml_parser_set_parser_error_context(parser,733 return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 773 734 "while parsing a block collection", POP(parser, parser->marks), 774 735 "did not found expected '-' indicator", token->start_mark); … … 880 841 else 881 842 { 882 return yaml_parser_set_parser_error_context(parser,843 return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 883 844 "while parsing a block mapping", POP(parser, parser->marks), 884 845 "did not found expected key", token->start_mark); … … 974 935 } 975 936 else { 976 return yaml_parser_set_parser_error_context(parser,937 return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 977 938 "while parsing a flow sequence", POP(parser, parser->marks), 978 939 "did not found expected ',' or ']'", token->start_mark); … … 1126 1087 } 1127 1088 else { 1128 return yaml_parser_set_parser_error_context(parser,1089 return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 1129 1090 "while parsing a flow mapping", POP(parser, parser->marks), 1130 1091 "did not found expected ',' or '}'", token->start_mark); … … 1215 1176 value = yaml_malloc(1); 1216 1177 if (!value) { 1217 parser->error = YAML_MEMORY_ERROR; 1218 return 0; 1178 return MEMORY_ERROR_INIT(parser); 1219 1179 } 1220 1180 value[0] = '\0'; … … 1233 1193 yaml_parser_process_directives(yaml_parser_t *parser, 1234 1194 yaml_version_directive_t **version_directive_ref, 1235 yaml_tag_directive_t **tag_directives_start_ref, 1236 yaml_tag_directive_t **tag_directives_end_ref) 1195 yaml_tag_directive_t **tag_directives_list_ref, 1196 size_t *tag_directives_length_ref, 1197 size_t *tag_directives_capacity_ref) 1237 1198 { 1238 1199 yaml_tag_directive_t default_tag_directives[] = { … … 1244 1205 yaml_version_directive_t *version_directive = NULL; 1245 1206 struct { 1246 yaml_tag_directive_t * start;1247 yaml_tag_directive_t *end;1248 yaml_tag_directive_t *top;1249 } tag_directives = { NULL, NULL, NULL};1250 yaml_token_t *token; 1251 1252 if (!STACK_INIT(parser, tag_directives, INITIAL_STACK_ SIZE))1207 yaml_tag_directive_t *list; 1208 size_t length; 1209 size_t capacity; 1210 } tag_directives = { NULL, 0, 0 }; 1211 yaml_token_t *token; 1212 1213 if (!STACK_INIT(parser, tag_directives, INITIAL_STACK_CAPACITY)) 1253 1214 goto error; 1254 1215 … … 1261 1222 if (token->type == YAML_VERSION_DIRECTIVE_TOKEN) { 1262 1223 if (version_directive) { 1263 yaml_parser_set_parser_error(parser,1224 PARSER_ERROR_INIT(parser, 1264 1225 "found duplicate %YAML directive", token->start_mark); 1265 1226 goto error; … … 1267 1228 if (token->data.version_directive.major != 1 1268 1229 || token->data.version_directive.minor != 1) { 1269 yaml_parser_set_parser_error(parser,1230 PARSER_ERROR_INIT(parser, 1270 1231 "found incompatible YAML document", token->start_mark); 1271 1232 goto error; … … 1273 1234 version_directive = yaml_malloc(sizeof(yaml_version_directive_t)); 1274 1235 if (!version_directive) { 1275 parser->error = YAML_MEMORY_ERROR;1236 MEMORY_ERROR_INIT(parser); 1276 1237 goto error; 1277 1238 } … … 1307 1268 *version_directive_ref = version_directive; 1308 1269 } 1309 if (tag_directives_ start_ref) {1270 if (tag_directives_list_ref) { 1310 1271 if (STACK_EMPTY(parser, tag_directives)) { 1311 *tag_directives_start_ref = *tag_directives_end_ref = NULL; 1272 *tag_directives_list_ref = NULL; 1273 *tag_directives_length_ref = 0; 1274 *tag_directives_capacity_ref = 0; 1312 1275 STACK_DEL(parser, tag_directives); 1313 1276 } 1314 1277 else { 1315 *tag_directives_start_ref = tag_directives.start; 1316 *tag_directives_end_ref = tag_directives.top; 1278 *tag_directives_list_ref = tag_directives.list; 1279 *tag_directives_length_ref = tag_directives.length; 1280 *tag_directives_capacity_ref = tag_directives.capacity; 1317 1281 } 1318 1282 } … … 1344 1308 yaml_tag_directive_t *tag_directive; 1345 1309 yaml_tag_directive_t copy = { NULL, NULL }; 1346 1347 for (tag_directive = parser->tag_directives.start; 1348 tag_directive != parser->tag_directives.top; tag_directive ++) { 1310 int idx; 1311 1312 for (idx = 0; idx < parser->tag_directives.length; idx++) { 1313 yaml_tag_directive_t *tag_directive = parser->tag_directives.list + idx; 1349 1314 if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { 1350 1315 if (allow_duplicates) 1351 1316 return 1; 1352 return yaml_parser_set_parser_error(parser,1317 return PARSER_ERROR_INIT(parser, 1353 1318 "found duplicate %TAG directive", mark); 1354 1319 } … … 1358 1323 copy.prefix = yaml_strdup(value.prefix); 1359 1324 if (!copy.handle || !copy.prefix) { 1360 parser->error = YAML_MEMORY_ERROR;1325 MEMORY_ERROR_INIT(parser); 1361 1326 goto error; 1362 1327 } -
libyaml/trunk/src/reader.c
r262 r263 36 36 /* Ensure that we had enough bytes in the raw buffer. */ 37 37 38 while (!parser->is_eof && parser->raw_input. length< 3) {38 while (!parser->is_eof && parser->raw_input.capacity < 3) { 39 39 if (!yaml_parser_update_raw_buffer(parser)) { 40 40 return 0; … … 44 44 /* Determine the encoding. */ 45 45 46 if (parser->raw_input. length>= 246 if (parser->raw_input.capacity >= 2 47 47 && !memcmp(parser->raw_input.buffer, BOM_UTF16LE, 2)) { 48 48 parser->encoding = YAML_UTF16LE_ENCODING; … … 50 50 parser->offset = 2; 51 51 } 52 else if (parser->raw_input. length>= 252 else if (parser->raw_input.capacity >= 2 53 53 && !memcmp(parser->raw_input.buffer, BOM_UTF16BE, 2)) { 54 54 parser->encoding = YAML_UTF16BE_ENCODING; … … 56 56 parser->offset = 2; 57 57 } 58 else if (parser->raw_input. length>= 358 else if (parser->raw_input.capacity >= 3 59 59 && !memcmp(parser->raw_input.buffer, BOM_UTF8, 3)) { 60 60 parser->encoding = YAML_UTF8_ENCODING; … … 81 81 82 82 if (parser->raw_input.pointer == 0 && 83 parser->raw_input. length == parser->raw_input.capacity)83 parser->raw_input.capacity == RAW_INPUT_BUFFER_CAPACITY) 84 84 return 1; 85 85 … … 92 92 93 93 if (parser->raw_input.pointer > 0 && 94 parser->raw_input.pointer < parser->raw_input. length) {94 parser->raw_input.pointer < parser->raw_input.capacity) { 95 95 memmove(parser->raw_input.buffer, 96 96 parser->raw_input.buffer + parser->raw_input.pointer, 97 parser->raw_input.length - parser->raw_input.pointer); 98 } 97 parser->raw_input.capacity - parser->raw_input.pointer); 98 } 99 parser->raw_input.capacity -= parser->raw_input.pointer; 99 100 parser->raw_input.pointer = 0; 100 101 … … 102 103 103 104 if (!parser->reader(parser->reader_data, 104 parser->raw_input.buffer + parser->raw_input. length,105 parser->raw_input.capacity - parser->raw_input.length,105 parser->raw_input.buffer + parser->raw_input.capacity, 106 RAW_INPUT_BUFFER_CAPACITY - parser->raw_input.capacity, 106 107 &length)) { 107 108 return READER_ERROR_INIT(parser, "Input error", parser->offset); 108 109 } 109 parser->raw_input. length+= length;110 parser->raw_input.capacity += length; 110 111 if (!length) { 111 112 parser->is_eof = 1; … … 125 126 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) 126 127 { 128 size_t old_capacity; 129 127 130 assert(parser->reader); /* Read handler must be set. */ 128 131 129 132 /* If the EOF flag is set and the raw buffer is empty, do nothing. */ 130 133 131 if (parser->is_eof && parser->raw_input.pointer == parser->raw_input. length)134 if (parser->is_eof && parser->raw_input.pointer == parser->raw_input.capacity) 132 135 return 1; 133 136 … … 147 150 148 151 if (parser->input.pointer > 0 && 149 parser->input.pointer < parser->input. length) {152 parser->input.pointer < parser->input.capacity) { 150 153 memmove(parser->input.buffer, 151 154 parser->input.buffer + parser->input.pointer, 152 parser->input.length - parser->input.pointer); 153 parser->input.length -= parser->input.pointer; 154 parser->input.pointer = 0; 155 } 156 else if (parser->input.pointer == parser->input.length) { 157 parser->input.pointer = parser->input.length = 0; 158 } 155 parser->input.capacity - parser->input.pointer); 156 parser->input.capacity -= parser->input.pointer; 157 } 158 else if (parser->input.pointer == parser->input.capacity) { 159 parser->input.capacity = 0; 160 } 161 162 /* Set the pointer to the end of the buffer. */ 163 164 parser->input.pointer = parser->input.capacity; 159 165 160 166 /* Fill the buffer until it has enough characters. */ … … 168 174 /* Decode the raw buffer. */ 169 175 170 while (parser->raw_input.pointer != parser->raw_input. length)176 while (parser->raw_input.pointer != parser->raw_input.capacity) 171 177 { 172 unsigned char *raw_buffer =173 parser->raw_input.buffer + parser->raw_input.pointer;174 178 size_t raw_unread = 175 parser->raw_input. length- parser->raw_input.pointer;179 parser->raw_input.capacity - parser->raw_input.pointer; 176 180 unsigned int value = 0, value2 = 0; 177 181 int is_incomplete = 0; … … 179 183 unsigned int width = 0; 180 184 int low, high; 181 size_t k;185 size_t idx; 182 186 183 187 /* Decode the next character. */ … … 209 213 /* Determine the length of the UTF-8 sequence. */ 210 214 211 octet = *raw_buffer;215 octet = OCTET(parser->raw_input); 212 216 width = (octet & 0x80) == 0x00 ? 1 : 213 217 (octet & 0xE0) == 0xC0 ? 2 : … … 243 247 /* Check and decode the trailing octets. */ 244 248 245 for ( k = 1; k < width; k++)249 for (idx = 1; idx < width; idx ++) 246 250 { 247 octet = raw_buffer[k];251 octet = OCTET_AT(parser->raw_input, idx); 248 252 249 253 /* Check if the octet is valid. */ … … 252 256 return DECODER_ERROR_INIT(parser, 253 257 "Invalid trailing UTF-8 octet", 254 parser->offset+ k, octet);258 parser->offset+idx, octet); 255 259 256 260 /* Decode the octet. */ … … 324 328 /* Get the character. */ 325 329 326 value = raw_buffer[low] + (raw_buffer[high] << 8); 330 value = OCTET_AT(parser->raw_input, low) 331 + (OCTET_AT(parser->raw_input, high) << 8); 327 332 328 333 /* Check for unexpected low surrogate area. */ … … 353 358 /* Get the next character. */ 354 359 355 value2 = raw_buffer[low+2] + (raw_buffer[high+2] << 8); 360 value2 = OCTET_AT(parser->raw_input, low+2) 361 + (OCTET_AT(parser->raw_input, high+2) << 8); 356 362 357 363 /* Check for a low surrogate area. */ … … 407 413 /* 0000 0000-0000 007F -> 0xxxxxxx */ 408 414 if (value <= 0x7F) { 409 parser->input.buffer[parser->input.length++] = value;415 JOIN_OCTET(parser->input, value); 410 416 } 411 417 /* 0000 0080-0000 07FF -> 110xxxxx 10xxxxxx */ 412 418 else if (value <= 0x7FF) { 413 parser->input.buffer[parser->input.length++] = 0xC0 + (value >> 6);414 parser->input.buffer[parser->input.length++] = 0x80 + (value & 0x3F);419 JOIN_OCTET(parser->input, 0xC0 + (value >> 6)); 420 JOIN_OCTET(parser->input, 0x80 + (value & 0x3F)); 415 421 } 416 422 /* 0000 0800-0000 FFFF -> 1110xxxx 10xxxxxx 10xxxxxx */ 417 423 else if (value <= 0xFFFF) { 418 parser->input.buffer[parser->input.length++] = 0xE0 + (value >> 12);419 parser->input.buffer[parser->input.length++] = 0x80 + ((value >> 6) & 0x3F);420 parser->input.buffer[parser->input.length++] = 0x80 + (value & 0x3F);424 JOIN_OCTET(parser->input, 0xE0 + (value >> 12)); 425 JOIN_OCTET(parser->input, 0x80 + ((value >> 6) & 0x3F)); 426 JOIN_OCTET(parser->input, 0x80 + (value & 0x3F)); 421 427 } 422 428 /* 0001 0000-0010 FFFF -> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ 423 429 else { 424 parser->input.buffer[parser->input.length++] = 0xF0 + (value >> 18);425 parser->input.buffer[parser->input.length++] = 0x80 + ((value >> 12) & 0x3F);426 parser->input.buffer[parser->input.length++] = 0x80 + ((value >> 6) & 0x3F);427 parser->input.buffer[parser->input.length++] = 0x80 + (value & 0x3F);430 JOIN_OCTET(parser->input, 0xF0 + (value >> 18)); 431 JOIN_OCTET(parser->input, 0x80 + ((value >> 12) & 0x3F)); 432 JOIN_OCTET(parser->input, 0x80 + ((value >> 6) & 0x3F)); 433 JOIN_OCTET(parser->input, 0x80 + (value & 0x3F)); 428 434 } 429 435 … … 431 437 } 432 438 433 /* On EOF, put NUL into the buffer and return. */439 /* On EOF, put NUL into the buffer and stop. */ 434 440 435 441 if (parser->is_eof) { 436 parser->input.buffer[parser->input.length++] = '\0';442 JOIN_OCTET(parser->input, '\0'); 437 443 parser->unread ++; 438 return 1;444 break; 439 445 } 440 446 441 447 } 448 /* Swap the pointer with the end of the buffer. */ 449 450 old_capacity = parser->input.capacity; 451 parser->input.capacity = parser->input.pointer; 452 parser->input.pointer = old_capacity; 442 453 443 454 return 1; -
libyaml/trunk/src/scanner.c
r243 r263 496 496 parser->mark.column ++, \ 497 497 parser->unread --, \ 498 parser-> buffer.pointer += WIDTH(parser->buffer))498 parser->input.pointer += WIDTH(parser->input)) 499 499 500 500 #define SKIP_LINE(parser) \ 501 (IS_CRLF(parser-> buffer) ?\501 (IS_CRLF(parser->input) ? \ 502 502 (parser->mark.index += 2, \ 503 503 parser->mark.column = 0, \ 504 504 parser->mark.line ++, \ 505 505 parser->unread -= 2, \ 506 parser-> buffer.pointer += 2) :\507 IS_BREAK(parser-> buffer) ?\506 parser->input.pointer += 2) : \ 507 IS_BREAK(parser->input) ? \ 508 508 (parser->mark.index ++, \ 509 509 parser->mark.column = 0, \ 510 510 parser->mark.line ++, \ 511 511 parser->unread --, \ 512 parser-> buffer.pointer += WIDTH(parser->buffer)) : 0)512 parser->input.pointer += WIDTH(parser->input)) : 0) 513 513 514 514 /* … … 518 518 #define READ(parser,string) \ 519 519 (STRING_EXTEND(parser,string) ? \ 520 (COPY(string,parser-> buffer),\520 (COPY(string,parser->input), \ 521 521 parser->mark.index ++, \ 522 522 parser->mark.column ++, \ … … 530 530 #define READ_LINE(parser,string) \ 531 531 (STRING_EXTEND(parser,string) ? \ 532 (((CHECK_AT(parser-> buffer,'\r',0)\533 && CHECK_AT(parser-> buffer,'\n',1)) ?/* CR LF -> LF */ \534 ( *((string).pointer++) = (yaml_char_t) '\n',\535 parser-> buffer.pointer += 2,\532 (((CHECK_AT(parser->input,'\r',0) \ 533 && CHECK_AT(parser->input,'\n',1)) ? /* CR LF -> LF */ \ 534 (JOIN_OCTET(string, (yaml_char_t) '\n'), \ 535 parser->input.pointer += 2, \ 536 536 parser->mark.index += 2, \ 537 537 parser->mark.column = 0, \ 538 538 parser->mark.line ++, \ 539 539 parser->unread -= 2) : \ 540 (CHECK_AT(parser-> buffer,'\r',0)\541 || CHECK_AT(parser-> buffer,'\n',0)) ?/* CR|LF -> LF */ \542 ( *((string).pointer++) = (yaml_char_t) '\n',\543 parser-> buffer.pointer ++,\540 (CHECK_AT(parser->input,'\r',0) \ 541 || CHECK_AT(parser->input,'\n',0)) ? /* CR|LF -> LF */ \ 542 (JOIN_OCTET(string,(yaml_char_t) '\n'), \ 543 parser->input.pointer ++, \ 544 544 parser->mark.index ++, \ 545 545 parser->mark.column = 0, \ 546 546 parser->mark.line ++, \ 547 547 parser->unread --) : \ 548 (CHECK_AT(parser-> buffer,'\xC2',0)\549 && CHECK_AT(parser-> buffer,'\x85',1)) ?/* NEL -> LF */ \550 ( *((string).pointer++) = (yaml_char_t) '\n',\551 parser-> buffer.pointer += 2,\548 (CHECK_AT(parser->input,'\xC2',0) \ 549 && CHECK_AT(parser->input,'\x85',1)) ? /* NEL -> LF */ \ 550 (JOIN_OCTET(string,(yaml_char_t) '\n'), \ 551 parser->input.pointer += 2, \ 552 552 parser->mark.index ++, \ 553 553 parser->mark.column = 0, \ 554 554 parser->mark.line ++, \ 555 555 parser->unread --) : \ 556 (CHECK_AT(parser-> buffer,'\xE2',0) &&\557 CHECK_AT(parser-> buffer,'\x80',1) &&\558 (CHECK_AT(parser-> buffer,'\xA8',2) ||\559 CHECK_AT(parser-> buffer,'\xA9',2))) ?/* LS|PS -> LS|PS */ \560 ( *((string).pointer++) = *(parser->buffer.pointer++),\561 *((string).pointer++) = *(parser->buffer.pointer++),\562 *((string).pointer++) = *(parser->buffer.pointer++),\556 (CHECK_AT(parser->input,'\xE2',0) && \ 557 CHECK_AT(parser->input,'\x80',1) && \ 558 (CHECK_AT(parser->input,'\xA8',2) || \ 559 CHECK_AT(parser->input,'\xA9',2))) ? /* LS|PS -> LS|PS */ \ 560 (COPY_OCTET(string,parser->input), \ 561 COPY_OCTET(string,parser->input), \ 562 COPY_OCTET(string,parser->input), \ 563 563 parser->mark.index ++, \ 564 564 parser->mark.column = 0, \ … … 575 575 576 576 /* 577 * Error handling.578 */579 580 static int581 yaml_parser_set_scanner_error(yaml_parser_t *parser, const char *context,582 yaml_mark_t context_mark, const char *problem);583 584 /*585 577 * High-level token API. 586 578 */ … … 751 743 /* No tokens after STREAM-END or error. */ 752 744 753 if (parser-> stream_end_produced || parser->error) {745 if (parser->is_stream_end_produced || parser->error.type) { 754 746 return 1; 755 747 } … … 757 749 /* Ensure that the tokens queue contains enough tokens. */ 758 750 759 if (!parser-> token_available) {751 if (!parser->is_token_available) { 760 752 if (!yaml_parser_fetch_more_tokens(parser)) 761 753 return 0; … … 765 757 766 758 *token = DEQUEUE(parser, parser->tokens); 767 parser-> token_available = 0;759 parser->is_token_available = 0; 768 760 parser->tokens_parsed ++; 769 761 770 762 if (token->type == YAML_STREAM_END_TOKEN) { 771 parser->stream_end_produced = 1; 772 } 773 774 return 1; 775 } 776 777 /* 778 * Set the scanner error and return 0. 779 */ 780 781 static int 782 yaml_parser_set_scanner_error(yaml_parser_t *parser, const char *context, 783 yaml_mark_t context_mark, const char *problem) 784 { 785 parser->error = YAML_SCANNER_ERROR; 786 parser->context = context; 787 parser->context_mark = context_mark; 788 parser->problem = problem; 789 parser->problem_mark = parser->mark; 790 791 return 0; 763 parser->is_stream_end_produced = 1; 764 } 765 766 return 1; 792 767 } 793 768 … … 820 795 else 821 796 { 822 yaml_simple_key_t *simple_key;797 size_t idx; 823 798 824 799 /* Check if any potential simple key may occupy the head position. */ … … 827 802 return 0; 828 803 829 for ( simple_key = parser->simple_keys.start;830 simple_key != parser->simple_keys.top; simple_key++) {831 if (simple_key-> possible804 for (idx = 0; idx < parser->simple_keys.length; idx++) { 805 yaml_simple_key_t *simple_key = parser->simple_keys.list + idx; 806 if (simple_key->is_possible 832 807 && simple_key->token_number == parser->tokens_parsed) { 833 808 need_more_tokens = 1; … … 848 823 } 849 824 850 parser-> token_available = 1;825 parser->is_token_available = 1; 851 826 852 827 return 1; … … 860 835 yaml_parser_fetch_next_token(yaml_parser_t *parser) 861 836 { 837 yaml_mark_t start_mark = parser->mark; 838 862 839 /* Ensure that the buffer is initialized. */ 863 840 … … 867 844 /* Check if we just started scanning. Fetch STREAM-START then. */ 868 845 869 if (!parser-> stream_start_produced)846 if (!parser->is_stream_start_produced) 870 847 return yaml_parser_fetch_stream_start(parser); 871 848 … … 895 872 /* Is it the end of the stream? */ 896 873 897 if (IS_Z(parser-> buffer))874 if (IS_Z(parser->input)) 898 875 return yaml_parser_fetch_stream_end(parser); 899 876 900 877 /* Is it a directive? */ 901 878 902 if (parser->mark.column == 0 && CHECK(parser-> buffer, '%'))879 if (parser->mark.column == 0 && CHECK(parser->input, '%')) 903 880 return yaml_parser_fetch_directive(parser); 904 881 … … 906 883 907 884 if (parser->mark.column == 0 908 && CHECK_AT(parser-> buffer, '-', 0)909 && CHECK_AT(parser-> buffer, '-', 1)910 && CHECK_AT(parser-> buffer, '-', 2)911 && IS_BLANKZ_AT(parser-> buffer, 3))885 && CHECK_AT(parser->input, '-', 0) 886 && CHECK_AT(parser->input, '-', 1) 887 && CHECK_AT(parser->input, '-', 2) 888 && IS_BLANKZ_AT(parser->input, 3)) 912 889 return yaml_parser_fetch_document_indicator(parser, 913 890 YAML_DOCUMENT_START_TOKEN); … … 916 893 917 894 if (parser->mark.column == 0 918 && CHECK_AT(parser-> buffer, '.', 0)919 && CHECK_AT(parser-> buffer, '.', 1)920 && CHECK_AT(parser-> buffer, '.', 2)921 && IS_BLANKZ_AT(parser-> buffer, 3))895 && CHECK_AT(parser->input, '.', 0) 896 && CHECK_AT(parser->input, '.', 1) 897 && CHECK_AT(parser->input, '.', 2) 898 && IS_BLANKZ_AT(parser->input, 3)) 922 899 return yaml_parser_fetch_document_indicator(parser, 923 900 YAML_DOCUMENT_END_TOKEN); … … 925 902 /* Is it the flow sequence start indicator? */ 926 903 927 if (CHECK(parser-> buffer, '['))904 if (CHECK(parser->input, '[')) 928 905 return yaml_parser_fetch_flow_collection_start(parser, 929 906 YAML_FLOW_SEQUENCE_START_TOKEN); … … 931 908 /* Is it the flow mapping start indicator? */ 932 909 933 if (CHECK(parser-> buffer, '{'))910 if (CHECK(parser->input, '{')) 934 911 return yaml_parser_fetch_flow_collection_start(parser, 935 912 YAML_FLOW_MAPPING_START_TOKEN); … … 937 914 /* Is it the flow sequence end indicator? */ 938 915 939 if (CHECK(parser-> buffer, ']'))916 if (CHECK(parser->input, ']')) 940 917 return yaml_parser_fetch_flow_collection_end(parser, 941 918 YAML_FLOW_SEQUENCE_END_TOKEN); … … 943 920 /* Is it the flow mapping end indicator? */ 944 921 945 if (CHECK(parser-> buffer, '}'))922 if (CHECK(parser->input, '}')) 946 923 return yaml_parser_fetch_flow_collection_end(parser, 947 924 YAML_FLOW_MAPPING_END_TOKEN); … … 949 926 /* Is it the flow entry indicator? */ 950 927 951 if (CHECK(parser-> buffer, ','))928 if (CHECK(parser->input, ',')) 952 929 return yaml_parser_fetch_flow_entry(parser); 953 930 954 931 /* Is it the block entry indicator? */ 955 932 956 if (CHECK(parser-> buffer, '-') && IS_BLANKZ_AT(parser->buffer, 1))933 if (CHECK(parser->input, '-') && IS_BLANKZ_AT(parser->input, 1)) 957 934 return yaml_parser_fetch_block_entry(parser); 958 935 959 936 /* Is it the key indicator? */ 960 937 961 if (CHECK(parser-> buffer, '?')962 && (parser->flow_level || IS_BLANKZ_AT(parser-> buffer, 1)))938 if (CHECK(parser->input, '?') 939 && (parser->flow_level || IS_BLANKZ_AT(parser->input, 1))) 963 940 return yaml_parser_fetch_key(parser); 964 941 965 942 /* Is it the value indicator? */ 966 943 967 if (CHECK(parser-> buffer, ':')968 && (parser->flow_level || IS_BLANKZ_AT(parser-> buffer, 1)))944 if (CHECK(parser->input, ':') 945 && (parser->flow_level || IS_BLANKZ_AT(parser->input, 1))) 969 946 return yaml_parser_fetch_value(parser); 970 947 971 948 /* Is it an alias? */ 972 949 973 if (CHECK(parser-> buffer, '*'))950 if (CHECK(parser->input, '*')) 974 951 return yaml_parser_fetch_anchor(parser, YAML_ALIAS_TOKEN); 975 952 976 953 /* Is it an anchor? */ 977 954 978 if (CHECK(parser-> buffer, '&'))955 if (CHECK(parser->input, '&')) 979 956 return yaml_parser_fetch_anchor(parser, YAML_ANCHOR_TOKEN); 980 957 981 958 /* Is it a tag? */ 982 959 983 if (CHECK(parser-> buffer, '!'))960 if (CHECK(parser->input, '!')) 984 961 return yaml_parser_fetch_tag(parser); 985 962 986 963 /* Is it a literal scalar? */ 987 964 988 if (CHECK(parser-> buffer, '|') && !parser->flow_level)965 if (CHECK(parser->input, '|') && !parser->flow_level) 989 966 return yaml_parser_fetch_block_scalar(parser, 1); 990 967 991 968 /* Is it a folded scalar? */ 992 969 993 if (CHECK(parser-> buffer, '>') && !parser->flow_level)970 if (CHECK(parser->input, '>') && !parser->flow_level) 994 971 return yaml_parser_fetch_block_scalar(parser, 0); 995 972 996 973 /* Is it a single-quoted scalar? */ 997 974 998 if (CHECK(parser-> buffer, '\''))975 if (CHECK(parser->input, '\'')) 999 976 return yaml_parser_fetch_flow_scalar(parser, 1); 1000 977 1001 978 /* Is it a double-quoted scalar? */ 1002 979 1003 if (CHECK(parser-> buffer, '"'))980 if (CHECK(parser->input, '"')) 1004 981 return yaml_parser_fetch_flow_scalar(parser, 0); 1005 982 … … 1023 1000 */ 1024 1001 1025 if (!(IS_BLANKZ(parser-> buffer) || CHECK(parser->buffer, '-')1026 || CHECK(parser-> buffer, '?') || CHECK(parser->buffer, ':')1027 || CHECK(parser-> buffer, ',') || CHECK(parser->buffer, '[')1028 || CHECK(parser-> buffer, ']') || CHECK(parser->buffer, '{')1029 || CHECK(parser-> buffer, '}') || CHECK(parser->buffer, '#')1030 || CHECK(parser-> buffer, '&') || CHECK(parser->buffer, '*')1031 || CHECK(parser-> buffer, '!') || CHECK(parser->buffer, '|')1032 || CHECK(parser-> buffer, '>') || CHECK(parser->buffer, '\'')1033 || CHECK(parser-> buffer, '"') || CHECK(parser->buffer, '%')1034 || CHECK(parser-> buffer, '@') || CHECK(parser->buffer, '`')) ||1035 (CHECK(parser-> buffer, '-') && !IS_BLANK_AT(parser->buffer, 1)) ||1002 if (!(IS_BLANKZ(parser->input) || CHECK(parser->input, '-') 1003 || CHECK(parser->input, '?') || CHECK(parser->input, ':') 1004 || CHECK(parser->input, ',') || CHECK(parser->input, '[') 1005 || CHECK(parser->input, ']') || CHECK(parser->input, '{') 1006 || CHECK(parser->input, '}') || CHECK(parser->input, '#') 1007 || CHECK(parser->input, '&') || CHECK(parser->input, '*') 1008 || CHECK(parser->input, '!') || CHECK(parser->input, '|') 1009 || CHECK(parser->input, '>') || CHECK(parser->input, '\'') 1010 || CHECK(parser->input, '"') || CHECK(parser->input, '%') 1011 || CHECK(parser->input, '@') || CHECK(parser->input, '`')) || 1012 (CHECK(parser->input, '-') && !IS_BLANK_AT(parser->input, 1)) || 1036 1013 (!parser->flow_level && 1037 (CHECK(parser-> buffer, '?') || CHECK(parser->buffer, ':'))1038 && !IS_BLANKZ_AT(parser-> buffer, 1)))1014 (CHECK(parser->input, '?') || CHECK(parser->input, ':')) 1015 && !IS_BLANKZ_AT(parser->input, 1))) 1039 1016 return yaml_parser_fetch_plain_scalar(parser); 1040 1017 … … 1043 1020 */ 1044 1021 1045 return yaml_parser_set_scanner_error(parser,1046 "while scanning for the next token", parser->mark,1047 "found character that cannot start any token" );1022 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 1023 "while scanning for the next token", start_mark, 1024 "found character that cannot start any token", parser->mark); 1048 1025 } 1049 1026 … … 1056 1033 yaml_parser_stale_simple_keys(yaml_parser_t *parser) 1057 1034 { 1058 yaml_simple_key_t *simple_key;1035 size_t idx; 1059 1036 1060 1037 /* Check for a potential simple key for each flow level. */ 1061 1038 1062 for (simple_key = parser->simple_keys.start; 1063 simple_key != parser->simple_keys.top; simple_key ++) 1039 for (idx = 0; idx < parser->simple_keys.length; idx ++) 1064 1040 { 1041 yaml_simple_key_t *simple_key = parser->simple_keys.list + idx; 1042 1065 1043 /* 1066 1044 * The specification requires that a simple key … … 1070 1048 */ 1071 1049 1072 if (simple_key-> possible1050 if (simple_key->is_possible 1073 1051 && (simple_key->mark.line < parser->mark.line 1074 1052 || simple_key->mark.index+1024 < parser->mark.index)) { … … 1076 1054 /* Check if the potential simple key to be removed is required. */ 1077 1055 1078 if (simple_key-> required) {1079 return yaml_parser_set_scanner_error(parser,1056 if (simple_key->is_required) { 1057 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 1080 1058 "while scanning a simple key", simple_key->mark, 1081 "could not found expected ':'" );1059 "could not found expected ':'", parser->mark); 1082 1060 } 1083 1061 1084 simple_key-> possible = 0;1062 simple_key->is_possible = 0; 1085 1063 } 1086 1064 } … … 1103 1081 */ 1104 1082 1105 int required = (!parser->flow_level1083 int is_required = (!parser->flow_level 1106 1084 && parser->indent == (int)parser->mark.column); 1107 1085 … … 1111 1089 */ 1112 1090 1113 assert(parser-> simple_key_allowed || !required);/* Impossible. */1091 assert(parser->is_simple_key_allowed || !is_required); /* Impossible. */ 1114 1092 1115 1093 /* … … 1117 1095 */ 1118 1096 1119 if (parser-> simple_key_allowed)1097 if (parser->is_simple_key_allowed) 1120 1098 { 1121 yaml_simple_key_t simple_key = { 1, required,1099 yaml_simple_key_t simple_key = { 1, is_required, 1122 1100 parser->tokens_parsed + parser->tokens.tail - parser->tokens.head, 1123 1101 { 0, 0, 0 } }; … … 1126 1104 if (!yaml_parser_remove_simple_key(parser)) return 0; 1127 1105 1128 *(parser->simple_keys.top-1)= simple_key;1106 parser->simple_keys.list[parser->simple_keys.length-1] = simple_key; 1129 1107 } 1130 1108 … … 1139 1117 yaml_parser_remove_simple_key(yaml_parser_t *parser) 1140 1118 { 1141 yaml_simple_key_t *simple_key = parser->simple_keys.top-1; 1142 1143 if (simple_key->possible) 1119 yaml_simple_key_t *simple_key = 1120 parser->simple_keys.list + parser->simple_keys.length - 1; 1121 1122 if (simple_key->is_possible) 1144 1123 { 1145 1124 /* If the key is required, it is an error. */ 1146 1125 1147 if (simple_key-> required) {1148 return yaml_parser_set_scanner_error(parser,1126 if (simple_key->is_required) { 1127 return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 1149 1128 "while scanning a simple key", simple_key->mark, 1150 "could not found expected ':'" );1129 "could not found expected ':'", parser->mark); 1151 1130 } 1152 1131 } … … 1154 1133 /* Remove the key from the stack. */ 1155 1134 1156 simple_key-> possible = 0;1135 simple_key->is_possible = 0; 1157 1136 1158 1137 return 1; … … 1302 1281 /* A simple key is allowed at the beginning of the stream. */ 1303 1282 1304 parser-> simple_key_allowed = 1;1283 parser->is_simple_key_allowed = 1; 1305 1284 1306 1285 /* We have started. */ 1307 1286 1308 parser-> stream_start_produced = 1;1287 parser->is_stream_start_produced = 1; 1309 1288 1310 1289 /* Create the STREAM-START token and append it to the queue. */ … … 1345 1324 return 0; 1346 1325 1347 parser-> simple_key_allowed = 0;1326 parser->is_simple_key_allowed = 0; 1348 1327 1349 1328 /* Create the STREAM-END token and append it to the queue. */ … … 1376 1355 return 0; 1377 1356 1378 parser-> simple_key_allowed = 0;1357 parser->is_simple_key_allowed = 0; 1379 1358 1380 1359 /* Create the YAML-DIRECTIVE or TAG-DIRECTIVE token. */ … … 1414 1393 return 0; 1415 1394 1416 parser-> simple_key_allowed = 0;1395 parser->is_simple_key_allowed = 0; 1417 1396 1418 1397 /* Consume the token. */ … … 1461 1440 /* A simple key may follow the indicators '[' and '{'. */ 1462 1441 1463 parser-> simple_key_allowed = 1;1442 parser->is_simple_key_allowed = 1; 1464 1443 1465 1444 /* Consume the token. */ … … 1504 1483 /* No simple keys after the indicators ']' and '}'. */ 1505 1484 1506 parser-> simple_key_allowed = 0;1485 parser->is_simple_key_allowed = 0; 1507 1486 1508 1487 /* Consume the token. */ … … 1541 1520 /* Simple keys are allowed after ','. */ 1542 1521 1543 parser-> simple_key_allowed = 1;1522 parser->is_simple_key_allowed = 1; 1544 1523 1545 1524 /* Consume the token. */ … … 1575 1554 /* Check if we are allowed to start a new entry. */ 1576 1555 1577 if (!parser->simple_key_allowed) { 1578 return yaml_parser_set_scanner_error(parser, NULL, parser->mark, 1579 "block sequence entries are not allowed in this context"); 1556 if (!parser->is_simple_key_allowed) { 1557 return SCANNER_ERROR_INIT(parser, 1558 "block sequence entries are not allowed in this context", 1559 parser->mark); 1580 1560 } 1581 1561 … … 1602 1582 /* Simple keys are allowed after '-'. */ 1603 1583 1604 parser-> simple_key_allowed = 1;1584 parser->is_simple_key_allowed = 1; 1605 1585 1606 1586 /* Consume the token. */ … … 1636 1616 /* Check if we are allowed to start a new key (not nessesary simple). */ 1637 1617 1638 if (!parser-> simple_key_allowed) {1639 return yaml_parser_set_scanner_error(parser, NULL, parser->mark,1640 "mapping keys are not allowed in this context" );1618 if (!parser->is_simple_key_allowed) { 1619 return SCANNER_ERROR_INIT(parser, 1620 "mapping keys are not allowed in this context", parser->mark); 1641 1621 } 1642 1622 … … 1655 1635 /* Simple keys are allowed after '?' in the block context. */ 1656 1636 1657 parser-> simple_key_allowed = (!parser->flow_level);1637 parser->is_simple_key_allowed = (!parser->flow_level); 1658 1638 1659 1639 /* Consume the token. */ … … 1682 1662 yaml_mark_t start_mark, end_mark; 1683 1663 yaml_token_t token; 1684 yaml_simple_key_t *simple_key = parser->simple_keys.top-1; 1664 yaml_simple_key_t *simple_key = 1665 parser->simple_keys.list + parser->simple_keys.length - 1; 1685 1666 1686 1667 /* Have we found a simple key? */ 1687 1668 1688 if (simple_key-> possible)1669 if (simple_key->is_possible) 1689 1670 { 1690 1671 … … 1706 1687 /* Remove the simple key. */ 1707 1688 1708 simple_key-> possible = 0;1689 simple_key->is_possible = 0; 1709 1690 1710 1691 /* A simple key cannot follow another simple key. */ 1711 1692 1712 parser-> simple_key_allowed = 0;1693 parser->is_simple_key_allowed = 0; 1713 1694 } 1714 1695 else … … 1722 1703 /* Check if we are allowed to start a complex value. */ 1723 1704 1724 if (!parser->simple_key_allowed) { 1725 return yaml_parser_set_scanner_error(parser, NULL, parser->mark, 1726 "mapping values are not allowed in this context"); 1705 if (!parser->is_simple_key_allowed) { 1706 return SCANNER_ERROR_INIT(parser, 1707 "mapping values are not allowed in this context", 1708 parser->mark); 1727 1709 } 1728 1710 … … 1736 1718 /* Simple keys after ':' are allowed in the block context. */ 1737 1719 1738 parser-> simple_key_allowed = (!parser->flow_level);1720 parser->is_simple_key_allowed = (!parser->flow_level); 1739 1721 } 1740 1722 … … 1771 1753 /* A simple key cannot follow an anchor or an alias. */ 1772 1754 1773 parser-> simple_key_allowed = 0;1755 parser->is_simple_key_allowed = 0; 1774 1756 1775 1757 /* Create the ALIAS or ANCHOR token and append it to the queue. */ … … 1801 1783 /* A simple key cannot follow a tag. */ 1802 1784 1803 parser-> simple_key_allowed = 0;
