Changeset 214
- Timestamp:
- 07/28/06 16:09:34 (7 years ago)
- Location:
- libyaml/trunk
- Files:
-
- 5 edited
-
include/yaml.h (modified) (1 diff)
-
src/emitter.c (modified) (25 diffs)
-
src/scanner.c (modified) (73 diffs)
-
src/writer.c (modified) (1 diff)
-
src/yaml_private.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/include/yaml.h
r213 r214 1204 1204 int indention; 1205 1205 1206 /** Anchor analysis. */ 1207 struct { 1208 /** The anchor value. */ 1209 yaml_char_t *anchor; 1210 /** The anchor length. */ 1211 size_t anchor_length; 1212 /** Is it an alias? */ 1213 int alias; 1214 } anchor_data; 1215 1216 /** Tag analysis. */ 1217 struct { 1218 /** The tag handle. */ 1219 yaml_char_t *handle; 1220 /** The tag handle length. */ 1221 size_t handle_length; 1222 /** The tag suffix. */ 1223 yaml_char_t *suffix; 1224 /** The tag suffix length. */ 1225 size_t suffix_length; 1226 } tag_data; 1227 1228 /** Scalar analysis. */ 1229 struct { 1230 /** The scalar value. */ 1231 yaml_char_t *value; 1232 /** The scalar length. */ 1233 size_t length; 1234 /** Does the scalar contain line breaks? */ 1235 int multiline; 1236 /** Can the scalar be expessed in the flow plain style? */ 1237 int flow_plain_allowed; 1238 /** Can the scalar be expressed in the block plain style? */ 1239 int block_plain_allowed; 1240 /** Can the scalar be expressed in the single quoted style? */ 1241 int single_quoted_allowed; 1242 /** Can the scalar be expressed in the literal or folded styles? */ 1243 int block_allowed; 1244 /** The output style. */ 1245 yaml_scalar_style_t style; 1246 } scalar_data; 1247 1206 1248 /** 1207 1249 * @} -
libyaml/trunk/src/emitter.c
r213 r214 1 1 2 2 #include "yaml_private.h" 3 4 /* 5 * Flush the buffer if needed. 6 */ 7 8 #define FLUSH(emitter) \ 9 ((emitter->buffer.pointer+5 < emitter->buffer.end) \ 10 || yaml_emitter_flush(emitter)) 11 12 /* 13 * Put a character to the output buffer. 14 */ 15 16 #define PUT(emitter,value) \ 17 (FLUSH(emitter) \ 18 && (*(emitter->buffer.pointer++) = (yaml_char_t)(value), \ 19 emitter->column ++, \ 20 1)) 21 22 /* 23 * Put a line break to the output buffer. 24 */ 25 26 #define PUT_BREAK(emitter) \ 27 (FLUSH(emitter) \ 28 && ((emitter->line_break == YAML_CR_BREAK ? \ 29 (*(emitter->buffer.pointer++) = (yaml_char_t) '\r') : \ 30 emitter->line_break == YAML_LN_BREAK ? \ 31 (*(emitter->buffer.pointer++) = (yaml_char_t) '\n') : \ 32 emitter->line_break == YAML_CRLN_BREAK ? \ 33 (*(emitter->buffer.pointer++) = (yaml_char_t) '\r', \ 34 *(emitter->buffer.pointer++) = (yaml_char_t) '\n') : 0), \ 35 emitter->column = 0, \ 36 emitter->line ++, \ 37 1)) 38 39 /* 40 * Copy a character from a string into buffer. 41 */ 42 43 #define WRITE(emitter,string) \ 44 (FLUSH(emitter) \ 45 && (COPY(emitter->buffer,string), \ 46 emitter->column ++, \ 47 1)) 48 49 /* 50 * Copy a line break character from a string into buffer. 51 */ 52 53 #define WRITE_BREAK(emitter,string) \ 54 (FLUSH(emitter) \ 55 && (COPY(emitter->buffer,string), \ 56 emitter->column = 0, \ 57 emitter->line ++, \ 58 1)) 3 59 4 60 /* … … 106 162 yaml_emitter_check_simple_key(yaml_emitter_t *emitter); 107 163 164 static int 165 yaml_emitter_select_scalar_style(yaml_emitter_t *emitter, yaml_event_t *event); 166 108 167 /* 109 168 * Processors. … … 111 170 112 171 static int 113 yaml_emitter_process_anchor(yaml_emitter_t *emitter, 172 yaml_emitter_process_anchor(yaml_emitter_t *emitter); 173 174 static int 175 yaml_emitter_process_tag(yaml_emitter_t *emitter); 176 177 static int 178 yaml_emitter_process_scalar(yaml_emitter_t *emitter); 179 180 /* 181 * Analyzers. 182 */ 183 184 static int 185 yaml_emitter_analyze_version_directive(yaml_emitter_t *emitter, 186 yaml_version_directive_t version_directive); 187 188 static int 189 yaml_emitter_analyze_tag_directive(yaml_emitter_t *emitter, 190 yaml_tag_directive_t tag_directive); 191 192 static int 193 yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, 114 194 yaml_char_t *anchor, int alias); 115 195 116 196 static int 117 yaml_emitter_ process_tag(yaml_emitter_t *emitter,197 yaml_emitter_analyze_tag(yaml_emitter_t *emitter, 118 198 yaml_char_t *tag); 119 199 120 200 static int 121 yaml_emitter_process_scalar(yaml_emitter_t *emitter, 122 yaml_char_t *value, size_t length, 123 int plain_implicit, int quoted_implicit, 124 yaml_scalar_style_t style); 201 yaml_emitter_analyze_scalar(yaml_emitter_t *emitter, 202 yaml_char_t *value, size_t length); 203 204 static int 205 yaml_emitter_analyze_event(yaml_emitter_t *emitter, 206 yaml_event_t *event); 125 207 126 208 /* … … 130 212 static int 131 213 yaml_emitter_write_bom(yaml_emitter_t *emitter); 132 133 static int134 yaml_emitter_write_version_directive(yaml_emitter_t *emitter,135 yaml_version_directive_t version_directive);136 137 static int138 yaml_emitter_write_tag_directive(yaml_emitter_t *emitter,139 yaml_tag_directive_t tag_directive);140 214 141 215 static int … … 147 221 int is_whitespace, int is_indention); 148 222 223 static int 224 yaml_emitter_write_anchor(yaml_emitter_t *emitter, 225 yaml_char_t *value, size_t length); 226 227 static int 228 yaml_emitter_write_tag_handle(yaml_emitter_t *emitter, 229 yaml_char_t *value, size_t length); 230 231 static int 232 yaml_emitter_write_tag_content(yaml_emitter_t *emitter, 233 yaml_char_t *value, size_t length); 234 235 static int 236 yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, 237 yaml_char_t *value, size_t length, int allow_breaks); 238 239 static int 240 yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter, 241 yaml_char_t *value, size_t length, int allow_breaks); 242 243 static int 244 yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, 245 yaml_char_t *value, size_t length, int allow_breaks); 246 247 static int 248 yaml_emitter_write_literal_scalar(yaml_emitter_t *emitter, 249 yaml_char_t *value, size_t length); 250 251 static int 252 yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter, 253 yaml_char_t *value, size_t length); 254 149 255 /* 150 256 * Set an emitter error and return 0. … … 173 279 174 280 while (!yaml_emitter_need_more_events(emitter)) { 175 if (!yaml_emitter_state_machine(emitter, emitter->events.head)) { 176 return 0; 177 } 281 if (!yaml_emitter_analyze_event(emitter, emitter->events.head)) 282 return 0; 283 if (!yaml_emitter_state_machine(emitter, emitter->events.head)) 284 return 0; 178 285 DEQUEUE(emitter, emitter->events); 179 286 } … … 429 536 } 430 537 538 /* 539 * Expect DOCUMENT-START or STREAM-END. 540 */ 541 431 542 static int 432 543 yaml_emitter_emit_document_start(yaml_emitter_t *emitter, … … 444 555 445 556 if (event->data.document_start.version_directive) { 446 if (event->data.document_start.version_directive->major != 1 447 || event->data.document_start.version_directive-> minor != 1) { 448 return yaml_emitter_set_emitter_error(emitter, 449 "incompatible %YAML directive"); 450 } 557 if (!yaml_emitter_analyze_version_directive(emitter, 558 *event->data.document_start.version_directive)) 559 return 0; 451 560 } 452 561 … … 454 563 tag_directive != event->data.document_start.tag_directives.end; 455 564 tag_directive ++) { 565 if (!yaml_emitter_analyze_tag_directive(emitter, *tag_directive)) 566 return 0; 456 567 if (!yaml_emitter_append_tag_directive(emitter, *tag_directive, 0)) 457 568 return 0; … … 471 582 if (event->data.document_start.version_directive) { 472 583 implicit = 0; 473 if (!yaml_emitter_write_version_directive(emitter, 474 *event->data.document_start.version_directive)) 584 if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0)) 585 return 0; 586 if (!yaml_emitter_write_indicator(emitter, "1.1", 1, 0, 0)) 587 return 0; 588 if (!yaml_emitter_write_indent(emitter)) 475 589 return 0; 476 590 } … … 482 596 tag_directive != event->data.document_start.tag_directives.end; 483 597 tag_directive ++) { 484 if (!yaml_emitter_write_tag_directive(emitter, *tag_directive)) 598 if (!yaml_emitter_write_indicator(emitter, "%TAG", 1, 0, 0)) 599 return 0; 600 if (!yaml_emitter_write_tag_handle(emitter, tag_directive->handle, 601 strlen((char *)tag_directive->handle))) 602 return 0; 603 if (!yaml_emitter_write_tag_content(emitter, tag_directive->prefix, 604 strlen((char *)tag_directive->prefix))) 605 return 0; 606 if (!yaml_emitter_write_indent(emitter)) 485 607 return 0; 486 608 } … … 521 643 } 522 644 645 /* 646 * Expect the root node. 647 */ 648 523 649 static int 524 650 yaml_emitter_emit_document_content(yaml_emitter_t *emitter, … … 531 657 } 532 658 659 /* 660 * Expect DOCUMENT-END. 661 */ 662 533 663 static int 534 664 yaml_emitter_emit_document_end(yaml_emitter_t *emitter, … … 556 686 "expected DOCUMENT-END"); 557 687 } 688 689 /* 690 * Expect a flow item node. 691 */ 558 692 559 693 static int … … 597 731 } 598 732 733 /* 734 * Expect a flow key node. 735 */ 736 599 737 static int 600 738 yaml_emitter_emit_flow_mapping_key(yaml_emitter_t *emitter, … … 656 794 } 657 795 796 /* 797 * Expect a flow value node. 798 */ 799 658 800 static int 659 801 yaml_emitter_emit_flow_mapping_value(yaml_emitter_t *emitter, … … 677 819 } 678 820 821 /* 822 * Expect a block item node. 823 */ 824 679 825 static int 680 826 yaml_emitter_emit_block_sequence_item(yaml_emitter_t *emitter, … … 707 853 } 708 854 855 /* 856 * Expect a block key node. 857 */ 858 709 859 static int 710 860 yaml_emitter_emit_block_mapping_key(yaml_emitter_t *emitter, … … 748 898 } 749 899 900 /* 901 * Expect a block value node. 902 */ 903 750 904 static int 751 905 yaml_emitter_emit_block_mapping_value(yaml_emitter_t *emitter, … … 768 922 return yaml_emitter_emit_node(emitter, event, 0, 0, 1, 0); 769 923 } 924 925 /* 926 * Expect a node. 927 */ 770 928 771 929 static int … … 800 958 } 801 959 960 /* 961 * Expect ALIAS. 962 */ 963 802 964 static int 803 965 yaml_emitter_emit_alias(yaml_emitter_t *emitter, yaml_event_t *event) 804 966 { 805 if (!yaml_emitter_process_anchor(emitter , event->data.alias.anchor, 1))967 if (!yaml_emitter_process_anchor(emitter)) 806 968 return 0; 807 969 emitter->state = POP(emitter, emitter->states); … … 810 972 } 811 973 974 /* 975 * Expect SCALAR. 976 */ 977 812 978 static int 813 979 yaml_emitter_emit_scalar(yaml_emitter_t *emitter, yaml_event_t *event) 814 980 { 815 if (!yaml_emitter_process_anchor(emitter, event->data.scalar.anchor, 0)) 816 return 0; 817 if (!yaml_emitter_process_tag(emitter, event->data.scalar.tag)) 981 if (!yaml_emitter_select_scalar_style(emitter, event)) 982 return 0; 983 if (!yaml_emitter_process_anchor(emitter)) 984 return 0; 985 if (!yaml_emitter_process_tag(emitter)) 818 986 return 0; 819 987 if (!yaml_emitter_increase_indent(emitter, 1, 0)) 820 988 return 0; 821 if (!yaml_emitter_process_scalar(emitter, 822 event->data.scalar.value, event->data.scalar.length, 823 event->data.scalar.plain_implicit, 824 event->data.scalar.quoted_implicit, 825 event->data.scalar.style)) 989 if (!yaml_emitter_process_scalar(emitter)) 826 990 return 0; 827 991 emitter->indent = POP(emitter, emitter->indents); … … 831 995 } 832 996 997 /* 998 * Expect SEQUENCE-START. 999 */ 1000 833 1001 static int 834 1002 yaml_emitter_emit_sequence_start(yaml_emitter_t *emitter, yaml_event_t *event) 835 1003 { 836 if (!yaml_emitter_process_anchor(emitter, 837 event->data.sequence_start.anchor, 0)) 838 return 0; 839 if (!yaml_emitter_process_tag(emitter, 840 event->data.sequence_start.tag)) 1004 if (!yaml_emitter_process_anchor(emitter)) 1005 return 0; 1006 if (!yaml_emitter_process_tag(emitter)) 841 1007 return 0; 842 1008 … … 853 1019 } 854 1020 1021 /* 1022 * Expect MAPPING-START. 1023 */ 1024 855 1025 static int 856 1026 yaml_emitter_emit_mapping_start(yaml_emitter_t *emitter, yaml_event_t *event) 857 1027 { 858 if (!yaml_emitter_process_anchor(emitter, 859 event->data.mapping_start.anchor, 0)) 860 return 0; 861 if (!yaml_emitter_process_tag(emitter, 862 event->data.mapping_start.tag)) 1028 if (!yaml_emitter_process_anchor(emitter)) 1029 return 0; 1030 if (!yaml_emitter_process_tag(emitter)) 863 1031 return 0; 864 1032 … … 875 1043 } 876 1044 1045 /* 1046 * Check if the document content is an empty scalar. 1047 */ 1048 1049 static int 1050 yaml_emitter_check_empty_document(yaml_emitter_t *emitter) 1051 { 1052 return 0; 1053 } 1054 1055 /* 1056 * Check if the next events represent an empty sequence. 1057 */ 1058 1059 static int 1060 yaml_emitter_check_empty_sequence(yaml_emitter_t *emitter) 1061 { 1062 if (emitter->events.tail - emitter->events.head < 2) 1063 return 0; 1064 1065 return (emitter->events.head[0].type == YAML_SEQUENCE_START_EVENT 1066 && emitter->events.head[1].type == YAML_SEQUENCE_END_EVENT); 1067 } 1068 1069 /* 1070 * Check if the next events represent an empty mapping. 1071 */ 1072 1073 static int 1074 yaml_emitter_check_empty_mapping(yaml_emitter_t *emitter) 1075 { 1076 if (emitter->events.tail - emitter->events.head < 2) 1077 return 0; 1078 1079 return (emitter->events.head[0].type == YAML_MAPPING_START_EVENT 1080 && emitter->events.head[1].type == YAML_MAPPING_END_EVENT); 1081 } 1082 1083 /* 1084 * Check if the next node can be expressed as a simple key. 1085 */ 1086 1087 static int 1088 yaml_emitter_check_simple_key(yaml_emitter_t *emitter) 1089 { 1090 yaml_event_t *event = emitter->events.head; 1091 size_t length = 0; 1092 1093 switch (event->type) 1094 { 1095 case YAML_ALIAS_EVENT: 1096 length += emitter->anchor_data.anchor_length; 1097 break; 1098 1099 case YAML_SCALAR_EVENT: 1100 if (emitter->scalar_data.multiline) 1101 return 0; 1102 length += emitter->anchor_data.anchor_length 1103 + emitter->tag_data.handle_length 1104 + emitter->tag_data.suffix_length 1105 + emitter->scalar_data.length; 1106 break; 1107 1108 case YAML_SEQUENCE_START_EVENT: 1109 if (!yaml_emitter_check_empty_sequence(emitter)) 1110 return 0; 1111 length += emitter->anchor_data.anchor_length 1112 + emitter->tag_data.handle_length 1113 + emitter->tag_data.suffix_length; 1114 break; 1115 1116 case YAML_MAPPING_START_EVENT: 1117 if (!yaml_emitter_check_empty_sequence(emitter)) 1118 return 0; 1119 length += emitter->anchor_data.anchor_length 1120 + emitter->tag_data.handle_length 1121 + emitter->tag_data.suffix_length; 1122 break; 1123 1124 default: 1125 return 0; 1126 } 1127 1128 if (length > 128) 1129 return 0; 1130 1131 return 1; 1132 } 1133 1134 /* 1135 * Determine an acceptable scalar style. 1136 */ 1137 1138 static int 1139 yaml_emitter_select_scalar_style(yaml_emitter_t *emitter, yaml_event_t *event) 1140 { 1141 yaml_scalar_style_t style = event->data.scalar.style; 1142 1143 if (style == YAML_ANY_SCALAR_STYLE) 1144 style = YAML_PLAIN_SCALAR_STYLE; 1145 1146 if (emitter->canonical) 1147 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1148 1149 if (emitter->simple_key_context && emitter->scalar_data.multiline) 1150 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1151 1152 if (style == YAML_PLAIN_SCALAR_STYLE) 1153 { 1154 if ((emitter->flow_level && !emitter->scalar_data.flow_plain_allowed) 1155 || (!emitter->flow_level && !emitter->scalar_data.block_plain_allowed)) 1156 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1157 if (!emitter->scalar_data.length 1158 && (emitter->flow_level || emitter->simple_key_context)) 1159 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1160 if (!event->data.scalar.plain_implicit 1161 && !emitter->tag_data.handle && !emitter->tag_data.suffix) 1162 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1163 } 1164 1165 if (style == YAML_SINGLE_QUOTED_SCALAR_STYLE) 1166 { 1167 if (!emitter->scalar_data.single_quoted_allowed) 1168 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1169 } 1170 1171 if (style == YAML_LITERAL_SCALAR_STYLE || style == YAML_FOLDED_SCALAR_STYLE) 1172 { 1173 if (!emitter->scalar_data.block_allowed) 1174 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1175 } 1176 1177 if (!emitter->tag_data.handle && !emitter->tag_data.suffix) 1178 { 1179 if (!event->data.scalar.plain_implicit 1180 && !event->data.scalar.quoted_implicit) { 1181 return yaml_emitter_set_emitter_error(emitter, 1182 "neither tag nor implicit flags are specified"); 1183 } 1184 1185 if (event->data.scalar.plain_implicit 1186 && style != YAML_PLAIN_SCALAR_STYLE) { 1187 emitter->tag_data.handle = (yaml_char_t *)"!"; 1188 emitter->tag_data.handle_length = 1; 1189 } 1190 } 1191 1192 emitter->scalar_data.style = style; 1193 1194 return 1; 1195 } 1196 1197 /* 1198 * Write an achor. 1199 */ 1200 1201 static int 1202 yaml_emitter_process_anchor(yaml_emitter_t *emitter) 1203 { 1204 if (!emitter->anchor_data.anchor) 1205 return 1; 1206 1207 if (!yaml_emitter_write_indicator(emitter, 1208 (emitter->anchor_data.alias ? "*" : "&"), 1, 0, 0)) 1209 return 0; 1210 1211 return yaml_emitter_write_anchor(emitter, 1212 emitter->anchor_data.anchor, emitter->anchor_data.anchor_length); 1213 } 1214 1215 /* 1216 * Write a tag. 1217 */ 1218 1219 static int 1220 yaml_emitter_process_tag(yaml_emitter_t *emitter) 1221 { 1222 if (!emitter->tag_data.handle && !emitter->tag_data.suffix) 1223 return 1; 1224 1225 if (emitter->tag_data.handle) 1226 { 1227 if (!yaml_emitter_write_tag_handle(emitter, emitter->tag_data.handle, 1228 emitter->tag_data.handle_length)) 1229 return 0; 1230 if (emitter->tag_data.suffix) { 1231 if (!yaml_emitter_write_tag_content(emitter, emitter->tag_data.suffix, 1232 emitter->tag_data.suffix_length)) 1233 return 0; 1234 } 1235 } 1236 else 1237 { 1238 if (!yaml_emitter_write_indicator(emitter, "!<", 1, 0, 0)) 1239 return 0; 1240 if (!yaml_emitter_write_tag_content(emitter, emitter->tag_data.suffix, 1241 emitter->tag_data.suffix_length)) 1242 return 0; 1243 if (!yaml_emitter_write_indicator(emitter, ">", 0, 0, 0)) 1244 return 0; 1245 } 1246 1247 return 1; 1248 } 1249 1250 /* 1251 * Write a scalar. 1252 */ 1253 1254 static int 1255 yaml_emitter_process_scalar(yaml_emitter_t *emitter) 1256 { 1257 switch (emitter->scalar_data.style) 1258 { 1259 case YAML_PLAIN_SCALAR_STYLE: 1260 return yaml_emitter_write_plain_scalar(emitter, 1261 emitter->scalar_data.value, emitter->scalar_data.length, 1262 !emitter->simple_key_context); 1263 1264 case YAML_SINGLE_QUOTED_SCALAR_STYLE: 1265 return yaml_emitter_write_single_quoted_scalar(emitter, 1266 emitter->scalar_data.value, emitter->scalar_data.length, 1267 !emitter->simple_key_context); 1268 1269 case YAML_DOUBLE_QUOTED_SCALAR_STYLE: 1270 return yaml_emitter_write_double_quoted_scalar(emitter, 1271 emitter->scalar_data.value, emitter->scalar_data.length, 1272 !emitter->simple_key_context); 1273 1274 case YAML_LITERAL_SCALAR_STYLE: 1275 return yaml_emitter_write_literal_scalar(emitter, 1276 emitter->scalar_data.value, emitter->scalar_data.length); 1277 1278 case YAML_FOLDED_SCALAR_STYLE: 1279 return yaml_emitter_write_folded_scalar(emitter, 1280 emitter->scalar_data.value, emitter->scalar_data.length); 1281 1282 default: 1283 assert(1); /* Impossible. */ 1284 } 1285 1286 return 0; 1287 } 1288 1289 /* 1290 * Check if a %YAML directive is valid. 1291 */ 1292 1293 static int 1294 yaml_emitter_analyze_version_directive(yaml_emitter_t *emitter, 1295 yaml_version_directive_t version_directive) 1296 { 1297 if (version_directive.major != 1 || version_directive.minor != 1) { 1298 return yaml_emitter_set_emitter_error(emitter, 1299 "incompatible %YAML directive"); 1300 } 1301 1302 return 1; 1303 } 1304 1305 /* 1306 * Check if a %TAG directive is valid. 1307 */ 1308 1309 static int 1310 yaml_emitter_analyze_tag_directive(yaml_emitter_t *emitter, 1311 yaml_tag_directive_t tag_directive) 1312 { 1313 yaml_string_t handle = STRING(tag_directive.handle, 1314 strlen((char *)tag_directive.handle)); 1315 yaml_string_t prefix = STRING(tag_directive.prefix, 1316 strlen((char *)tag_directive.prefix)); 1317 1318 if (handle.start == handle.end) { 1319 return yaml_emitter_set_emitter_error(emitter, 1320 "tag handle must not be empty"); 1321 } 1322 1323 if (handle.start[0] != '!') { 1324 return yaml_emitter_set_emitter_error(emitter, 1325 "tag handle must start with '!'"); 1326 } 1327 1328 if (handle.end[-1] != '!') { 1329 return yaml_emitter_set_emitter_error(emitter, 1330 "tag handle must end with '!'"); 1331 } 1332 1333 handle.pointer ++; 1334 1335 while (handle.pointer != handle.end-1) { 1336 if (!IS_ALPHA(handle)) { 1337 return yaml_emitter_set_emitter_error(emitter, 1338 "tag handle must contain alphanumerical characters only"); 1339 } 1340 MOVE(handle); 1341 } 1342 1343 if (prefix.start == prefix.end) { 1344 return yaml_emitter_set_emitter_error(emitter, 1345 "tag prefix must not be empty"); 1346 } 1347 1348 return 1; 1349 } 1350 1351 /* 1352 * Check if an anchor is valid. 1353 */ 1354 1355 static int 1356 yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, 1357 yaml_char_t *anchor, int alias) 1358 { 1359 yaml_string_t string = STRING(anchor, strlen((char *)anchor)); 1360 1361 if (string.start == string.end) { 1362 return yaml_emitter_set_emitter_error(emitter, alias ? 1363 "alias value must not be empty" : 1364 "anchor value must not be empty"); 1365 } 1366 1367 while (string.pointer != string.end) { 1368 if (!IS_ALPHA(string)) { 1369 return yaml_emitter_set_emitter_error(emitter, alias ? 1370 "alias value must contain alphanumerical characters only" : 1371 "anchor value must contain alphanumerical characters only"); 1372 } 1373 MOVE(string); 1374 } 1375 } 1376 1377 /* 1378 * Check if a tag is valid. 1379 */ 1380 1381 static int 1382 yaml_emitter_analyze_tag(yaml_emitter_t *emitter, 1383 yaml_char_t *tag) 1384 { 1385 yaml_string_t string = STRING(tag, strlen((char *)tag)); 1386 yaml_tag_directive_t *tag_directive; 1387 1388 if (string.start == string.end) { 1389 return yaml_emitter_set_emitter_error(emitter, 1390 "tag value must not be empty"); 1391 } 1392 1393 for (tag_directive = emitter->tag_directives.start; 1394 tag_directive != emitter->tag_directives.end; tag_directive ++) { 1395 size_t prefix_length = strlen((char *)tag_directive->prefix); 1396 if (prefix_length < (string.end - string.start) 1397 && strncmp((char *)tag_directive->prefix, (char *)string.start, 1398 prefix_length) == 0) 1399 { 1400 emitter->tag_data.handle = tag_directive->handle; 1401 emitter->tag_data.handle_length = 1402 strlen((char *)tag_directive->handle); 1403 emitter->tag_data.suffix = string.start + prefix_length; 1404 emitter->tag_data.suffix_length = 1405 (string.end - string.start) - prefix_length; 1406 return 1; 1407 } 1408 } 1409 1410 emitter->tag_data.suffix = string.start; 1411 emitter->tag_data.suffix_length = string.end - string.start; 1412 1413 return 1; 1414 } 1415 1416 /* 1417 * Check if a scalar is valid. 1418 */ 1419 1420 static int 1421 yaml_emitter_analyze_scalar(yaml_emitter_t *emitter, 1422 yaml_char_t *value, size_t length) 1423 { 1424 yaml_string_t string = STRING(value, length); 1425 1426 int block_indicators = 0; 1427 int flow_indicators = 0; 1428 int line_breaks = 0; 1429 int special_characters = 0; 1430 1431 int inline_spaces = 0; 1432 int inline_breaks = 0; 1433 int leading_spaces = 0; 1434 int leading_breaks = 0; 1435 int trailing_spaces = 0; 1436 int trailing_breaks = 0; 1437 int inline_breaks_spaces = 0; 1438 int mixed_breaks_spaces = 0; 1439 1440 int preceeded_by_space = 0; 1441 int followed_by_space = 0; 1442 int spaces = 0; 1443 int breaks = 0; 1444 int mixed = 0; 1445 int leading = 0; 1446 1447 emitter->scalar_data.value = value; 1448 emitter->scalar_data.length = length; 1449 1450 if (string.start == string.end) 1451 { 1452 emitter->scalar_data.multiline = 0; 1453 emitter->scalar_data.flow_plain_allowed = 0; 1454 emitter->scalar_data.block_plain_allowed = 1; 1455 emitter->scalar_data.single_quoted_allowed = 1; 1456 emitter->scalar_data.block_allowed = 0; 1457 1458 return 1; 1459 } 1460 1461 if ((CHECK_AT(string, '-', 0) 1462 && CHECK_AT(string, '-', 1) 1463 && CHECK_AT(string, '-', 2)) 1464 || (CHECK_AT(string, '.', 0) 1465 && CHECK_AT(string, '.', 1) 1466 && CHECK_AT(string, '.', 2))) { 1467 block_indicators = 1; 1468 flow_indicators = 1; 1469 } 1470 1471 preceeded_by_space = 1; 1472 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1473 1474 while (string.pointer != string.end) 1475 { 1476 if (string.start == string.pointer) 1477 { 1478 if (CHECK(string, '#') || CHECK(string, ',') 1479 || CHECK(string, '[') || CHECK(string, ']') 1480 || CHECK(string, '{') || CHECK(string, '}') 1481 || CHECK(string, '&') || CHECK(string, '*') 1482 || CHECK(string, '!') || CHECK(string, '|') 1483 || CHECK(string, '>') || CHECK(string, '\'') 1484 || CHECK(string, '"') || CHECK(string, '%') 1485 || CHECK(string, '@') || CHECK(string, '`')) { 1486 flow_indicators = 1; 1487 block_indicators = 1; 1488 } 1489 1490 if (CHECK(string, '?') || CHECK(string, ':')) { 1491 flow_indicators = 1; 1492 if (followed_by_space) { 1493 block_indicators = 1; 1494 } 1495 } 1496 1497 if (CHECK(string, '-') && followed_by_space) { 1498 flow_indicators = 1; 1499 block_indicators = 1; 1500 } 1501 } 1502 else 1503 { 1504 if (CHECK(string, ',') || CHECK(string, '?') 1505 || CHECK(string, '[') || CHECK(string, ']') 1506 || CHECK(string, '{') || CHECK(string, '}')) { 1507 flow_indicators = 1; 1508 } 1509 1510 if (CHECK(string, ':')) { 1511 flow_indicators = 1; 1512 if (followed_by_space) { 1513 block_indicators = 1; 1514 } 1515 } 1516 1517 if (CHECK(string, '#') && preceeded_by_space) { 1518 flow_indicators = 1; 1519 block_indicators = 1; 1520 } 1521 } 1522 1523 if (!IS_PRINTABLE(string) 1524 || (!IS_ASCII(string) && !emitter->unicode)) { 1525 special_characters = 1; 1526 } 1527 1528 if (IS_BREAK(string)) { 1529 line_breaks = 1; 1530 } 1531 1532 if (IS_SPACE(string)) 1533 { 1534 spaces = 1; 1535 if (string.start == string.pointer) { 1536 leading = 1; 1537 } 1538 } 1539 1540 else if (IS_BREAK(string)) 1541 { 1542 if (spaces) { 1543 mixed = 1; 1544 } 1545 breaks = 1; 1546 if (string.start == string.pointer) { 1547 leading = 1; 1548 } 1549 } 1550 1551 else if (spaces || breaks) 1552 { 1553 if (leading) { 1554 if (spaces && breaks) { 1555 mixed_breaks_spaces = 1; 1556 } 1557 else if (spaces) { 1558 leading_spaces = 1; 1559 } 1560 else if (breaks) { 1561 leading_breaks = 1; 1562 } 1563 } 1564 else { 1565 if (mixed) { 1566 mixed_breaks_spaces = 1; 1567 } 1568 else if (spaces && breaks) { 1569 inline_breaks_spaces = 1; 1570 } 1571 else if (spaces) { 1572 inline_spaces = 1; 1573 } 1574 else if (breaks) { 1575 inline_breaks = 1; 1576 } 1577 } 1578 spaces = breaks = mixed = leading = 0; 1579 } 1580 1581 preceeded_by_space = IS_BLANKZ(string); 1582 MOVE(string); 1583 if (string.pointer != string.end) { 1584 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1585 } 1586 } 1587 1588 emitter->scalar_data.multiline = line_breaks; 1589 1590 emitter->scalar_data.flow_plain_allowed = 1; 1591 emitter->scalar_data.block_plain_allowed = 1; 1592 emitter->scalar_data.single_quoted_allowed = 1; 1593 emitter->scalar_data.block_allowed = 1; 1594 1595 if (leading_spaces || leading_breaks || trailing_spaces) { 1596 emitter->scalar_data.flow_plain_allowed = 0; 1597 emitter->scalar_data.block_plain_allowed = 0; 1598 emitter->scalar_data.block_allowed = 0; 1599 } 1600 1601 if (trailing_breaks) { 1602 emitter->scalar_data.flow_plain_allowed = 0; 1603 emitter->scalar_data.block_plain_allowed = 0; 1604 } 1605 1606 if (inline_breaks_spaces) { 1607 emitter->scalar_data.flow_plain_allowed = 0; 1608 emitter->scalar_data.block_plain_allowed = 0; 1609 emitter->scalar_data.single_quoted_allowed = 0; 1610 } 1611 1612 if (mixed_breaks_spaces || special_characters) { 1613 emitter->scalar_data.flow_plain_allowed = 0; 1614 emitter->scalar_data.block_plain_allowed = 0; 1615 emitter->scalar_data.single_quoted_allowed = 0; 1616 emitter->scalar_data.block_allowed = 0; 1617 } 1618 1619 if (line_breaks) { 1620 emitter->scalar_data.flow_plain_allowed = 0; 1621 emitter->scalar_data.block_plain_allowed = 0; 1622 } 1623 1624 if (flow_indicators) { 1625 emitter->scalar_data.flow_plain_allowed = 0; 1626 } 1627 1628 if (block_indicators) { 1629 emitter->scalar_data.block_plain_allowed = 0; 1630 } 1631 1632 return 1; 1633 } 1634 1635 /* 1636 * Check if the event data is valid. 1637 */ 1638 1639 static int 1640 yaml_emitter_analyze_event(yaml_emitter_t *emitter, 1641 yaml_event_t *event) 1642 { 1643 emitter->anchor_data.anchor = NULL; 1644 emitter->anchor_data.anchor_length = 0; 1645 emitter->tag_data.handle = NULL; 1646 emitter->tag_data.handle_length = 0; 1647 emitter->tag_data.suffix = NULL; 1648 emitter->tag_data.suffix_length = 0; 1649 emitter->scalar_data.value = NULL; 1650 emitter->scalar_data.length = 0; 1651 1652 switch (event->type) 1653 { 1654 case YAML_ALIAS_EVENT: 1655 if (!yaml_emitter_analyze_anchor(emitter, 1656 event->data.alias.anchor, 1)) 1657 return 0; 1658 return 1; 1659 1660 case YAML_SCALAR_EVENT: 1661 if (event->data.scalar.anchor) { 1662 if (!yaml_emitter_analyze_anchor(emitter, 1663 event->data.scalar.anchor, 0)) 1664 return 0; 1665 } 1666 if (event->data.scalar.tag && (emitter->canonical || 1667 (!event->data.scalar.plain_implicit 1668 && !event->data.scalar.quoted_implicit))) { 1669 if (!yaml_emitter_analyze_tag(emitter, event->data.scalar.tag)) 1670 return 0; 1671 } 1672 if (!yaml_emitter_analyze_scalar(emitter, 1673 event->data.scalar.value, event->data.scalar.length)) 1674 return 0; 1675 return 1; 1676 1677 case YAML_SEQUENCE_START_EVENT: 1678 if (event->data.sequence_start.anchor) { 1679 if (!yaml_emitter_analyze_anchor(emitter, 1680 event->data.sequence_start.anchor, 0)) 1681 return 0; 1682 } 1683 if (event->data.sequence_start.tag && (emitter->canonical || 1684 !event->data.sequence_start.implicit)) { 1685 if (!yaml_emitter_analyze_tag(emitter, 1686 event->data.sequence_start.tag)) 1687 return 0; 1688 } 1689 return 1; 1690 1691 case YAML_MAPPING_START_EVENT: 1692 if (event->data.mapping_start.anchor) { 1693 if (!yaml_emitter_analyze_anchor(emitter, 1694 event->data.mapping_start.anchor, 0)) 1695 return 0; 1696 } 1697 if (event->data.mapping_start.tag && (emitter->canonical || 1698 !event->data.mapping_start.implicit)) { 1699 if (!yaml_emitter_analyze_tag(emitter, 1700 event->data.mapping_start.tag)) 1701 return 0; 1702 } 1703 return 1; 1704 1705 default: 1706 return 1; 1707 } 1708 } 1709 1710 /* 1711 * Write the BOM character. 1712 */ 1713 1714 static int 1715 yaml_emitter_write_bom(yaml_emitter_t *emitter) 1716 { 1717 if (!FLUSH(emitter)) return 0; 1718 1719 *(emitter->buffer.pointer++) = (yaml_char_t) '\xEF'; 1720 *(emitter->buffer.pointer++) = (yaml_char_t) '\xBB'; 1721 *(emitter->buffer.pointer++) = (yaml_char_t) '\xBF'; 1722 1723 return 1; 1724 } 1725 1726 static int 1727 yaml_emitter_write_indent(yaml_emitter_t *emitter) 1728 { 1729 int indent = (emitter->indent >= 0) ? emitter->indent : 0; 1730 1731 if (!emitter->indention || emitter->column > indent 1732 || (emitter->column == indent && !emitter->whitespace)) { 1733 if (!PUT_BREAK(emitter)) return 0; 1734 } 1735 1736 while (emitter->column < indent) { 1737 if (!PUT(emitter, ' ')) return 0; 1738 } 1739 1740 emitter->whitespace = 1; 1741 emitter->indention = 1; 1742 1743 return 1; 1744 } 1745 1746 static int 1747 yaml_emitter_write_indicator(yaml_emitter_t *emitter, 1748 char *indicator, int need_whitespace, 1749 int is_whitespace, int is_indention) 1750 { 1751 yaml_string_t string = STRING((yaml_char_t *)indicator, strlen(indicator)); 1752 1753 if (need_whitespace && !emitter->whitespace) { 1754 if (!PUT(emitter, ' ')) return 0; 1755 } 1756 1757 while (string.pointer != string.end) { 1758 if (!WRITE(emitter, string)) return 0; 1759 } 1760 1761 emitter->whitespace = is_whitespace; 1762 emitter->indention = (emitter->indention && is_indention); 1763 1764 return 1; 1765 } 1766 1767 static int 1768 yaml_emitter_write_anchor(yaml_emitter_t *emitter, 1769 yaml_char_t *value, size_t length) 1770 { 1771 yaml_string_t string = STRING(value, length); 1772 1773 while (string.pointer != string.end) { 1774 if (!WRITE(emitter, string)) return 0; 1775 } 1776 1777 emitter->whitespace = 0; 1778 emitter->indention = 0; 1779 1780 return 1; 1781 } 1782 1783 static int 1784 yaml_emitter_write_tag_handle(yaml_emitter_t *emitter, 1785 yaml_char_t *value, size_t length) 1786 { 1787 yaml_string_t string = STRING(value, length); 1788 1789 while (string.pointer != string.end) { 1790 if (!WRITE(emitter, string)) return 0; 1791 } 1792 1793 emitter->whitespace = 0; 1794 emitter->indention = 0; 1795 1796 return 1; 1797 } 1798 1799 static int 1800 yaml_emitter_write_tag_content(yaml_emitter_t *emitter, 1801 yaml_char_t *value, size_t length) 1802 { 1803 return 0; 1804 } 1805 1806 static int 1807 yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, 1808 yaml_char_t *value, size_t length, int allow_breaks) 1809 { 1810 return 0; 1811 } 1812 1813 static int 1814 yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter, 1815 yaml_char_t *value, size_t length, int allow_breaks) 1816 { 1817 return 0; 1818 } 1819 1820 static int 1821 yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, 1822 yaml_char_t *value, size_t length, int allow_breaks) 1823 { 1824 return 0; 1825 } 1826 1827 static int 1828 yaml_emitter_write_literal_scalar(yaml_emitter_t *emitter, 1829 yaml_char_t *value, size_t length) 1830 { 1831 return 0; 1832 } 1833 1834 static int 1835 yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter, 1836 yaml_char_t *value, size_t length) 1837 { 1838 return 0; 1839 } 1840 -
libyaml/trunk/src/scanner.c
r213 r214 489 489 490 490 /* 491 * Check the octet at the specified position.492 */493 494 #define CHECK_AT(parser,octet,offset) \495 (parser->buffer.pointer[offset] == (yaml_char_t)(octet))496 497 /*498 * Check the current octet in the buffer.499 */500 501 #define CHECK(parser,octet) CHECK_AT(parser,(octet),0)502 503 /*504 * Check if the character at the specified position is an alphabetical505 * character, a digit, '_', or '-'.506 */507 508 #define IS_ALPHA_AT(parser,offset) \509 ((parser->buffer.pointer[offset] >= (yaml_char_t) '0' && \510 parser->buffer.pointer[offset] <= (yaml_char_t) '9') || \511 (parser->buffer.pointer[offset] >= (yaml_char_t) 'A' && \512 parser->buffer.pointer[offset] <= (yaml_char_t) 'Z') || \513 (parser->buffer.pointer[offset] >= (yaml_char_t) 'a' && \514 parser->buffer.pointer[offset] <= (yaml_char_t) 'z') || \515 parser->buffer.pointer[offset] == '_' || \516 parser->buffer.pointer[offset] == '-')517 518 #define IS_ALPHA(parser) IS_ALPHA_AT(parser,0)519 520 /*521 * Check if the character at the specified position is a digit.522 */523 524 #define IS_DIGIT_AT(parser,offset) \525 ((parser->buffer.pointer[offset] >= (yaml_char_t) '0' && \526 parser->buffer.pointer[offset] <= (yaml_char_t) '9'))527 528 #define IS_DIGIT(parser) IS_DIGIT_AT(parser,0)529 530 /*531 * Get the value of a digit.532 */533 534 #define AS_DIGIT_AT(parser,offset) \535 (parser->buffer.pointer[offset] - (yaml_char_t) '0')536 537 #define AS_DIGIT(parser) AS_DIGIT_AT(parser,0)538 539 /*540 * Check if the character at the specified position is a hex-digit.541 */542 543 #define IS_HEX_AT(parser,offset) \544 ((parser->buffer.pointer[offset] >= (yaml_char_t) '0' && \545 parser->buffer.pointer[offset] <= (yaml_char_t) '9') || \546 (parser->buffer.pointer[offset] >= (yaml_char_t) 'A' && \547 parser->buffer.pointer[offset] <= (yaml_char_t) 'F') || \548 (parser->buffer.pointer[offset] >= (yaml_char_t) 'a' && \549 parser->buffer.pointer[offset] <= (yaml_char_t) 'f'))550 551 #define IS_HEX(parser) IS_HEX_AT(parser,0)552 553 /*554 * Get the value of a hex-digit.555 */556 557 #define AS_HEX_AT(parser,offset) \558 ((parser->buffer.pointer[offset] >= (yaml_char_t) 'A' && \559 parser->buffer.pointer[offset] <= (yaml_char_t) 'F') ? \560 (parser->buffer.pointer[offset] - (yaml_char_t) 'A' + 10) : \561 (parser->buffer.pointer[offset] >= (yaml_char_t) 'a' && \562 parser->buffer.pointer[offset] <= (yaml_char_t) 'f') ? \563 (parser->buffer.pointer[offset] - (yaml_char_t) 'a' + 10) : \564 (parser->buffer.pointer[offset] - (yaml_char_t) '0'))565 566 #define AS_HEX(parser) AS_HEX_AT(parser,0)567 568 /*569 * Check if the character at the specified position is NUL.570 */571 572 #define IS_Z_AT(parser,offset) CHECK_AT(parser,'\0',(offset))573 574 #define IS_Z(parser) IS_Z_AT(parser,0)575 576 /*577 * Check if the character at the specified position is BOM.578 */579 580 #define IS_BOM_AT(parser,offset) \581 (CHECK_AT(parser,'\xEF',(offset)) \582 && CHECK_AT(parser,'\xBB',(offset)+1) \583 && CHECK_AT(parser,'\xBF',(offset)+1)) /* BOM (#xFEFF) */584 585 #define IS_BOM(parser) IS_BOM_AT(parser,0)586 587 /*588 * Check if the character at the specified position is space.589 */590 591 #define IS_SPACE_AT(parser,offset) CHECK_AT(parser,' ',(offset))592 593 #define IS_SPACE(parser) IS_SPACE_AT(parser,0)594 595 /*596 * Check if the character at the specified position is tab.597 */598 599 #define IS_TAB_AT(parser,offset) CHECK_AT(parser,'\t',(offset))600 601 #define IS_TAB(parser) IS_TAB_AT(parser,0)602 603 /*604 * Check if the character at the specified position is blank (space or tab).605 */606 607 #define IS_BLANK_AT(parser,offset) \608 (IS_SPACE_AT(parser,(offset)) || IS_TAB_AT(parser,(offset)))609 610 #define IS_BLANK(parser) IS_BLANK_AT(parser,0)611 612 /*613 * Check if the character at the specified position is a line break.614 */615 616 #define IS_BREAK_AT(parser,offset) \617 (CHECK_AT(parser,'\r',(offset)) /* CR (#xD)*/ \618 || CHECK_AT(parser,'\n',(offset)) /* LF (#xA) */ \619 || (CHECK_AT(parser,'\xC2',(offset)) \620 && CHECK_AT(parser,'\x85',(offset)+1)) /* NEL (#x85) */ \621 || (CHECK_AT(parser,'\xE2',(offset)) \622 && CHECK_AT(parser,'\x80',(offset)+1) \623 && CHECK_AT(parser,'\xA8',(offset)+2)) /* LS (#x2028) */ \624 || (CHECK_AT(parser,'\xE2',(offset)) \625 && CHECK_AT(parser,'\x80',(offset)+1) \626 && CHECK_AT(parser,'\xA9',(offset)+2))) /* PS (#x2029) */627 628 #define IS_BREAK(parser) IS_BREAK_AT(parser,0)629 630 #define IS_CRLF_AT(parser,offset) \631 (CHECK_AT(parser,'\r',(offset)) && CHECK_AT(parser,'\n',(offset)+1))632 633 #define IS_CRLF(parser) IS_CRLF_AT(parser,0)634 635 /*636 * Check if the character is a line break or NUL.637 */638 639 #define IS_BREAKZ_AT(parser,offset) \640 (IS_BREAK_AT(parser,(offset)) || IS_Z_AT(parser,(offset)))641 642 #define IS_BREAKZ(parser) IS_BREAKZ_AT(parser,0)643 644 /*645 * Check if the character is a line break, space, or NUL.646 */647 648 #define IS_SPACEZ_AT(parser,offset) \649 (IS_SPACE_AT(parser,(offset)) || IS_BREAKZ_AT(parser,(offset)))650 651 #define IS_SPACEZ(parser) IS_SPACEZ_AT(parser,0)652 653 /*654 * Check if the character is a line break, space, tab, or NUL.655 */656 657 #define IS_BLANKZ_AT(parser,offset) \658 (IS_BLANK_AT(parser,(offset)) || IS_BREAKZ_AT(parser,(offset)))659 660 #define IS_BLANKZ(parser) IS_BLANKZ_AT(parser,0)661 662 /*663 * Determine the width of the character.664 */665 666 #define WIDTH_AT(parser,offset) \667 ((parser->buffer.pointer[offset] & 0x80) == 0x00 ? 1 : \668 (parser->buffer.pointer[offset] & 0xE0) == 0xC0 ? 2 : \669 (parser->buffer.pointer[offset] & 0xF0) == 0xE0 ? 3 : \670 (parser->buffer.pointer[offset] & 0xF8) == 0xF0 ? 4 : 0)671 672 #define WIDTH(parser) WIDTH_AT(parser,0)673 674 /*675 491 * Advance the buffer pointer. 676 492 */ … … 680 496 parser->mark.column ++, \ 681 497 parser->unread --, \ 682 parser->buffer.pointer += WIDTH(parser ))498 parser->buffer.pointer += WIDTH(parser->buffer)) 683 499 684 500 #define SKIP_LINE(parser) \ 685 (IS_CRLF(parser ) ?\501 (IS_CRLF(parser->buffer) ? \ 686 502 (parser->mark.index += 2, \ 687 503 parser->mark.column = 0, \ … … 689 505 parser->unread -= 2, \ 690 506 parser->buffer.pointer += 2) : \ 691 IS_BREAK(parser ) ?\507 IS_BREAK(parser->buffer) ? \ 692 508 (parser->mark.index ++, \ 693 509 parser->mark.column = 0, \ 694 510 parser->mark.line ++, \ 695 511 parser->unread --, \ 696 parser->buffer.pointer += WIDTH(parser )) : 0)512 parser->buffer.pointer += WIDTH(parser->buffer)) : 0) 697 513 698 514 /* … … 702 518 #define READ(parser,string) \ 703 519 (STRING_EXTEND(parser,string) ? \ 704 (((*parser->buffer.pointer & 0x80) == 0x00 ? \ 705 (*((string).pointer++) = *(parser->buffer.pointer++)) : \ 706 (*parser->buffer.pointer & 0xE0) == 0xC0 ? \ 707 (*((string).pointer++) = *(parser->buffer.pointer++), \ 708 *((string).pointer++) = *(parser->buffer.pointer++)) : \ 709 (*parser->buffer.pointer & 0xF0) == 0xE0 ? \ 710 (*((string).pointer++) = *(parser->buffer.pointer++), \ 711 *((string).pointer++) = *(parser->buffer.pointer++), \ 712 *((string).pointer++) = *(parser->buffer.pointer++)) : \ 713 (*parser->buffer.pointer & 0xF8) == 0xF0 ? \ 714 (*((string).pointer++) = *(parser->buffer.pointer++), \ 715 *((string).pointer++) = *(parser->buffer.pointer++), \ 716 *((string).pointer++) = *(parser->buffer.pointer++), \ 717 *((string).pointer++) = *(parser->buffer.pointer++)) : 0), \ 520 (COPY(string,parser->buffer), \ 718 521 parser->mark.index ++, \ 719 522 parser->mark.column ++, \ … … 727 530 #define READ_LINE(parser,string) \ 728 531 (STRING_EXTEND(parser,string) ? \ 729 (((CHECK_AT(parser,'\r',0) && CHECK_AT(parser,'\n',1)) ? /* CR LF -> LF */ \ 532 (((CHECK_AT(parser->buffer,'\r',0) \ 533 && CHECK_AT(parser->buffer,'\n',1)) ? /* CR LF -> LF */ \ 730 534 (*((string).pointer++) = (yaml_char_t) '\n', \ 731 535 parser->buffer.pointer += 2, \ … … 734 538 parser->mark.line ++, \ 735 539 parser->unread -= 2) : \ 736 (CHECK_AT(parser,'\r',0) || CHECK_AT(parser,'\n',0)) ? /* CR|LF -> LF */ \ 540 (CHECK_AT(parser->buffer,'\r',0) \ 541 || CHECK_AT(parser->buffer,'\n',0)) ? /* CR|LF -> LF */ \ 737 542 (*((string).pointer++) = (yaml_char_t) '\n', \ 738 543 parser->buffer.pointer ++, \ … … 741 546 parser->mark.line ++, \ 742 547 parser->unread --) : \ 743 (CHECK_AT(parser,'\xC2',0) && CHECK_AT(parser,'\x85',1)) ? /* NEL -> LF */ \ 548 (CHECK_AT(parser->buffer,'\xC2',0) \ 549 && CHECK_AT(parser->buffer,'\x85',1)) ? /* NEL -> LF */ \ 744 550 (*((string).pointer++) = (yaml_char_t) '\n', \ 745 551 parser->buffer.pointer += 2, \ … … 748 554 parser->mark.line ++, \ 749 555 parser->unread --) : \ 750 (CHECK_AT(parser ,'\xE2',0) &&\751 CHECK_AT(parser ,'\x80',1) &&\752 (CHECK_AT(parser ,'\xA8',2) ||\753 CHECK_AT(parser ,'\xA9',2))) ? /* LS|PS -> LS|PS */\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 */ \ 754 560 (*((string).pointer++) = *(parser->buffer.pointer++), \ 755 561 *((string).pointer++) = *(parser->buffer.pointer++), \ … … 1089 895 /* Is it the end of the stream? */ 1090 896 1091 if (IS_Z(parser ))897 if (IS_Z(parser->buffer)) 1092 898 return yaml_parser_fetch_stream_end(parser); 1093 899 1094 900 /* Is it a directive? */ 1095 901 1096 if (parser->mark.column == 0 && CHECK(parser , '%'))902 if (parser->mark.column == 0 && CHECK(parser->buffer, '%')) 1097 903 return yaml_parser_fetch_directive(parser); 1098 904 … … 1100 906 1101 907 if (parser->mark.column == 0 1102 && CHECK_AT(parser , '-', 0)1103 && CHECK_AT(parser , '-', 1)1104 && CHECK_AT(parser , '-', 2)1105 && IS_BLANKZ_AT(parser , 3))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)) 1106 912 return yaml_parser_fetch_document_indicator(parser, 1107 913 YAML_DOCUMENT_START_TOKEN); … … 1110 916 1111 917 if (parser->mark.column == 0 1112 && CHECK_AT(parser , '.', 0)1113 && CHECK_AT(parser , '.', 1)1114 && CHECK_AT(parser , '.', 2)1115 && IS_BLANKZ_AT(parser , 3))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)) 1116 922 return yaml_parser_fetch_document_indicator(parser, 1117 923 YAML_DOCUMENT_END_TOKEN); … … 1119 925 /* Is it the flow sequence start indicator? */ 1120 926 1121 if (CHECK(parser , '['))927 if (CHECK(parser->buffer, '[')) 1122 928 return yaml_parser_fetch_flow_collection_start(parser, 1123 929 YAML_FLOW_SEQUENCE_START_TOKEN); … … 1125 931 /* Is it the flow mapping start indicator? */ 1126 932 1127 if (CHECK(parser , '{'))933 if (CHECK(parser->buffer, '{')) 1128 934 return yaml_parser_fetch_flow_collection_start(parser, 1129 935 YAML_FLOW_MAPPING_START_TOKEN); … … 1131 937 /* Is it the flow sequence end indicator? */ 1132 938 1133 if (CHECK(parser , ']'))939 if (CHECK(parser->buffer, ']')) 1134 940 return yaml_parser_fetch_flow_collection_end(parser, 1135 941 YAML_FLOW_SEQUENCE_END_TOKEN); … … 1137 943 /* Is it the flow mapping end indicator? */ 1138 944 1139 if (CHECK(parser , '}'))945 if (CHECK(parser->buffer, '}')) 1140 946 return yaml_parser_fetch_flow_collection_end(parser, 1141 947 YAML_FLOW_MAPPING_END_TOKEN); … … 1143 949 /* Is it the flow entry indicator? */ 1144 950 1145 if (CHECK(parser , ','))951 if (CHECK(parser->buffer, ',')) 1146 952 return yaml_parser_fetch_flow_entry(parser); 1147 953 1148 954 /* Is it the block entry indicator? */ 1149 955 1150 if (CHECK(parser , '-') && IS_BLANKZ_AT(parser, 1))956 if (CHECK(parser->buffer, '-') && IS_BLANKZ_AT(parser->buffer, 1)) 1151 957 return yaml_parser_fetch_block_entry(parser); 1152 958 1153 959 /* Is it the key indicator? */ 1154 960 1155 if (CHECK(parser, '?') && (parser->flow_level || IS_BLANKZ_AT(parser, 1))) 961 if (CHECK(parser->buffer, '?') 962 && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1))) 1156 963 return yaml_parser_fetch_key(parser); 1157 964 1158 965 /* Is it the value indicator? */ 1159 966 1160 if (CHECK(parser, ':') && (parser->flow_level || IS_BLANKZ_AT(parser, 1))) 967 if (CHECK(parser->buffer, ':') 968 && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1))) 1161 969 return yaml_parser_fetch_value(parser); 1162 970 1163 971 /* Is it an alias? */ 1164 972 1165 if (CHECK(parser , '*'))973 if (CHECK(parser->buffer, '*')) 1166 974 return yaml_parser_fetch_anchor(parser, YAML_ALIAS_TOKEN); 1167 975 1168 976 /* Is it an anchor? */ 1169 977 1170 if (CHECK(parser , '&'))978 if (CHECK(parser->buffer, '&')) 1171 979 return yaml_parser_fetch_anchor(parser, YAML_ANCHOR_TOKEN); 1172 980 1173 981 /* Is it a tag? */ 1174 982 1175 if (CHECK(parser , '!'))983 if (CHECK(parser->buffer, '!')) 1176 984 return yaml_parser_fetch_tag(parser); 1177 985 1178 986 /* Is it a literal scalar? */ 1179 987 1180 if (CHECK(parser , '|') && !parser->flow_level)988 if (CHECK(parser->buffer, '|') && !parser->flow_level) 1181 989 return yaml_parser_fetch_block_scalar(parser, 1); 1182 990 1183 991 /* Is it a folded scalar? */ 1184 992 1185 if (CHECK(parser , '>') && !parser->flow_level)993 if (CHECK(parser->buffer, '>') && !parser->flow_level) 1186 994 return yaml_parser_fetch_block_scalar(parser, 0); 1187 995 1188 996 /* Is it a single-quoted scalar? */ 1189 997 1190 if (CHECK(parser , '\''))998 if (CHECK(parser->buffer, '\'')) 1191 999 return yaml_parser_fetch_flow_scalar(parser, 1); 1192 1000 1193 1001 /* Is it a double-quoted scalar? */ 1194 1002 1195 if (CHECK(parser , '"'))1003 if (CHECK(parser->buffer, '"')) 1196 1004 return yaml_parser_fetch_flow_scalar(parser, 0); 1197 1005 … … 1215 1023 */ 1216 1024 1217 if (!(IS_BLANKZ(parser) || CHECK(parser, '-') || CHECK(parser, '?') 1218 || CHECK(parser, ':') || CHECK(parser, ',') || CHECK(parser, '[') 1219 || CHECK(parser, ']') || CHECK(parser, '{') || CHECK(parser, '}') 1220 || CHECK(parser, '#') || CHECK(parser, '&') || CHECK(parser, '*') 1221 || CHECK(parser, '!') || CHECK(parser, '|') || CHECK(parser, '>') 1222 || CHECK(parser, '\'') || CHECK(parser, '"') || CHECK(parser, '%') 1223 || CHECK(parser, '@') || CHECK(parser, '`')) || 1224 (CHECK(parser, '-') && !IS_BLANK_AT(parser, 1)) || 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)) || 1225 1036 (!parser->flow_level && 1226 (CHECK(parser, '?') || CHECK(parser, ':')) && !IS_BLANKZ_AT(parser, 1))) 1037 (CHECK(parser->buffer, '?') || CHECK(parser->buffer, ':')) 1038 && !IS_BLANKZ_AT(parser->buffer, 1))) 1227 1039 return yaml_parser_fetch_plain_scalar(parser); 1228 1040 … … 2102 1914 if (!CACHE(parser, 1)) return 0; 2103 1915 2104 if (parser->mark.column == 0 && IS_BOM(parser ))1916 if (parser->mark.column == 0 && IS_BOM(parser->buffer)) 2105 1917 SKIP(parser); 2106 1918 … … 2117 1929 if (!CACHE(parser, 1)) return 0; 2118 1930 2119 while (CHECK(parser ,' ') ||1931 while (CHECK(parser->buffer,' ') || 2120 1932 ((parser->flow_level || !parser->simple_key_allowed) && 2121 CHECK(parser , '\t'))) {1933 CHECK(parser->buffer, '\t'))) { 2122 1934 SKIP(parser); 2123 1935 if (!CACHE(parser, 1)) return 0; … … 2126 1938 /* Eat a comment until a line break. */ 2127 1939 2128 if (CHECK(parser , '#')) {2129 while (!IS_BREAKZ(parser )) {1940 if (CHECK(parser->buffer, '#')) { 1941 while (!IS_BREAKZ(parser->buffer)) { 2130 1942 SKIP(parser); 2131 1943 if (!CACHE(parser, 1)) return 0; … … 2135 1947 /* If it is a line break, eat it. */ 2136 1948 2137 if (IS_BREAK(parser ))1949 if (IS_BREAK(parser->buffer)) 2138 1950 { 2139 1951 if (!CACHE(parser, 2)) return 0; … … 2235 2047 if (!CACHE(parser, 1)) goto error; 2236 2048 2237 while (IS_BLANK(parser )) {2049 while (IS_BLANK(parser->buffer)) { 2238 2050 SKIP(parser); 2239 2051 if (!CACHE(parser, 1)) goto error; 2240 2052 } 2241 2053 2242 if (CHECK(parser , '#')) {2243 while (!IS_BREAKZ(parser )) {2054 if (CHECK(parser->buffer, '#')) { 2055 while (!IS_BREAKZ(parser->buffer)) { 2244 2056 SKIP(parser); 2245 2057 if (!CACHE(parser, 1)) goto error; … … 2249 2061 /* Check if we are at the end of the line. */ 2250 2062 2251 if (!IS_BREAKZ(parser )) {2063 if (!IS_BREAKZ(parser->buffer)) { 2252 2064 yaml_parser_set_scanner_error(parser, "while scanning a directive", 2253 2065 start_mark, "did not found expected comment or line break"); … … 2257 2069 /* Eat a line break. */ 2258 2070 2259 if (IS_BREAK(parser )) {2071 if (IS_BREAK(parser->buffer)) { 2260 2072 if (!CACHE(parser, 2)) goto error; 2261 2073 SKIP_LINE(parser); … … 2295 2107 if (!CACHE(parser, 1)) goto error; 2296 2108 2297 while (IS_ALPHA(parser ))2109 while (IS_ALPHA(parser->buffer)) 2298 2110 { 2299 2111 if (!READ(parser, string)) goto error; … … 2311 2123 /* Check for an blank character after the name. */ 2312 2124 2313 if (!IS_BLANKZ(parser )) {2125 if (!IS_BLANKZ(parser->buffer)) { 2314 2126 yaml_parser_set_scanner_error(parser, "while scanning a directive", 2315 2127 start_mark, "found unexpected non-alphabetical character"); … … 2342 2154 if (!CACHE(parser, 1)) return 0; 2343 2155 2344 while (IS_BLANK(parser )) {2156 while (IS_BLANK(parser->buffer)) { 2345 2157 SKIP(parser); 2346 2158 if (!CACHE(parser, 1)) return 0; … … 2354 2166 /* Eat '.'. */ 2355 2167 2356 if (!CHECK(parser , '.')) {2168 if (!CHECK(parser->buffer, '.')) { 2357 2169 return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", 2358 2170 start_mark, "did not find expected digit or '.' character"); … … 2392 2204 if (!CACHE(parser, 1)) return 0; 2393 2205 2394 while (IS_DIGIT(parser ))2206 while (IS_DIGIT(parser->buffer)) 2395 2207 { 2396 2208 /* Check if the number is too long. */ … … 2401 2213 } 2402 2214 2403 value = value*10 + AS_DIGIT(parser );2215 value = value*10 + AS_DIGIT(parser->buffer); 2404 2216 2405 2217 SKIP(parser); … … 2439 2251 if (!CACHE(parser, 1)) goto error; 2440 2252 2441 while (IS_BLANK(parser )) {2253 while (IS_BLANK(parser->buffer)) { 2442 2254 SKIP(parser); 2443 2255 if (!CACHE(parser, 1)) goto error; … … 2453 2265 if (!CACHE(parser, 1)) goto error; 2454 2266 2455 if (!IS_BLANK(parser )) {2267 if (!IS_BLANK(parser->buffer)) { 2456 2268 yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", 2457 2269 start_mark, "did not find expected whitespace"); … … 2461 2273 /* Eat whitespaces. */ 2462 2274 2463 while (IS_BLANK(parser )) {2275 while (IS_BLANK(parser->buffer)) { 2464 2276 SKIP(parser); 2465 2277 if (!CACHE(parser, 1)) goto error; … … 2475 2287 if (!CACHE(parser, 1)) goto error; 2476 2288 2477 if (!IS_BLANKZ(parser )) {2289 if (!IS_BLANKZ(parser->buffer)) { 2478 2290 yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", 2479 2291 start_mark, "did not find expected whitespace or line break"); … … 2512 2324 if (!CACHE(parser, 1)) goto error; 2513 2325 2514 while (IS_ALPHA(parser )) {2326 while (IS_ALPHA(parser->buffer)) { 2515 2327 if (!READ(parser, string)) goto error; 2516 2328 if (!CACHE(parser, 1)) goto error; … … 2527 2339 */ 2528 2340 2529 if (!length || !(IS_BLANKZ(parser) || CHECK(parser, '?') || CHECK(parser, ':') || 2530 CHECK(parser, ',') || CHECK(parser, ']') || CHECK(parser, '}') || 2531 CHECK(parser, '%') || CHECK(parser, '@') || CHECK(parser, '`'))) { 2341 if (!length || !(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '?') 2342 || CHECK(parser->buffer, ':') || CHECK(parser->buffer, ',') 2343 || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '}') 2344 || CHECK(parser->buffer, '%') || CHECK(parser->buffer, '@') 2345 || CHECK(parser->buffer, '`'))) { 2532 2346 yaml_parser_set_scanner_error(parser, type == YAML_ANCHOR_TOKEN ? 2533 2347 "while scanning an anchor" : "while scanning an alias", start_mark, … … 2569 2383 if (!CACHE(parser, 2)) goto error; 2570 2384 2571 if (CHECK_AT(parser , '<', 1))2385 if (CHECK_AT(parser->buffer, '<', 1)) 2572 2386 { 2573 2387 /* Set the handle to '' */ … … 2589 2403 /* Check for '>' and eat it. */ 2590 2404 2591 if (!CHECK(parser , '>')) {2405 if (!CHECK(parser->buffer, '>')) { 2592 2406 yaml_parser_set_scanner_error(parser, "while scanning a tag", 2593 2407 start_mark, "did not find the expected '>'"); … … 2647 2461 if (!CACHE(parser, 1)) goto error; 2648 2462 2649 if (!IS_BLANKZ(parser )) {2463 if (!IS_BLANKZ(parser->buffer)) { 2650 2464 yaml_parser_set_scanner_error(parser, "while scanning a tag", 2651 2465 start_mark, "did not found expected whitespace or line break"); … … 2683 2497 if (!CACHE(parser, 1)) goto error; 2684 2498 2685 if (!CHECK(parser , '!')) {2499 if (!CHECK(parser->buffer, '!')) { 2686 2500 yaml_parser_set_scanner_error(parser, directive ? 2687 2501 "while scanning a tag directive" : "while scanning a tag", … … 2698 2512 if (!CACHE(parser, 1)) goto error; 2699 2513 2700 while (IS_ALPHA(parser ))2514 while (IS_ALPHA(parser->buffer)) 2701 2515 { 2702 2516 if (!READ(parser, string)) goto error; … … 2706 2520 /* Check if the trailing character is '!' and copy it. */ 2707 2521 2708 if (CHECK(parser , '!'))2522 if (CHECK(parser->buffer, '!')) 2709 2523 { 2710 2524 if (!READ(parser, string)) goto error; … … 2779 2593 */ 2780 2594 2781 while (IS_ALPHA(parser) || CHECK(parser, ';') || CHECK(parser, '/') || 2782 CHECK(parser, '?') || CHECK(parser, ':') || CHECK(parser, '@') || 2783 CHECK(parser, '&') || CHECK(parser, '=') || CHECK(parser, '+') || 2784 CHECK(parser, '$') || CHECK(parser, ',') || CHECK(parser, '.') || 2785 CHECK(parser, '!') || CHECK(parser, '~') || CHECK(parser, '*') || 2786 CHECK(parser, '\'') || CHECK(parser, '(') || CHECK(parser, ')') || 2787 CHECK(parser, '[') || CHECK(parser, ']') || CHECK(parser, '%')) 2595 while (IS_ALPHA(parser->buffer) || CHECK(parser->buffer, ';') 2596 || CHECK(parser->buffer, '/') || CHECK(parser->buffer, '?') 2597 || CHECK(parser->buffer, ':') || CHECK(parser->buffer, '@') 2598 || CHECK(parser->buffer, '&') || CHECK(parser->buffer, '=') 2599 || CHECK(parser->buffer, '+') || CHECK(parser->buffer, '$') 2600 || CHECK(parser->buffer, ',') || CHECK(parser->buffer, '.') 2601 || CHECK(parser->buffer, '!') || CHECK(parser->buffer, '~') 2602 || CHECK(parser->buffer, '*') || CHECK(parser->buffer, '\'') 2603 || CHECK(parser->buffer, '(') || CHECK(parser->buffer, ')') 2604 || CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']') 2605 || CHECK(parser->buffer, '%')) 2788 2606 { 2789 2607 /* Check if it is a URI-escape sequence. */ 2790 2608 2791 if (CHECK(parser , '%')) {2609 if (CHECK(parser->buffer, '%')) { 2792 2610 if (!yaml_parser_scan_uri_escapes(parser, 2793 2611 directive, start_mark, &string)) goto error; … … 2842 2660 if (!CACHE(parser, 3)) return 0; 2843 2661 2844 if (!(CHECK(parser, '%') && IS_HEX_AT(parser, 1) && IS_HEX_AT(parser, 2))) { 2662 if (!(CHECK(parser->buffer, '%') 2663 && IS_HEX_AT(parser->buffer, 1) 2664 && IS_HEX_AT(parser->buffer, 2))) { 2845 2665 return yaml_parser_set_scanner_error(parser, directive ? 2846 2666 "while parsing a %TAG directive" : "while parsing a tag", … … 2850 2670 /* Get the octet. */ 2851 2671 2852 octet = (AS_HEX_AT(parser , 1) << 4) + AS_HEX_AT(parser, 2);2672 octet = (AS_HEX_AT(parser->buffer, 1) << 4) + AS_HEX_AT(parser->buffer, 2); 2853 2673 2854 2674 /* If it is the leading octet, determine the length of the UTF-8 sequence. */ … … 2924 2744 /* Check for a chomping indicator. */ 2925 2745 2926 if (CHECK(parser , '+') || CHECK(parser, '-'))2746 if (CHECK(parser->buffer, '+') || CHECK(parser->buffer, '-')) 2927 2747 { 2928 2748 /* Set the chomping method and eat the indicator. */ 2929 2749 2930 chomping = CHECK(parser , '+') ? +1 : -1;2750 chomping = CHECK(parser->buffer, '+') ? +1 : -1; 2931 2751 2932 2752 SKIP(parser); … … 2936 2756 if (!CACHE(parser, 1)) goto error; 2937 2757 2938 if (IS_DIGIT(parser ))2758 if (IS_DIGIT(parser->buffer)) 2939 2759 { 2940 2760 /* Check that the intendation is greater than 0. */ 2941 2761 2942 if (CHECK(parser , '0')) {2762 if (CHECK(parser->buffer, '0')) { 2943 2763 yaml_parser_set_scanner_error(parser, "while scanning a block scalar", 2944 2764 start_mark, "found an intendation indicator equal to 0"); … … 2948 2768 /* Get the intendation level and eat the indicator. */ 2949 2769 2950 increment = AS_DIGIT(parser );2770 increment = AS_DIGIT(parser->buffer); 2951 2771 2952 2772 SKIP(parser); … … 2956 2776 /* Do the same as above, but in the opposite order. */ 2957 2777 2958 else if (IS_DIGIT(parser ))2778 else if (IS_DIGIT(parser->buffer)) 2959 2779 { 2960 if (CHECK(parser , '0')) {2780 if (CHECK(parser->buffer, '0')) { 2961 2781 yaml_parser_set_scanner_error(parser, "while scanning a block scalar", 2962 2782 start_mark, "found an intendation indicator equal to 0"); … … 2964 2784 } 2965 2785 2966 increment = AS_DIGIT(parser );2786 increment = AS_DIGIT(parser->buffer); 2967 2787 2968 2788 SKIP(parser); … … 2970 2790 if (!CACHE(parser, 1)) goto error; 2971 2791 2972 if (CHECK(parser , '+') || CHECK(parser, '-')) {2973 chomping = CHECK(parser , '+') ? +1 : -1;2792 if (CHECK(parser->buffer, '+') || CHECK(parser->buffer, '-')) { 2793 chomping = CHECK(parser->buffer, '+') ? +1 : -1; 2974 2794 2975 2795 SKIP(parser); … … 2981 2801 if (!CACHE(parser, 1)) goto error; 2982 2802 2983 while (IS_BLANK(parser )) {2803 while (IS_BLANK(parser->buffer)) { 2984 2804 SKIP(parser); 2985 2805 if (!CACHE(parser, 1)) goto error; 2986 2806 } 2987 2807 2988 if (CHECK(parser , '#')) {2989 while (!IS_BREAKZ(parser )) {2808 if (CHECK(parser->buffer, '#')) { 2809 while (!IS_BREAKZ(parser->buffer)) { 2990 2810 SKIP(parser); 2991 2811 if (!CACHE(parser, 1)) goto error; … … 2995 2815 /* Check if we are at the end of the line. */ 2996 2816 2997 if (!IS_BREAKZ(parser )) {2817 if (!IS_BREAKZ(parser->buffer)) { 2998 2818 yaml_parser_set_scanner_error(parser, "while scanning a block scalar", 2999 2819 start_mark, "did not found expected comment or line break"); … … 3003 2823 /* Eat a line break. */ 3004 2824 3005 if (IS_BREAK(parser )) {2825 if (IS_BREAK(parser->buffer)) { 3006 2826 if (!CACHE(parser, 2)) goto error; 3007 2827 SKIP_LINE(parser); … … 3025 2845 if (!CACHE(parser, 1)) goto error; 3026 2846 3027 while (parser->mark.column == indent && !IS_Z(parser ))2847 while (parser->mark.column == indent && !IS_Z(parser->buffer)) 3028 2848 { 3029 2849 /* … … 3033 2853 /* Is it a trailing whitespace? */ 3034 2854 3035 trailing_blank = IS_BLANK(parser );2855 trailing_blank = IS_BLANK(parser->buffer); 3036 2856 3037 2857 /* Check if we need to fold the leading line break. */ … … 3061 2881 /* Is it a leading whitespace? */ 3062 2882 3063 leading_blank = IS_BLANK(parser );2883 leading_blank = IS_BLANK(parser->buffer); 3064 2884 3065 2885 /* Consume the current line. */ 3066 2886 3067 while (!IS_BREAKZ(parser )) {2887 while (!IS_BREAKZ(parser->buffer)) { 3068 2888 if (!READ(parser, string)) goto error; 3069 2889 if (!CACHE(parser, 1)) goto error; … … 3132 2952 if (!CACHE(parser, 1)) return 0; 3133 2953 3134 while ((!*indent || parser->mark.column < *indent) && IS_SPACE(parser)) { 2954 while ((!*indent || parser->mark.column < *indent) 2955 && IS_SPACE(parser->buffer)) { 3135 2956 SKIP(parser); 3136 2957 if (!CACHE(parser, 1)) return 0; … … 3142 2963 /* Check for a tab character messing the intendation. */ 3143 2964 3144 if ((!*indent || parser->mark.column < *indent) && IS_TAB(parser)) { 2965 if ((!*indent || parser->mark.column < *indent) 2966 && IS_TAB(parser->buffer)) { 3145 2967 return yaml_parser_set_scanner_error(parser, "while scanning a block scalar", 3146 2968 start_mark, "found a tab character where an intendation space is expected"); … … 3149 2971 /* Have we found a non-empty line? */ 3150 2972 3151 if (!IS_BREAK(parser )) break;2973 if (!IS_BREAK(parser->buffer)) break; 3152 2974 3153 2975 /* Consume the line break. */ … … 3207 3029 3208 3030 if (parser->mark.column == 0 && 3209 ((CHECK_AT(parser , '-', 0) &&3210 CHECK_AT(parser , '-', 1) &&3211 CHECK_AT(parser , '-', 2)) ||3212 (CHECK_AT(parser , '.', 0) &&3213 CHECK_AT(parser , '.', 1) &&3214 CHECK_AT(parser , '.', 2))) &&3215 IS_BLANKZ_AT(parser , 3))3031 ((CHECK_AT(parser->buffer, '-', 0) && 3032 CHECK_AT(parser->buffer, '-', 1) && 3033 CHECK_AT(parser->buffer, '-', 2)) || 3034 (CHECK_AT(parser->buffer, '.', 0) && 3035 CHECK_AT(parser->buffer, '.', 1) && 3036 CHECK_AT(parser->buffer, '.', 2))) && 3037 IS_BLANKZ_AT(parser->buffer, 3)) 3216 3038 { 3217 3039 yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", … … 3222 3044 /* Check for EOF. */ 3223 3045 3224 if (IS_Z(parser )) {3046 if (IS_Z(parser->buffer)) { 3225 3047 yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", 3226 3048 start_mark, "found unexpected end of stream"); … … 3234 3056 leading_blanks = 0; 3235 3057 3236 while (!IS_BLANKZ(parser ))3058 while (!IS_BLANKZ(parser->buffer)) 3237 3059 { 3238 3060 /* Check for an escaped single quote. */ 3239 3061 3240 if (single && CHECK_AT(parser, '\'', 0) && CHECK_AT(parser, '\'', 1)) 3062 if (single && CHECK_AT(parser->buffer, '\'', 0) 3063 && CHECK_AT(parser->buffer, '\'', 1)) 3241 3064 { 3242 3065 if (!STRING_EXTEND(parser, string)) goto error; … … 3248 3071 /* Check for the right quote. */ 3249 3072 3250 else if (CHECK(parser , single ? '\'' : '"'))3073 else if (CHECK(parser->buffer, single ? '\'' : '"')) 3251 3074 { 3252 3075 break; … … 3255 3078 /* Check for an escaped line break. */ 3256 3079 3257 else if (!single && CHECK(parser, '\\') && IS_BREAK_AT(parser, 1)) 3080 else if (!single && CHECK(parser->buffer, '\\') 3081 && IS_BREAK_AT(parser->buffer, 1)) 3258 3082 { 3259 3083 if (!CACHE(parser, 3)) goto error; … … 3266 3090 /* Check for an escape sequence. */ 3267 3091 3268 else if (!single && CHECK(parser , '\\'))3092 else if (!single && CHECK(parser->buffer, '\\')) 3269 3093 { 3270 3094 int code_length = 0; … … 3384 3208 3385 3209 for (k = 0; k < code_length; k ++) { 3386 if (!IS_HEX_AT(parser , k)) {3210 if (!IS_HEX_AT(parser->buffer, k)) { 3387 3211 yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", 3388 3212 start_mark, "did not find expected hexdecimal number"); 3389 3213 goto error; 3390 3214 } 3391 value = (value << 4) + AS_HEX_AT(parser , k);3215 value = (value << 4) + AS_HEX_AT(parser->buffer, k); 3392 3216 } 3393 3217 … … 3439 3263 /* Check if we are at the end of the scalar. */ 3440 3264 3441 if (CHECK(parser , single ? '\'' : '"'))3265 if (CHECK(parser->buffer, single ? '\'' : '"')) 3442 3266 break; 3443 3267 … … 3446 3270 if (!CACHE(parser, 1)) goto error; 3447 3271 3448 while (IS_BLANK(parser ) || IS_BREAK(parser))3272 while (IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer)) 3449 3273 { 3450 if (IS_BLANK(parser ))3274 if (IS_BLANK(parser->buffer)) 3451 3275 { 3452 3276 /* Consume a space or a tab character. */ … … 3569 3393 3570 3394 if (parser->mark.column == 0 && 3571 ((CHECK_AT(parser , '-', 0) &&3572 CHECK_AT(parser , '-', 1) &&3573 CHECK_AT(parser , '-', 2)) ||3574 (CHECK_AT(parser , '.', 0) &&3575 CHECK_AT(parser , '.', 1) &&3576 CHECK_AT(parser , '.', 2))) &&3577 IS_BLANKZ_AT(parser , 3)) break;3395 ((CHECK_AT(parser->buffer, '-', 0) && 3396 CHECK_AT(parser->buffer, '-', 1) && 3397 CHECK_AT(parser->buffer, '-', 2)) || 3398 (CHECK_AT(parser->buffer, '.', 0) && 3399 CHECK_AT(parser->buffer, '.', 1) && 3400 CHECK_AT(parser->buffer, '.', 2))) && 3401 IS_BLANKZ_AT(parser->buffer, 3)) break; 3578 3402 3579 3403 /* Check for a comment. */ 3580 3404 3581 if (CHECK(parser , '#'))3405 if (CHECK(parser->buffer, '#')) 3582 3406 break; 3583 3407 3584 3408 /* Consume non-blank characters. */ 3585 3409 3586 while (!IS_BLANKZ(parser ))3410 while (!IS_BLANKZ(parser->buffer)) 3587 3411 { 3588 3412 /* Check for 'x:x' in the flow context. TODO: Fix the test "spec-08-13". */ 3589 3413 3590 if (parser->flow_level && CHECK(parser, ':') && !IS_BLANKZ_AT(parser, 1)) { 3414 if (parser->flow_level 3415 && CHECK(parser->buffer, ':') 3416 && !IS_BLANKZ_AT(parser->buffer, 1)) { 3591 3417 yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", 3592 3418 start_mark, "found unexpected ':'"); … … 3596 3422 /* Check for indicators that may end a plain scalar. */ 3597 3423 3598 if ((CHECK(parser , ':') && IS_BLANKZ_AT(parser, 1)) ||3599 (parser->flow_level &&3600 (CHECK(parser, ',') || CHECK(parser, ':') ||3601 CHECK(parser, '?') || CHECK(parser, '[') ||3602 CHECK(parser, ']') || CHECK(parser, '{') ||3603 CHECK(parser, '}'))))3424 if ((CHECK(parser->buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1)) 3425 || (parser->flow_level && 3426 (CHECK(parser->buffer, ',') || CHECK(parser->buffer, ':') 3427 || CHECK(parser->buffer, '?') || CHECK(parser->buffer, '[') 3428 || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{') 3429 || CHECK(parser->buffer, '}')))) 3604 3430 break; 3605 3431 … … 3650 3476 /* Is it the end? */ 3651 3477 3652 if (!(IS_BLANK(parser ) || IS_BREAK(parser)))3478 if (!(IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer))) 3653 3479 break; 3654 3480 … … 3657 3483 if (!CACHE(parser, 1)) goto error; 3658 3484 3659 while (IS_BLANK(parser ) || IS_BREAK(parser))3485 while (IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer)) 3660 3486 { 3661 if (IS_BLANK(parser ))3487 if (IS_BLANK(parser->buffer)) 3662 3488 { 3663 3489 /* Check for tab character that abuse intendation. */ 3664 3490 3665 if (leading_blanks && parser->mark.column < indent && IS_TAB(parser)) { 3491 if (leading_blanks && parser->mark.column < indent 3492 && IS_TAB(parser->buffer)) { 3666 3493 yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", 3667 3494 start_mark, "found a tab character that violate intendation"); -
libyaml/trunk/src/writer.c
r211 r214 37 37 assert(emitter->write_handler); /* Write handler must be set. */ 38 38 assert(emitter->encoding); /* Output encoding must be set. */ 39 40 emitter->buffer.last = emitter->buffer.pointer; 41 emitter->buffer.pointer = emitter->buffer.start; 39 42 40 43 /* Check if the buffer is empty. */ -
libyaml/trunk/src/yaml_private.h
r213 r214 112 112 #define NULL_STRING { NULL, NULL, NULL } 113 113 114 #define STRING(string,length) { (string), (string)+(length), (string) } 115 114 116 #define STRING_INIT(context,string,size) \ 115 117 (((string).start = yaml_malloc(size)) ? \ … … 142 144 ((context)->error = YAML_MEMORY_ERROR, \ 143 145 0)) 146 147 /* 148 * String check operations. 149 */ 150 151 /* 152 * Check the octet at the specified position. 153 */ 154 155 #define CHECK_AT(string,octet,offset) \ 156 ((string).pointer[offset] == (yaml_char_t)(octet)) 157 158 /* 159 * Check the current octet in the buffer. 160 */ 161 162 #define CHECK(string,octet) CHECK_AT((string),(octet),0) 163 164 /* 165 * Check if the character at the specified position is an alphabetical 166 * character, a digit, '_', or '-'. 167 */ 168 169 #define IS_ALPHA_AT(string,offset) \ 170 (((string).pointer[offset] >= (yaml_char_t) '0' && \ 171 (string).pointer[offset] <= (yaml_char_t) '9') || \ 172 ((string).pointer[offset] >= (yaml_char_t) 'A' && \ 173 (string).pointer[offset] <= (yaml_char_t) 'Z') || \ 174 ((string).pointer[offset] >= (yaml_char_t) 'a' && \ 175 (string).pointer[offset] <= (yaml_char_t) 'z') || \ 176 (string).pointer[offset] == '_' || \ 177 (string).pointer[offset] == '-') 178 179 #define IS_ALPHA(string) IS_ALPHA_AT((string),0) 180 181 /* 182 * Check if the character at the specified position is a digit. 183 */ 184 185 #define IS_DIGIT_AT(string,offset) \ 186 (((string).pointer[offset] >= (yaml_char_t) '0' && \ 187 (string).pointer[offset] <= (yaml_char_t) '9')) 188 189 #define IS_DIGIT(string) IS_DIGIT_AT((string),0) 190 191 /* 192 * Get the value of a digit. 193 */ 194 195 #define AS_DIGIT_AT(string,offset) \ 196 ((string).pointer[offset] - (yaml_char_t) '0') 197 198 #define AS_DIGIT(string) AS_DIGIT_AT((string),0) 199 200 /* 201 * Check if the character at the specified position is a hex-digit. 202 */ 203 204 #define IS_HEX_AT(string,offset) \ 205 (((string).pointer[offset] >= (yaml_char_t) '0' && \ 206 (string).pointer[offset] <= (yaml_char_t) '9') || \ 207 ((string).pointer[offset] >= (yaml_char_t) 'A' && \ 208 (string).pointer[offset] <= (yaml_char_t) 'F') || \ 209 ((string).pointer[offset] >= (yaml_char_t) 'a' && \ 210 (string).pointer[offset] <= (yaml_char_t) 'f')) 211 212 #define IS_HEX(string) IS_HEX_AT((string),0) 213 214 /* 215 * Get the value of a hex-digit. 216 */ 217 218 #define AS_HEX_AT(string,offset) \ 219 (((string).pointer[offset] >= (yaml_char_t) 'A' && \ 220 (string).pointer[offset] <= (yaml_char_t) 'F') ? \ 221 ((string).pointer[offset] - (yaml_char_t) 'A' + 10) : \ 222 ((string).pointer[offset] >= (yaml_char_t) 'a' && \ 223 (string).pointer[offset] <= (yaml_char_t) 'f') ? \ 224 ((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \ 225 ((string).pointer[offset] - (yaml_char_t) '0')) 226 227 #define AS_HEX(string) AS_HEX_AT((string),0) 228 229 /* 230 * Check if the character is ASCII. 231 */ 232 233 #define IS_ASCII_AT(string,offset) \ 234 ((string).pointer[offset] <= (yaml_char_t) '\x7F') 235 236 #define IS_ASCII(string) IS_ASCII_AT((string),0) 237 238 /* 239 * Check if the character can be printed unescaped. 240 */ 241 242 #define IS_PRINTABLE_AT(string,offset) \ 243 (((string).pointer[offset] == 0x0A) /* . == #x0A */ \ 244 || ((string).pointer[offset] >= 0x20 /* #x20 <= . <= #x7E */ \ 245 && (string).pointer[offset] <= 0x7E) \ 246 || ((string).pointer[offset] == 0xC2 /* #0xA0 <= . <= #xD7FF */ \ 247 && (string).pointer[offset+1] >= 0xA0) \ 248 || ((string).pointer[offset] > 0xC2 \ 249 && (string).pointer[offset] < 0xED) \ 250 || ((string).pointer[offset] == 0xED \ 251 && (string).pointer[offset+1] < 0xA0) \ 252 || ((string).pointer[offset] == 0xEE) \ 253 || ((string).pointer[offset] == 0xEF /* #xE000 <= . <= #xFFFD */ \ 254 && !((string).pointer[offset+1] == 0xBB /* && . != #xFEFF */ \ 255 && (string).pointer[offset+2] == 0xBF) \ 256 && !((string).pointer[offset+1] == 0xBF \ 257 && ((string).pointer[offset+2] == 0xBE \ 258 || (string).pointer[offset+2] == 0xBF)))) 259 260 #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string),0) 261 262 /* 263 * Check if the character at the specified position is NUL. 264 */ 265 266 #define IS_Z_AT(string,offset) CHECK_AT((string),'\0',(offset)) 267 268 #define IS_Z(string) IS_Z_AT((string),0) 269 270 /* 271 * Check if the character at the specified position is BOM. 272 */ 273 274 #define IS_BOM_AT(string,offset) \ 275 (CHECK_AT((string),'\xEF',(offset)) \ 276 && CHECK_AT((string),'\xBB',(offset)+1) \ 277 && CHECK_AT((string),'\xBF',(offset)+2)) /* BOM (#xFEFF) */ 278 279 #define IS_BOM(string) IS_BOM_AT(string,0) 280 281 /* 282 * Check if the character at the specified position is space. 283 */ 284 285 #define IS_SPACE_AT(string,offset) CHECK_AT((string),' ',(offset)) 286 287 #define IS_SPACE(string) IS_SPACE_AT((string),0) 288 289 /* 290 * Check if the character at the specified position is tab. 291 */ 292 293 #define IS_TAB_AT(string,offset) CHECK_AT((string),'\t',(offset)) 294 295 #define IS_TAB(string) IS_TAB_AT((string),0) 296 297 /* 298 * Check if the character at the specified position is blank (space or tab). 299 */ 300 301 #define IS_BLANK_AT(string,offset) \ 302 (IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset))) 303 304 #define IS_BLANK(string) IS_BLANK_AT((string),0) 305 306 /* 307 * Check if the character at the specified position is a line break. 308 */ 309 310 #define IS_BREAK_AT(string,offset) \ 311 (CHECK_AT((string),'\r',(offset)) /* CR (#xD)*/ \ 312 || CHECK_AT((string),'\n',(offset)) /* LF (#xA) */ \ 313 || (CHECK_AT((string),'\xC2',(offset)) \ 314 && CHECK_AT((string),'\x85',(offset)+1)) /* NEL (#x85) */ \ 315 || (CHECK_AT((string),'\xE2',(offset)) \ 316 && CHECK_AT((string),'\x80',(offset)+1) \ 317 && CHECK_AT((string),'\xA8',(offset)+2)) /* LS (#x2028) */ \ 318 || (CHECK_AT((string),'\xE2',(offset)) \ 319 && CHECK_AT((string),'\x80',(offset)+1) \ 320 && CHECK_AT((string),'\xA9',(offset)+2))) /* PS (#x2029) */ 321 322 #define IS_BREAK(string) IS_BREAK_AT((string),0) 323 324 #define IS_CRLF_AT(string,offset) \ 325 (CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1)) 326 327 #define IS_CRLF(string) IS_CRLF_AT((string),0) 328 329 /* 330 * Check if the character is a line break or NUL. 331 */ 332 333 #define IS_BREAKZ_AT(string,offset) \ 334 (IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset))) 335 336 #define IS_BREAKZ(string) IS_BREAKZ_AT((string),0) 337 338 /* 339 * Check if the character is a line break, space, or NUL. 340 */ 341 342 #define IS_SPACEZ_AT(string,offset) \ 343 (IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset))) 344 345 #define IS_SPACEZ(string) IS_SPACEZ_AT((string),0) 346 347 /* 348 * Check if the character is a line break, space, tab, or NUL. 349 */ 350 351 #define IS_BLANKZ_AT(string,offset) \ 352 (IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset))) 353 354 #define IS_BLANKZ(string) IS_BLANKZ_AT((string),0) 355 356 /* 357 * Determine the width of the character. 358 */ 359 360 #define WIDTH_AT(string,offset) \ 361 (((string).pointer[offset] & 0x80) == 0x00 ? 1 : \ 362 ((string).pointer[offset] & 0xE0) == 0xC0 ? 2 : \ 363 ((string).pointer[offset] & 0xF0) == 0xE0 ? 3 : \ 364 ((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0) 365 366 #define WIDTH(string) WIDTH_AT((string),0) 367 368 /* 369 * Move the string pointer to the next character. 370 */ 371 372 #define MOVE(string) ((string).pointer += WIDTH((string))) 373 374 /* 375 * Copy a character and move the pointers of both strings. 376 */ 377 378 #define COPY(string_a,string_b) \ 379 ((*(string_b).pointer & 0x80) == 0x00 ? \ 380 (*((string_a).pointer++) = *((string_b).pointer++)) : \ 381 (*(string_b).pointer & 0xE0) == 0xC0 ? \ 382 (*((string_a).pointer++) = *((string_b).pointer++), \ 383 *((string_a).pointer++) = *((string_b).pointer++)) : \ 384 (*(string_b).pointer & 0xF0) == 0xE0 ? \ 385 (*((string_a).pointer++) = *((string_b).pointer++), \ 386 *((string_a).pointer++) = *((string_b).pointer++), \ 387 *((string_a).pointer++) = *((string_b).pointer++)) : \ 388 (*(string_b).pointer & 0xF8) == 0xF0 ? \ 389 (*((string_a).pointer++) = *((string_b).pointer++), \ 390 *((string_a).pointer++) = *((string_b).pointer++), \ 391 *((string_a).pointer++) = *((string_b).pointer++), \ 392 *((string_a).pointer++) = *((string_b).pointer++)) : 0) 144 393 145 394 /*
Note: See TracChangeset
for help on using the changeset viewer.
