         [ next-event type>> ] dip =
         [ "wrong event" throw ] unless
     ] with-destructors ;
+
+:: parse-yaml-doc ( parser event -- obj )
+    H{ } clone anchors [
+        parser event next-value
+    ] with-variable ;
 
 :: ?parse-yaml-doc ( parser event -- obj/f ? )
     [


: yaml-assert-ok ( ? -- ) [ "yaml error" throw ] unless ;

: event>scalar ( event -- obj )
    data>> scalar>> construct-scalar ;

: ?scalar-value ( event -- scalar/f f/type )
    dup type>> YAML_SCALAR_EVENT =
    [ event>scalar f ] [ type>> clone f swap ] if ;

! Must not reuse the event struct before with-destructors scope ends
: next-event ( parser event -- event )

            [
                parser event next-event type>>
                YAML_SEQUENCE_END_EVENT = [
                    t done! f f
                ] [
                    event ?scalar-value
                ] if
            ] with-destructors
            done [ 2drop ] [
              [ [ parser event ] dip next-complex-value ] unless ,
            ] if
        ] until
    ] { } make ;

