Commits

Kirill Simonov committed 411281b

Fixed emitting folded scalars with trailing breaks; Forced emitting of a document end indicator when there is a possibility of ambiguous parsing.

Comments (0)

Files changed (2)

     int whitespace;
     /** If the last character was an indentation character (' ', '-', '?', ':')? */
     int indention;
+    /** If an explicit document end is required? */
+    int open_ended;
 
     /** Anchor analysis. */
     struct {
             implicit = 0;
         }
 
+        if ((event->data.document_start.version_directive ||
+                    (event->data.document_start.tag_directives.start
+                     != event->data.document_start.tag_directives.end)) &&
+                emitter->open_ended)
+        {
+            if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
+                return 0;
+            if (!yaml_emitter_write_indent(emitter))
+                return 0;
+        }
+
         if (event->data.document_start.version_directive) {
             implicit = 0;
             if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0))
 
     else if (event->type == YAML_STREAM_END_EVENT)
     {
+        if (emitter->open_ended)
+        {
+            if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
+                return 0;
+            if (!yaml_emitter_write_indent(emitter))
+                return 0;
+        }
+
         if (!yaml_emitter_flush(emitter))
             return 0;
 
 
     emitter->whitespace = is_whitespace;
     emitter->indention = (emitter->indention && is_indention);
+    emitter->open_ended = 0;
 
     return 1;
 }
 
     emitter->whitespace = 0;
     emitter->indention = 0;
+    if (emitter->root_context)
+    {
+        emitter->open_ended = 1;
+    }
 
     return 1;
 }
             return 0;
     }
 
+    emitter->open_ended = 0;
+
     string.pointer = string.end;
     if (string.start == string.pointer)
     {
         else if (string.start == string.pointer)
         {
             chomp_hint = "+";
+            emitter->open_ended = 1;
         }
         else
         {
             if (IS_BREAK(string))
             {
                 chomp_hint = "+";
+                emitter->open_ended = 1;
             }
         }
     }
                 while (IS_BREAK_AT(string, k)) {
                     k += WIDTH_AT(string, k);
                 }
-                if (!IS_BLANK_AT(string, k)) {
+                if (!IS_BLANKZ_AT(string, k)) {
                     if (!PUT_BREAK(emitter)) return 0;
                 }
             }