Skip to content

Commit 6e2fa97

Browse files
authored
Emitter: Output space after an alias mapping key (#185)
Before: a: &b x *b: c Now: a: &b x *b : c Passing tests: * 26DV: Whitespace around colon in mappings * E76Z: Aliases in Implicit Block Mapping * X38W: Aliases in Flow Objects Test manually because `make test-suite` will overwrite changes in the skiplist: ./tests/run-parser-test-suite tests/run-test-suite/data/26DV/in.yaml | ./tests/run-emitter-test-suite ./tests/run-parser-test-suite tests/run-test-suite/data/E76Z/in.yaml | ./tests/run-emitter-test-suite ./tests/run-parser-test-suite tests/run-test-suite/data/X38W/in.yaml | ./tests/run-emitter-test-suite Or edit tests/run-test-suite/test/blacklist/libyaml-emitter and do: (cd tests/run-test-suite; prove -lv test) Also I added some newlines to yaml.h to help identifying states by number.
1 parent f41d360 commit 6e2fa97

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

include/yaml.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,7 @@ typedef enum yaml_parser_state_e {
10201020
YAML_PARSE_DOCUMENT_CONTENT_STATE,
10211021
/** Expect DOCUMENT-END. */
10221022
YAML_PARSE_DOCUMENT_END_STATE,
1023+
10231024
/** Expect a block node. */
10241025
YAML_PARSE_BLOCK_NODE_STATE,
10251026
/** Expect a block node or indentless sequence. */
@@ -1030,6 +1031,7 @@ typedef enum yaml_parser_state_e {
10301031
YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE,
10311032
/** Expect an entry of a block sequence. */
10321033
YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,
1034+
10331035
/** Expect an entry of an indentless sequence. */
10341036
YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE,
10351037
/** Expect the first key of a block mapping. */
@@ -1040,6 +1042,7 @@ typedef enum yaml_parser_state_e {
10401042
YAML_PARSE_BLOCK_MAPPING_VALUE_STATE,
10411043
/** Expect the first entry of a flow sequence. */
10421044
YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE,
1045+
10431046
/** Expect an entry of a flow sequence. */
10441047
YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,
10451048
/** Expect a key of an ordered mapping. */
@@ -1051,6 +1054,7 @@ typedef enum yaml_parser_state_e {
10511054
/** Expect the first key of a flow mapping. */
10521055
YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,
10531056
/** Expect a key of a flow mapping. */
1057+
10541058
YAML_PARSE_FLOW_MAPPING_KEY_STATE,
10551059
/** Expect a value of a flow mapping. */
10561060
YAML_PARSE_FLOW_MAPPING_VALUE_STATE,
@@ -1489,6 +1493,7 @@ typedef enum yaml_emitter_state_e {
14891493
YAML_EMIT_DOCUMENT_CONTENT_STATE,
14901494
/** Expect DOCUMENT-END. */
14911495
YAML_EMIT_DOCUMENT_END_STATE,
1496+
14921497
/** Expect the first item of a flow sequence. */
14931498
YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE,
14941499
/** Expect an item of a flow sequence. */
@@ -1499,6 +1504,7 @@ typedef enum yaml_emitter_state_e {
14991504
YAML_EMIT_FLOW_MAPPING_KEY_STATE,
15001505
/** Expect a value for a simple key of a flow mapping. */
15011506
YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE,
1507+
15021508
/** Expect a value of a flow mapping. */
15031509
YAML_EMIT_FLOW_MAPPING_VALUE_STATE,
15041510
/** Expect the first item of a block sequence. */
@@ -1509,6 +1515,7 @@ typedef enum yaml_emitter_state_e {
15091515
YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE,
15101516
/** Expect the key of a block mapping. */
15111517
YAML_EMIT_BLOCK_MAPPING_KEY_STATE,
1518+
15121519
/** Expect a value for a simple key of a block mapping. */
15131520
YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE,
15141521
/** Expect a value of a block mapping. */

src/emitter.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,8 @@ yaml_emitter_emit_alias(yaml_emitter_t *emitter, SHIM(yaml_event_t *event))
10231023
{
10241024
if (!yaml_emitter_process_anchor(emitter))
10251025
return 0;
1026+
if (emitter->simple_key_context)
1027+
if (!PUT(emitter, ' ')) return 0;
10261028
emitter->state = POP(emitter, emitter->states);
10271029

10281030
return 1;

0 commit comments

Comments
 (0)