diff --git a/ChangeLog.md b/ChangeLog.md
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,5 +1,9 @@
 # Changelog for libyaml
 
+## 0.1.2
+
+* Upgrade `libyaml` to 0.2.2
+
 ## 0.1.1.1
 
 * Work around GHC 8.6.5 issue on Windows preventing truncated files.  [#178](https://github.com/snoyberg/yaml/issues/178)
diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
 # libyaml
 
-This package provides a haskell wrapper over the [libyaml C library version 0.2.1 by Kirill Simonov](https://github.com/yaml/libyaml). It contains the C source so you don't need to worry about any non-Haskell dependencies.
+This package provides a haskell wrapper over the [libyaml C library version 0.2.2 by Kirill Simonov](https://github.com/yaml/libyaml). It contains the C source so you don't need to worry about any non-Haskell dependencies.
diff --git a/libyaml.cabal b/libyaml.cabal
--- a/libyaml.cabal
+++ b/libyaml.cabal
@@ -4,10 +4,10 @@
 --
 -- see: https://github.com/sol/hpack
 --
--- hash: d35e8c4d317f96574fdc8b6a72f99c2244dacbb949ce1609e8dd56ddbe89a108
+-- hash: 93d917f62be86415287d10db638b1d5422a21b7a4c5b229fbe16b62c47717555
 
 name:           libyaml
-version:        0.1.1.1
+version:        0.1.2
 synopsis:       Low-level, streaming YAML interface.
 description:    README and API documentation are available at <https://www.stackage.org/package/libyaml>
 category:       Text
diff --git a/libyaml_src/LICENSE b/libyaml_src/LICENSE
--- a/libyaml_src/LICENSE
+++ b/libyaml_src/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2017-2018 Ingy döt Net
+Copyright (c) 2017-2019 Ingy döt Net
 Copyright (c) 2006-2016 Kirill Simonov
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of
diff --git a/libyaml_src/dumper.c b/libyaml_src/dumper.c
--- a/libyaml_src/dumper.c
+++ b/libyaml_src/dumper.c
@@ -131,7 +131,7 @@
 
     assert(emitter->opened);    /* Emitter should be opened. */
 
-    emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors))
+    emitter->anchors = (yaml_anchors_t*)yaml_malloc(sizeof(*(emitter->anchors))
             * (document->nodes.top - document->nodes.start));
     if (!emitter->anchors) goto error;
     memset(emitter->anchors, 0, sizeof(*(emitter->anchors))
diff --git a/libyaml_src/emitter.c b/libyaml_src/emitter.c
--- a/libyaml_src/emitter.c
+++ b/libyaml_src/emitter.c
@@ -16,7 +16,7 @@
 #define PUT(emitter,value)                                                      \
     (FLUSH(emitter)                                                             \
      && (*(emitter->buffer.pointer++) = (yaml_char_t)(value),                   \
-         emitter->column ++,                                                    \
+         emitter->column++,                                             	\
          1))
 
 /*
@@ -221,7 +221,7 @@
 
 static int
 yaml_emitter_write_indicator(yaml_emitter_t *emitter,
-        char *indicator, int need_whitespace,
+        const char *indicator, int need_whitespace,
         int is_whitespace, int is_indention);
 
 static int
@@ -649,13 +649,6 @@
 
     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;
@@ -1784,7 +1777,7 @@
 
 static int
 yaml_emitter_write_indicator(yaml_emitter_t *emitter,
-        char *indicator, int need_whitespace,
+        const char *indicator, int need_whitespace,
         int is_whitespace, int is_indention)
 {
     size_t indicator_length;
@@ -1946,6 +1939,10 @@
 
     emitter->whitespace = 0;
     emitter->indention = 0;
+    if (emitter->root_context)
+    {
+        emitter->open_ended = 1;
+    }
 
     return 1;
 }
@@ -2004,6 +2001,9 @@
         }
     }
 
+    if (breaks)
+        if (!yaml_emitter_write_indent(emitter)) return 0;
+
     if (!yaml_emitter_write_indicator(emitter, "'", 0, 0, 0))
         return 0;
 
@@ -2174,7 +2174,7 @@
         yaml_string_t string)
 {
     char indent_hint[2];
-    char *chomp_hint = NULL;
+    const char *chomp_hint = NULL;
 
     if (IS_SPACE(string) || IS_BREAK(string))
     {
diff --git a/libyaml_src/parser.c b/libyaml_src/parser.c
--- a/libyaml_src/parser.c
+++ b/libyaml_src/parser.c
@@ -1316,6 +1316,8 @@
         STACK_DEL(parser, tag_directives);
     }
 
+    if (!version_directive_ref)
+        yaml_free(version_directive);
     return 1;
 
 error:
diff --git a/libyaml_src/scanner.c b/libyaml_src/scanner.c
--- a/libyaml_src/scanner.c
+++ b/libyaml_src/scanner.c
@@ -38,8 +38,8 @@
  *      BLOCK-END                       # Indentation decrease.
  *      FLOW-SEQUENCE-START             # '['
  *      FLOW-SEQUENCE-END               # ']'
- *      BLOCK-SEQUENCE-START            # '{'
- *      BLOCK-SEQUENCE-END              # '}'
+ *      FLOW-MAPPING-START              # '{'
+ *      FLOW-MAPPING-END                # '}'
  *      BLOCK-ENTRY                     # '-'
  *      FLOW-ENTRY                      # ','
  *      KEY                             # '?' or nothing (simple keys).
@@ -1636,7 +1636,7 @@
 
     if (!parser->flow_level)
     {
-        /* Check if we are allowed to start a new key (not nessesary simple). */
+        /* Check if we are allowed to start a new key (not necessary simple). */
 
         if (!parser->simple_key_allowed) {
             return yaml_parser_set_scanner_error(parser, NULL, parser->mark,
@@ -2860,7 +2860,7 @@
 
     if (!CACHE(parser, 1)) goto error;
 
-    while ((int)parser->mark.column == indent && !IS_Z(parser->buffer))
+    while ((int)parser->mark.column == indent && !(IS_Z(parser->buffer)))
     {
         /*
          * We are at the beginning of a non-empty line.
@@ -3430,11 +3430,22 @@
 
         while (!IS_BLANKZ(parser->buffer))
         {
-            /* Check for 'x:x' in the flow context. TODO: Fix the test "spec-08-13". */
+            /* Check for "x:" + one of ',?[]{}' in the flow context. TODO: Fix the test "spec-08-13".
+             * This is not completely according to the spec
+             * See http://yaml.org/spec/1.1/#id907281 9.1.3. Plain
+             */
 
             if (parser->flow_level
                     && CHECK(parser->buffer, ':')
-                    && !IS_BLANKZ_AT(parser->buffer, 1)) {
+                    && (
+                        CHECK_AT(parser->buffer, ',', 1)
+                        || CHECK_AT(parser->buffer, '?', 1)
+                        || CHECK_AT(parser->buffer, '[', 1)
+                        || CHECK_AT(parser->buffer, ']', 1)
+                        || CHECK_AT(parser->buffer, '{', 1)
+                        || CHECK_AT(parser->buffer, '}', 1)
+                    )
+                    ) {
                 yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
                         start_mark, "found unexpected ':'");
                 goto error;
@@ -3444,7 +3455,7 @@
 
             if ((CHECK(parser->buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1))
                     || (parser->flow_level &&
-                        (CHECK(parser->buffer, ',') || CHECK(parser->buffer, ':')
+                        (CHECK(parser->buffer, ',')
                          || CHECK(parser->buffer, '?') || CHECK(parser->buffer, '[')
                          || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{')
                          || CHECK(parser->buffer, '}'))))
diff --git a/libyaml_src/yaml.h b/libyaml_src/yaml.h
--- a/libyaml_src/yaml.h
+++ b/libyaml_src/yaml.h
@@ -232,7 +232,7 @@
 
     /** A BLOCK-SEQUENCE-START token. */
     YAML_BLOCK_SEQUENCE_START_TOKEN,
-    /** A BLOCK-SEQUENCE-END token. */
+    /** A BLOCK-MAPPING-START token. */
     YAML_BLOCK_MAPPING_START_TOKEN,
     /** A BLOCK-END token. */
     YAML_BLOCK_END_TOKEN,
@@ -1517,6 +1517,18 @@
     YAML_EMIT_END_STATE
 } yaml_emitter_state_t;
 
+
+/* This is needed for C++ */
+
+typedef struct yaml_anchors_s {
+    /** The number of references. */
+    int references;
+    /** The anchor id. */
+    int anchor;
+    /** If the node has been emitted? */
+    int serialized;
+} yaml_anchors_t;
+
 /**
  * The emitter structure.
  *
@@ -1742,14 +1754,7 @@
     int closed;
 
     /** The information associated with the document nodes. */
-    struct {
-        /** The number of references. */
-        int references;
-        /** The anchor id. */
-        int anchor;
-        /** If the node has been emitted? */
-        int serialized;
-    } *anchors;
+    yaml_anchors_t *anchors;
 
     /** The last assigned anchor id. */
     int last_anchor_id;
diff --git a/libyaml_src/yaml_private.h b/libyaml_src/yaml_private.h
--- a/libyaml_src/yaml_private.h
+++ b/libyaml_src/yaml_private.h
@@ -1,5 +1,5 @@
 #if HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
 #endif
 
 #include <yaml.h>
@@ -171,14 +171,14 @@
  * Check the octet at the specified position.
  */
 
-#define CHECK_AT(string,octet,offset)                                           \
+#define CHECK_AT(string,octet,offset)                   \
     ((string).pointer[offset] == (yaml_char_t)(octet))
 
 /*
  * Check the current octet in the buffer.
  */
 
-#define CHECK(string,octet) CHECK_AT((string),(octet),0)
+#define CHECK(string,octet) (CHECK_AT((string),(octet),0))
 
 /*
  * Check if the character at the specified position is an alphabetical
@@ -684,7 +684,7 @@
 #define YAML_MALLOC(size)        (yaml_char_t *)yaml_malloc(size)
 
 /* For Haskell yaml package, since we do not use the configure script */
-#define YAML_VERSION_STRING "0.2.1"
+#define YAML_VERSION_STRING "0.2.2"
 #define YAML_VERSION_MAJOR 0
 #define YAML_VERSION_MINOR 2
-#define YAML_VERSION_PATCH 1
+#define YAML_VERSION_PATCH 2
