]> gitweb.factorcode.org Git - factor.git/commitdiff
YAML: support non-scalar keys
authorJon Harper <jon.harper87@gmail.com>
Sat, 15 Feb 2014 17:28:15 +0000 (18:28 +0100)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 27 Apr 2014 22:24:22 +0000 (15:24 -0700)
extra/yaml/yaml-tests.factor
extra/yaml/yaml.factor

index b203c86b1faeebf9c36969aca801b0437bd58936..3b6411fa32b23b33cb5f4deadacfba9873e3461f 100644 (file)
@@ -35,3 +35,13 @@ CONSTANT: test-represented-string """--- !!seq
 ${ test-obj } [ $ test-string yaml> ] unit-test
 ${ test-represented-string } [ $ test-obj >yaml ] unit-test
 ${ test-represented-string } [ $ test-represented-string yaml> >yaml ] unit-test
+
+CONSTANT: complex-key H{ { { "4" } "3" } }
+CONSTANT: complex-key-represented """--- !!map
+? !!seq
+- !!str 4
+: !!str 3
+...
+"""
+
+${ complex-key } [ $ complex-key-represented yaml> ] unit-test
index 67e51e4601a7e39e29564badb55fd504807820b2..75fe9ffbcd8fdf5ddcc318f2c221388523b5388e 100644 (file)
@@ -34,9 +34,12 @@ DEFER: parse-mapping
     YAML_MAPPING_END_EVENT = [
       t done! f f
     ] [
-      event event>scalar t
+      event ?scalar-value
     ] if
-  ] with-destructors [ parser event next-value swap ,, ] [ drop ] if ] until
+  ] with-destructors 2dup or [
+    [ nip [ parser event ] dip next-complex-value ] when*
+    parser event next-value swap ,,
+  ] [ 2drop ] if ] until
 ] H{ } make ;
 :: parse-sequence ( parser event -- seq ) [
   f :> done!