! http://yaml.org/type/
CONSTANT: YAML_MERGE_TAG "tag:yaml.org,2002:merge"
+CONSTANT: YAML_VALUE_TAG "tag:yaml.org,2002:value"
! !!!!!!!!!!!!!!
! tag resolution
} cond-case ;
CONSTANT: re-merge R/ <</
+CONSTANT: re-value R/ =/
: (resolve-mapping-key-plain-scalar) ( str -- tag )
{
{ [ re-merge matches? ] [ YAML_MERGE_TAG ] }
+ { [ re-value matches? ] [ YAML_VALUE_TAG ] }
[ drop YAML_STR_TAG ]
} cond-case ;
TUPLE: yaml-merge ;
C: <yaml-merge> yaml-merge
+TUPLE: yaml-value ;
+C: <yaml-value> yaml-value
: construct-scalar ( scalar-event mapping-key? -- scalar )
[ drop value>> ] [ resolve-scalar ] 2bi {
{ YAML_BINARY_TAG [ base64> ] }
{ YAML_TIMESTAMP_TAG [ construct-timestamp ] }
{ YAML_MERGE_TAG [ drop <yaml-merge> ] }
+ { YAML_VALUE_TAG [ drop <yaml-value> ] }
{ YAML_STR_TAG [ ] }
} case ;
M: yaml-merge represent-scalar ( obj -- str ) drop "<<" ;
M: yaml-merge yaml-tag ( obj -- str ) drop YAML_MERGE_TAG ;
+
+M: yaml-value represent-scalar ( obj -- str ) drop "=" ;
+M: yaml-value yaml-tag ( obj -- str ) drop YAML_VALUE_TAG ;
! !!!!!!!!!!!!!!!
! construct-value
-! TODO: find something better to do with '=' ? see http://yaml.org/type/value.html
-! Maybe a global parameter to replace all maps with their default values ? See pyyaml SafeConstructor
-CONSTANT: construct-value-obj {
+CONSTANT: construct-value-unsafe-obj {
H{ { "link with" { "library1.dll" "library2.dll" } } }
H{ {
"link with" {
}
} }
}
+CONSTANT: construct-value-safe-obj {
+ H{ { "link with" { "library1.dll" "library2.dll" } } }
+ H{ { "link with" { "library1.dll" "library2.dll" } } }
+}
CONSTANT: construct-value-str """--- # Old schema
link with:
version: 2.3
"""
-${ construct-value-obj } [ $ construct-value-str yaml-docs> ] unit-test
-${ construct-value-obj } [ $ construct-value-obj >yaml-docs yaml-docs> ] unit-test
+${ construct-value-safe-obj } [ $ construct-value-str yaml-docs> ] unit-test
+${ construct-value-safe-obj } [ $ construct-value-safe-obj >yaml-docs yaml-docs> ] unit-test
! !!!!!!!!!!!!!!!
! errors
: ?apply-merge-key ( assoc -- assoc' )
T{ yaml-merge } over pop-at*
[ merge-value ] [ drop ] if ;
+: ?apply-default-key ( assoc -- obj' )
+ T{ yaml-value } over pop-at* [ nip ] [ drop ] if ;
M: assoc apply-merge-keys
[ [ ?apply-merge-keys ] bi-curry@ bi ] with2 assoc-map!
- ?apply-merge-key ;
+ ?apply-merge-key ?apply-default-key ;
:: parse-yaml-doc ( parser event -- obj )
H{ } clone anchors [
! strings and special keys are the only things that need special treatment
! because they can have the same representation
: emit-mapping-key ( emitter event obj -- )
- dup [ string? ] [ yaml-merge? ] bi or
+ dup { [ string? ] [ yaml-merge? ] [ yaml-value? ] } 1||
[ [ f ] dip emit-mapping-key-scalar ] [ emit-object ] if ;
M: object emit-value ( emitter event anchor obj -- ) emit-scalar ;