1 ! Copyright (C) 2014 Jon Harper.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays assocs byte-arrays hash-sets hashtables calendar
4 help.markup help.syntax kernel linked-assocs math sequences sets
5 strings yaml.ffi yaml.config yaml.conversion ;
13 { $description "Serializes the object into a YAML formatted string with one document representing the object." } ;
20 { $description "Serializes the sequence into a YAML formatted string. Each element is outputted as a YAML document." } ;
27 { $description "Deserializes the YAML formatted string into a Factor array. Each document becomes an element of the array." } ;
34 { $description "Deserializes the YAML formatted string into a Factor object. Throws "
35 { $link yaml-no-document } " when there is no document (for example the empty string)."
39 "Contrary to " { $link yaml-docs> } ", this word only parses the input until one document is produced."
40 " Valid or invalid content after the first document is ignored."
41 " To verifiy that the whole input is one valid YAML document, use "
42 { $link yaml-docs> } " and assert that the length of the output array is 1."
46 HELP: libyaml-emitter-error
48 { "error" yaml_error_type_t } { "problem" string }
50 { $description "yaml_emitter_emit returned with status 0. The slots of this error give more information." } ;
52 HELP: libyaml-initialize-error
53 { $description "yaml_*_initialize returned with status 0. This usually means LibYAML failed to allocate memory." } ;
55 HELP: libyaml-parser-error
57 { "error" yaml_error_type_t } { "problem" string } { "problem_offset" integer } { "problem_value" integer } { "problem_mark" yaml_mark_t } { "context" string } { "context_mark" yaml_mark_t }
59 { $description "yaml_parser_parse returned with status 0. The slots of this error give more information." } ;
61 HELP: yaml-no-document
62 { $description "The input of " { $link yaml> } " had no documents." } ;
64 HELP: yaml-undefined-anchor
66 { "anchor" string } { "anchors" sequence }
68 { $description "The document references an undefined anchor " { $snippet "anchor" } ". For information, the list of currently defined anchors in the document is " { $snippet "anchors" } "." } ;
70 HELP: yaml-unexpected-event
72 { "actual" yaml_event_type_t } { "expected" sequence }
74 { $description "LibYAML produced the unexpected event " { $snippet "actual" } ", but the list of expected events is " { $snippet "expected" } "." } ;
76 HELP: ?apply-merge-key
81 { $description "Merges the value of the !!merge key in " { $snippet "assoc" } } ;
82 { merge ?apply-merge-key } related-words
83 { value scalar-value } related-words
90 { $description "If " { $snippet "obj" } " is hashtable, returns it's default value, else return " { $snippet "obj" } " itself." } ;
92 ARTICLE: "yaml-mapping" "Mapping between Factor and YAML types"
93 { $heading "Types mapping" }
94 "The rules in the table below are used to convert between yaml and factor objects."
95 " They are based on " { $url "http://www.yaml.org/spec/1.2/spec.html" } ", section \"10.3. Core Schema\" and " { $url "http://yaml.org/type/" } ", adapted to factor's conventions."
97 { { $snippet "yaml" } { $snippet "factor" } }
98 { { $snippet "scalars" } "" }
99 { "!!null" { $link f } }
100 { "!!bool" { $link boolean } }
101 { "!!int" { $link integer } }
102 { "!!float" { $link float } }
103 { "!!str" { $link string } }
104 { "!!binary" { $link byte-array } }
105 { "!!timestamp" { $link timestamp } }
106 { { $snippet "sequences" } "" }
107 { "!!seq" { $link array } }
108 { "!!omap" { $link linked-assoc } }
109 { "!!pairs" { $link "alists" } }
110 { { $snippet "mappings" } "" }
111 { "!!map" { $link hashtable } }
112 { "!!set" { $link hash-set } }
113 { { $snippet "special keys" } "" }
114 { "!!merge" { $link yaml-merge } }
115 { "!!value" { $link yaml-value } }
118 { $heading "YAML to Factor Round Tripping" }
119 "The following YAML types are not preserved:"
121 { "!!null -> " { $link boolean } " -> !!bool" }
122 { "!!pairs -> " { $link "alists" } " -> !!seq" }
124 { $heading "Factor to YAML Round Tripping" }
125 "The following Factor types are not preserved, unless another type has precedence:"
127 { { $link assoc } " -> !!map -> " { $link hashtable } }
128 { { $link set } " -> !!set -> " { $link hash-set } }
129 { { $link sequence } " -> !!seq -> " { $link array } }
131 "Examples of type precedence which preserves type: " { $link byte-array } " over " { $link sequence } "."
134 ARTICLE: "yaml-errors" "YAML errors"
135 { $heading "libYAML's errors" }
136 "LibYAML exposes error when parsing/emitting yaml. See " { $url "http://pyyaml.org/wiki/LibYAML" } ". More information is available directly in pyyaml's source code in their C interface. They are groupped in the following errors:"
138 { $link libyaml-parser-error }
139 { $link libyaml-emitter-error }
140 { $link libyaml-initialize-error }
142 { $heading "Conversion errors" }
143 "Additional errors are thrown when converting to/from factor objects:"
145 { $link yaml-undefined-anchor }
146 { $link yaml-no-document }
147 "Or many errors thrown by library words (eg unparseable numbers, converting unsupported objects to yaml, etc)"
150 "The following error probably means that there is a bug in the implementation: " { $link yaml-unexpected-event }
153 ARTICLE: "yaml-keys" "Special mapping keys"
154 "The following special keys have been implemented for !!map. By default, these keys will be taken into account when deserializing yaml documents. To keep the original document structure, configuration variables can be set. See " { $link "yaml-config" } "."
155 { $heading "!!merge" }
156 "See " { $url "http://yaml.org/type/merge.html" } $nl
157 "As per " { $url "http://sourceforge.net/p/yaml/mailman/message/12308050" }
158 ", the merge key is implemented bottom up:" $nl
159 { $unchecked-example "USING: yaml prettyprint ;
167 "H{ { \"baz\" 3 } { \"foo\" 1 } { \"bar\" 2 } }" }
168 { $heading "!!value" }
169 "See " { $url "http://yaml.org/type/value.html" } $nl
170 { $unchecked-example "USING: yaml prettyprint ;
184 H{ { \"link with\" { \"library1.dll\" \"library2.dll\" } } }
185 H{ { \"link with\" { \"library1.dll\" \"library2.dll\" } } }
190 ARTICLE: "yaml" "YAML serialization"
191 "The " { $vocab-link "yaml" } " vocabulary implements YAML serialization/deserialization. It uses LibYAML, a YAML parser and emitter written in C (" { $url "http://pyyaml.org/wiki/LibYAML" } ")."
192 { $heading "Main conversion words" }
199 { $heading "Next topics:" }
208 { $unchecked-example "USING: prettyprint yaml ;"
218 "{ t f \"42\" \"42\" 42 42 42 42.0 42.0 }"
220 { $heading "Output -- human readable" }
221 { $unchecked-example "USING: yaml yaml.config ;"
225 +libyaml-default+ emitter-canonical set
226 +libyaml-default+ emitter-indent set
227 +libyaml-default+ emitter-width set
228 +libyaml-default+ emitter-line-break set
229 t emitter-unicode set
233 { \"name\" \"Mark McGwire\" }
238 { \"name\" \"Sammy Sosa\" }
243 "- name: Mark McGwire
251 { $heading "Output -- verbose" }
252 { $unchecked-example "USING: yaml yaml.config ;"
256 +libyaml-default+ emitter-canonical set
257 +libyaml-default+ emitter-indent set
258 +libyaml-default+ emitter-width set
259 +libyaml-default+ emitter-line-break set
260 t emitter-unicode set
262 { t 32 \"foobar\" { \"nested\" \"list\" } H{ { \"nested\" \"assoc\" } } } >yaml print"
263 "--- !!seq\n- !!bool true\n- !!int 32\n- !!str foobar\n- !!seq\n - !!str nested\n - !!str list\n- !!map\n !!str nested: !!str assoc\n...\n"
269 { >yaml >yaml-docs } related-words
270 { yaml> yaml-docs> } related-words