SyckPatches: emitter.c.diff
| File emitter.c.diff, 5.0 kB (added by xi, 2 years ago) |
|---|
-
emitter.c
old new 359 359 char *anchor_name = NULL; 360 360 int indent = 0; 361 361 long x = 0; 362 SyckLevel *parent; 362 363 SyckLevel *lvl = syck_emitter_current_level( e ); 363 364 364 365 /* … … 386 387 indent = lvl->spaces + e->indent; 387 388 } 388 389 syck_emitter_add_level( e, indent, syck_lvl_open ); 390 parent = lvl; 389 391 lvl = syck_emitter_current_level( e ); 390 392 391 393 /* Look for anchor */ … … 402 404 { 403 405 char *an = S_ALLOC_N( char, strlen( anchor_name ) + 3 ); 404 406 sprintf( an, "&%s ", anchor_name ); 407 408 /* Complex key */ 409 if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1) { 410 syck_emitter_write( e, "? ", 2 ); 411 parent->status = syck_lvl_mapx; 412 } 413 405 414 syck_emitter_write( e, an, strlen( anchor_name ) + 2 ); 406 415 free( an ); 407 416 … … 996 1005 { 997 1006 SyckLevel *parent = syck_emitter_parent_level( e ); 998 1007 SyckLevel *lvl = syck_emitter_current_level( e ); 1008 1009 /* complex key 1010 * There should also be the check "&& style == seq_none", 1011 * but unfortunately syck cannot parse flow collections as simple keys 1012 * now, so we will make a complex key. 1013 * Add the check when syck is able to parse "[]: foo" */ 1014 if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1 ) { 1015 syck_emitter_write( e, "? ", 2 ); 1016 parent->status = syck_lvl_mapx; 1017 } 1018 999 1019 syck_emit_tag( e, tag, "tag:yaml.org,2002:seq" ); 1000 1020 if ( style == seq_inline || ( parent->status == syck_lvl_imap || parent->status == syck_lvl_iseq ) ) { 1001 1021 syck_emitter_write( e, "[", 1 ); … … 1012 1032 { 1013 1033 SyckLevel *parent = syck_emitter_parent_level( e ); 1014 1034 SyckLevel *lvl = syck_emitter_current_level( e ); 1035 1036 /* complex key 1037 * There should also be the check "&& style == map_none", 1038 * but unfortunately syck cannot parse flow collections as simple keys 1039 * now, so we will make a complex key. 1040 * Add the check when syck is able to parse "{}: foo". */ 1041 if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1 ) { 1042 syck_emitter_write( e, "? ", 2 ); 1043 parent->status = syck_lvl_mapx; 1044 } 1045 1015 1046 syck_emit_tag( e, tag, "tag:yaml.org,2002:map" ); 1016 1047 if ( style == map_inline || ( parent->status == syck_lvl_imap || parent->status == syck_lvl_iseq ) ) { 1017 1048 syck_emitter_write( e, "{", 1 ); … … 1035 1066 SyckLevel *parent = syck_emitter_parent_level( e ); 1036 1067 1037 1068 /* seq-in-map shortcut */ 1038 if ( parent->status == syck_lvl_map && lvl->ncount == 0 ) { 1039 /* complex key */ 1040 if ( parent->ncount % 2 == 1 ) { 1041 syck_emitter_write( e, "?", 1 ); 1042 parent->status = syck_lvl_mapx; 1069 if ( parent->status == syck_lvl_mapx && lvl->ncount == 0 ) { 1043 1070 /* shortcut -- the lvl->anctag check should be unneccesary but 1044 1071 * there is a nasty shift/reduce in the parser on this point and 1045 1072 * i'm not ready to tickle it. */ 1046 } else if ( lvl->anctag == 0 ) {1073 if ( parent->ncount % 2 == 0 && lvl->anctag == 0 ) { 1047 1074 lvl->spaces = parent->spaces; 1048 1075 } 1049 1076 } … … 1078 1105 { 1079 1106 SyckLevel *parent = syck_emitter_parent_level( e ); 1080 1107 1081 /* map-in-map */1082 if ( parent->status == syck_lvl_map && lvl->ncount == 0 ) {1083 /* complex key */1084 if ( parent->ncount % 2 == 1 ) {1085 syck_emitter_write( e, "?", 1 );1086 parent->status = syck_lvl_mapx;1087 }1088 }1089 1090 1108 /* map-in-seq shortcut */ 1091 1109 if ( lvl->anctag == 0 && parent->status == syck_lvl_seq && lvl->ncount == 0 ) { 1092 1110 int spcs = ( lvl->spaces - parent->spaces ) - 2; … … 1164 1182 break; 1165 1183 1166 1184 case syck_lvl_iseq: 1167 syck_emitter_write( e, "]\n", 1 ); 1185 syck_emitter_write( e, "]", 1 ); 1186 if ( parent->status == syck_lvl_mapx ) { 1187 syck_emitter_write( e, "\n", 1 ); 1188 } 1168 1189 break; 1169 1190 1170 1191 case syck_lvl_map: 1171 1192 if ( lvl->ncount == 0 ) { 1172 1193 syck_emitter_write( e, "{}\n", 3 ); 1173 1194 } else if ( lvl->ncount % 2 == 1 ) { 1174 syck_emitter_write( e, ": \n", 1 );1195 syck_emitter_write( e, ":", 1 ); 1175 1196 } else if ( parent->status == syck_lvl_mapx ) { 1176 1197 syck_emitter_write( e, "\n", 1 ); 1177 1198 } 1178 1199 break; 1179 1200 1180 1201 case syck_lvl_imap: 1181 syck_emitter_write( e, "}\n", 1 ); 1202 syck_emitter_write( e, "}", 1 ); 1203 if ( parent->status == syck_lvl_mapx ) { 1204 syck_emitter_write( e, "\n", 1 ); 1205 } 1182 1206 break; 1183 1207 1184 1208 default: break;
