~mwhudson/ubuntu/xenial/juju-core/mwhudson

« back to all changes in this revision

Viewing changes to src/launchpad.net/goyaml/yamlh.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package goyaml
 
2
 
 
3
import (
 
4
        "io"
 
5
)
 
6
 
 
7
// The version directive data.
 
8
type yaml_version_directive_t struct {
 
9
        major int8 // The major version number.
 
10
        minor int8 // The minor version number.
 
11
}
 
12
 
 
13
// The tag directive data.
 
14
type yaml_tag_directive_t struct {
 
15
        handle []byte // The tag handle.
 
16
        prefix []byte // The tag prefix.
 
17
}
 
18
 
 
19
type yaml_encoding_t int
 
20
 
 
21
// The stream encoding.
 
22
const (
 
23
        // Let the parser choose the encoding.
 
24
        yaml_ANY_ENCODING yaml_encoding_t = iota
 
25
 
 
26
        yaml_UTF8_ENCODING    // The default UTF-8 encoding.
 
27
        yaml_UTF16LE_ENCODING // The UTF-16-LE encoding with BOM.
 
28
        yaml_UTF16BE_ENCODING // The UTF-16-BE encoding with BOM.
 
29
)
 
30
 
 
31
type yaml_break_t int
 
32
 
 
33
// Line break types.
 
34
const (
 
35
        // Let the parser choose the break type.
 
36
        yaml_ANY_BREAK yaml_break_t = iota
 
37
 
 
38
        yaml_CR_BREAK   // Use CR for line breaks (Mac style).
 
39
        yaml_LN_BREAK   // Use LN for line breaks (Unix style).
 
40
        yaml_CRLN_BREAK // Use CR LN for line breaks (DOS style).
 
41
)
 
42
 
 
43
type yaml_error_type_t int
 
44
 
 
45
// Many bad things could happen with the parser and emitter.
 
46
const (
 
47
        // No error is produced.
 
48
        yaml_NO_ERROR yaml_error_type_t = iota
 
49
 
 
50
        yaml_MEMORY_ERROR   // Cannot allocate or reallocate a block of memory.
 
51
        yaml_READER_ERROR   // Cannot read or decode the input stream.
 
52
        yaml_SCANNER_ERROR  // Cannot scan the input stream.
 
53
        yaml_PARSER_ERROR   // Cannot parse the input stream.
 
54
        yaml_COMPOSER_ERROR // Cannot compose a YAML document.
 
55
        yaml_WRITER_ERROR   // Cannot write to the output stream.
 
56
        yaml_EMITTER_ERROR  // Cannot emit a YAML stream.
 
57
)
 
58
 
 
59
// The pointer position.
 
60
type yaml_mark_t struct {
 
61
        index  int // The position index.
 
62
        line   int // The position line.
 
63
        column int // The position column.
 
64
}
 
65
 
 
66
// Node Styles
 
67
 
 
68
type yaml_style_t int8
 
69
 
 
70
type yaml_scalar_style_t yaml_style_t
 
71
 
 
72
// Scalar styles.
 
73
const (
 
74
        // Let the emitter choose the style.
 
75
        yaml_ANY_SCALAR_STYLE yaml_scalar_style_t = iota
 
76
 
 
77
        yaml_PLAIN_SCALAR_STYLE         // The plain scalar style.
 
78
        yaml_SINGLE_QUOTED_SCALAR_STYLE // The single-quoted scalar style.
 
79
        yaml_DOUBLE_QUOTED_SCALAR_STYLE // The double-quoted scalar style.
 
80
        yaml_LITERAL_SCALAR_STYLE       // The literal scalar style.
 
81
        yaml_FOLDED_SCALAR_STYLE        // The folded scalar style.
 
82
)
 
83
 
 
84
type yaml_sequence_style_t yaml_style_t
 
85
 
 
86
// Sequence styles.
 
87
const (
 
88
        // Let the emitter choose the style.
 
89
        yaml_ANY_SEQUENCE_STYLE yaml_sequence_style_t = iota
 
90
 
 
91
        yaml_BLOCK_SEQUENCE_STYLE // The block sequence style.
 
92
        yaml_FLOW_SEQUENCE_STYLE  // The flow sequence style.
 
93
)
 
94
 
 
95
type yaml_mapping_style_t yaml_style_t
 
96
 
 
97
// Mapping styles.
 
98
const (
 
99
        // Let the emitter choose the style.
 
100
        yaml_ANY_MAPPING_STYLE yaml_mapping_style_t = iota
 
101
 
 
102
        yaml_BLOCK_MAPPING_STYLE // The block mapping style.
 
103
        yaml_FLOW_MAPPING_STYLE  // The flow mapping style.
 
104
)
 
105
 
 
106
// Tokens
 
107
 
 
108
type yaml_token_type_t int
 
109
 
 
110
// Token types.
 
111
const (
 
112
        // An empty token.
 
113
        yaml_NO_TOKEN yaml_token_type_t = iota
 
114
 
 
115
        yaml_STREAM_START_TOKEN // A STREAM-START token.
 
116
        yaml_STREAM_END_TOKEN   // A STREAM-END token.
 
117
 
 
118
        yaml_VERSION_DIRECTIVE_TOKEN // A VERSION-DIRECTIVE token.
 
119
        yaml_TAG_DIRECTIVE_TOKEN     // A TAG-DIRECTIVE token.
 
120
        yaml_DOCUMENT_START_TOKEN    // A DOCUMENT-START token.
 
121
        yaml_DOCUMENT_END_TOKEN      // A DOCUMENT-END token.
 
122
 
 
123
        yaml_BLOCK_SEQUENCE_START_TOKEN // A BLOCK-SEQUENCE-START token.
 
124
        yaml_BLOCK_MAPPING_START_TOKEN  // A BLOCK-SEQUENCE-END token.
 
125
        yaml_BLOCK_END_TOKEN            // A BLOCK-END token.
 
126
 
 
127
        yaml_FLOW_SEQUENCE_START_TOKEN // A FLOW-SEQUENCE-START token.
 
128
        yaml_FLOW_SEQUENCE_END_TOKEN   // A FLOW-SEQUENCE-END token.
 
129
        yaml_FLOW_MAPPING_START_TOKEN  // A FLOW-MAPPING-START token.
 
130
        yaml_FLOW_MAPPING_END_TOKEN    // A FLOW-MAPPING-END token.
 
131
 
 
132
        yaml_BLOCK_ENTRY_TOKEN // A BLOCK-ENTRY token.
 
133
        yaml_FLOW_ENTRY_TOKEN  // A FLOW-ENTRY token.
 
134
        yaml_KEY_TOKEN         // A KEY token.
 
135
        yaml_VALUE_TOKEN       // A VALUE token.
 
136
 
 
137
        yaml_ALIAS_TOKEN  // An ALIAS token.
 
138
        yaml_ANCHOR_TOKEN // An ANCHOR token.
 
139
        yaml_TAG_TOKEN    // A TAG token.
 
140
        yaml_SCALAR_TOKEN // A SCALAR token.
 
141
)
 
142
 
 
143
func (tt yaml_token_type_t) String() string {
 
144
        switch tt {
 
145
        case yaml_NO_TOKEN:
 
146
                return "yaml_NO_TOKEN"
 
147
        case yaml_STREAM_START_TOKEN:
 
148
                return "yaml_STREAM_START_TOKEN"
 
149
        case yaml_STREAM_END_TOKEN:
 
150
                return "yaml_STREAM_END_TOKEN"
 
151
        case yaml_VERSION_DIRECTIVE_TOKEN:
 
152
                return "yaml_VERSION_DIRECTIVE_TOKEN"
 
153
        case yaml_TAG_DIRECTIVE_TOKEN:
 
154
                return "yaml_TAG_DIRECTIVE_TOKEN"
 
155
        case yaml_DOCUMENT_START_TOKEN:
 
156
                return "yaml_DOCUMENT_START_TOKEN"
 
157
        case yaml_DOCUMENT_END_TOKEN:
 
158
                return "yaml_DOCUMENT_END_TOKEN"
 
159
        case yaml_BLOCK_SEQUENCE_START_TOKEN:
 
160
                return "yaml_BLOCK_SEQUENCE_START_TOKEN"
 
161
        case yaml_BLOCK_MAPPING_START_TOKEN:
 
162
                return "yaml_BLOCK_MAPPING_START_TOKEN"
 
163
        case yaml_BLOCK_END_TOKEN:
 
164
                return "yaml_BLOCK_END_TOKEN"
 
165
        case yaml_FLOW_SEQUENCE_START_TOKEN:
 
166
                return "yaml_FLOW_SEQUENCE_START_TOKEN"
 
167
        case yaml_FLOW_SEQUENCE_END_TOKEN:
 
168
                return "yaml_FLOW_SEQUENCE_END_TOKEN"
 
169
        case yaml_FLOW_MAPPING_START_TOKEN:
 
170
                return "yaml_FLOW_MAPPING_START_TOKEN"
 
171
        case yaml_FLOW_MAPPING_END_TOKEN:
 
172
                return "yaml_FLOW_MAPPING_END_TOKEN"
 
173
        case yaml_BLOCK_ENTRY_TOKEN:
 
174
                return "yaml_BLOCK_ENTRY_TOKEN"
 
175
        case yaml_FLOW_ENTRY_TOKEN:
 
176
                return "yaml_FLOW_ENTRY_TOKEN"
 
177
        case yaml_KEY_TOKEN:
 
178
                return "yaml_KEY_TOKEN"
 
179
        case yaml_VALUE_TOKEN:
 
180
                return "yaml_VALUE_TOKEN"
 
181
        case yaml_ALIAS_TOKEN:
 
182
                return "yaml_ALIAS_TOKEN"
 
183
        case yaml_ANCHOR_TOKEN:
 
184
                return "yaml_ANCHOR_TOKEN"
 
185
        case yaml_TAG_TOKEN:
 
186
                return "yaml_TAG_TOKEN"
 
187
        case yaml_SCALAR_TOKEN:
 
188
                return "yaml_SCALAR_TOKEN"
 
189
        }
 
190
        return "<unknown token>"
 
191
}
 
192
 
 
193
// The token structure.
 
194
type yaml_token_t struct {
 
195
        // The token type.
 
196
        typ yaml_token_type_t
 
197
 
 
198
        // The start/end of the token.
 
199
        start_mark, end_mark yaml_mark_t
 
200
 
 
201
        // The stream encoding (for yaml_STREAM_START_TOKEN).
 
202
        encoding yaml_encoding_t
 
203
 
 
204
        // The alias/anchor/scalar value or tag/tag directive handle
 
205
        // (for yaml_ALIAS_TOKEN, yaml_ANCHOR_TOKEN, yaml_SCALAR_TOKEN, yaml_TAG_TOKEN, yaml_TAG_DIRECTIVE_TOKEN).
 
206
        value []byte
 
207
 
 
208
        // The tag suffix (for yaml_TAG_TOKEN).
 
209
        suffix []byte
 
210
 
 
211
        // The tag directive prefix (for yaml_TAG_DIRECTIVE_TOKEN).
 
212
        prefix []byte
 
213
 
 
214
        // The scalar style (for yaml_SCALAR_TOKEN).
 
215
        style yaml_scalar_style_t
 
216
 
 
217
        // The version directive major/minor (for yaml_VERSION_DIRECTIVE_TOKEN).
 
218
        major, minor int8
 
219
}
 
220
 
 
221
// Events
 
222
 
 
223
type yaml_event_type_t int8
 
224
 
 
225
// Event types.
 
226
const (
 
227
        // An empty event.
 
228
        yaml_NO_EVENT yaml_event_type_t = iota
 
229
 
 
230
        yaml_STREAM_START_EVENT   // A STREAM-START event.
 
231
        yaml_STREAM_END_EVENT     // A STREAM-END event.
 
232
        yaml_DOCUMENT_START_EVENT // A DOCUMENT-START event.
 
233
        yaml_DOCUMENT_END_EVENT   // A DOCUMENT-END event.
 
234
        yaml_ALIAS_EVENT          // An ALIAS event.
 
235
        yaml_SCALAR_EVENT         // A SCALAR event.
 
236
        yaml_SEQUENCE_START_EVENT // A SEQUENCE-START event.
 
237
        yaml_SEQUENCE_END_EVENT   // A SEQUENCE-END event.
 
238
        yaml_MAPPING_START_EVENT  // A MAPPING-START event.
 
239
        yaml_MAPPING_END_EVENT    // A MAPPING-END event.
 
240
)
 
241
 
 
242
// The event structure.
 
243
type yaml_event_t struct {
 
244
 
 
245
        // The event type.
 
246
        typ yaml_event_type_t
 
247
 
 
248
        // The start and end of the event.
 
249
        start_mark, end_mark yaml_mark_t
 
250
 
 
251
        // The document encoding (for yaml_STREAM_START_EVENT).
 
252
        encoding yaml_encoding_t
 
253
 
 
254
        // The version directive (for yaml_DOCUMENT_START_EVENT).
 
255
        version_directive *yaml_version_directive_t
 
256
 
 
257
        // The list of tag directives (for yaml_DOCUMENT_START_EVENT).
 
258
        tag_directives []yaml_tag_directive_t
 
259
 
 
260
        // The anchor (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_ALIAS_EVENT).
 
261
        anchor []byte
 
262
 
 
263
        // The tag (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT).
 
264
        tag []byte
 
265
 
 
266
        // The scalar value (for yaml_SCALAR_EVENT).
 
267
        value []byte
 
268
 
 
269
        // Is the document start/end indicator implicit, or the tag optional?
 
270
        // (for yaml_DOCUMENT_START_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_SCALAR_EVENT).
 
271
        implicit bool
 
272
 
 
273
        // Is the tag optional for any non-plain style? (for yaml_SCALAR_EVENT).
 
274
        quoted_implicit bool
 
275
 
 
276
        // The style (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT).
 
277
        style yaml_style_t
 
278
}
 
279
 
 
280
func (e *yaml_event_t) scalar_style() yaml_scalar_style_t     { return yaml_scalar_style_t(e.style) }
 
281
func (e *yaml_event_t) sequence_style() yaml_sequence_style_t { return yaml_sequence_style_t(e.style) }
 
282
func (e *yaml_event_t) mapping_style() yaml_mapping_style_t   { return yaml_mapping_style_t(e.style) }
 
283
 
 
284
// Nodes
 
285
 
 
286
const (
 
287
        yaml_NULL_TAG      = "tag:yaml.org,2002:null"      // The tag !!null with the only possible value: null.
 
288
        yaml_BOOL_TAG      = "tag:yaml.org,2002:bool"      // The tag !!bool with the values: true and false.
 
289
        yaml_STR_TAG       = "tag:yaml.org,2002:str"       // The tag !!str for string values.
 
290
        yaml_INT_TAG       = "tag:yaml.org,2002:int"       // The tag !!int for integer values.
 
291
        yaml_FLOAT_TAG     = "tag:yaml.org,2002:float"     // The tag !!float for float values.
 
292
        yaml_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp" // The tag !!timestamp for date and time values.
 
293
 
 
294
        yaml_SEQ_TAG = "tag:yaml.org,2002:seq" // The tag !!seq is used to denote sequences.
 
295
        yaml_MAP_TAG = "tag:yaml.org,2002:map" // The tag !!map is used to denote mapping.
 
296
 
 
297
        yaml_DEFAULT_SCALAR_TAG   = yaml_STR_TAG // The default scalar tag is !!str.
 
298
        yaml_DEFAULT_SEQUENCE_TAG = yaml_SEQ_TAG // The default sequence tag is !!seq.
 
299
        yaml_DEFAULT_MAPPING_TAG  = yaml_MAP_TAG // The default mapping tag is !!map.
 
300
)
 
301
 
 
302
type yaml_node_type_t int
 
303
 
 
304
// Node types.
 
305
const (
 
306
        // An empty node.
 
307
        yaml_NO_NODE yaml_node_type_t = iota
 
308
 
 
309
        yaml_SCALAR_NODE   // A scalar node.
 
310
        yaml_SEQUENCE_NODE // A sequence node.
 
311
        yaml_MAPPING_NODE  // A mapping node.
 
312
)
 
313
 
 
314
// An element of a sequence node.
 
315
type yaml_node_item_t int
 
316
 
 
317
// An element of a mapping node.
 
318
type yaml_node_pair_t struct {
 
319
        key   int // The key of the element.
 
320
        value int // The value of the element.
 
321
}
 
322
 
 
323
// The node structure.
 
324
type yaml_node_t struct {
 
325
        typ yaml_node_type_t // The node type.
 
326
        tag []byte           // The node tag.
 
327
 
 
328
        // The node data.
 
329
 
 
330
        // The scalar parameters (for yaml_SCALAR_NODE).
 
331
        scalar struct {
 
332
                value  []byte              // The scalar value.
 
333
                length int                 // The length of the scalar value.
 
334
                style  yaml_scalar_style_t // The scalar style.
 
335
        }
 
336
 
 
337
        // The sequence parameters (for YAML_SEQUENCE_NODE).
 
338
        sequence struct {
 
339
                items_data []yaml_node_item_t    // The stack of sequence items.
 
340
                style      yaml_sequence_style_t // The sequence style.
 
341
        }
 
342
 
 
343
        // The mapping parameters (for yaml_MAPPING_NODE).
 
344
        mapping struct {
 
345
                pairs_data  []yaml_node_pair_t   // The stack of mapping pairs (key, value).
 
346
                pairs_start *yaml_node_pair_t    // The beginning of the stack.
 
347
                pairs_end   *yaml_node_pair_t    // The end of the stack.
 
348
                pairs_top   *yaml_node_pair_t    // The top of the stack.
 
349
                style       yaml_mapping_style_t // The mapping style.
 
350
        }
 
351
 
 
352
        start_mark yaml_mark_t // The beginning of the node.
 
353
        end_mark   yaml_mark_t // The end of the node.
 
354
 
 
355
}
 
356
 
 
357
// The document structure.
 
358
type yaml_document_t struct {
 
359
 
 
360
        // The document nodes.
 
361
        nodes []yaml_node_t
 
362
 
 
363
        // The version directive.
 
364
        version_directive *yaml_version_directive_t
 
365
 
 
366
        // The list of tag directives.
 
367
        tag_directives_data  []yaml_tag_directive_t
 
368
        tag_directives_start int // The beginning of the tag directives list.
 
369
        tag_directives_end   int // The end of the tag directives list.
 
370
 
 
371
        start_implicit int // Is the document start indicator implicit?
 
372
        end_implicit   int // Is the document end indicator implicit?
 
373
 
 
374
        // The start/end of the document.
 
375
        start_mark, end_mark yaml_mark_t
 
376
}
 
377
 
 
378
// The prototype of a read handler.
 
379
//
 
380
// The read handler is called when the parser needs to read more bytes from the
 
381
// source. The handler should write not more than size bytes to the buffer.
 
382
// The number of written bytes should be set to the size_read variable.
 
383
//
 
384
// [in,out]   data        A pointer to an application data specified by
 
385
//                        yaml_parser_set_input().
 
386
// [out]      buffer      The buffer to write the data from the source.
 
387
// [in]       size        The size of the buffer.
 
388
// [out]      size_read   The actual number of bytes read from the source.
 
389
//
 
390
// On success, the handler should return 1.  If the handler failed,
 
391
// the returned value should be 0. On EOF, the handler should set the
 
392
// size_read to 0 and return 1.
 
393
type yaml_read_handler_t func(parser *yaml_parser_t, buffer []byte) (n int, err error)
 
394
 
 
395
// This structure holds information about a potential simple key.
 
396
type yaml_simple_key_t struct {
 
397
        possible     bool        // Is a simple key possible?
 
398
        required     bool        // Is a simple key required?
 
399
        token_number int         // The number of the token.
 
400
        mark         yaml_mark_t // The position mark.
 
401
}
 
402
 
 
403
// The states of the parser.
 
404
type yaml_parser_state_t int
 
405
 
 
406
const (
 
407
        yaml_PARSE_STREAM_START_STATE yaml_parser_state_t = iota
 
408
 
 
409
        yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE           // Expect the beginning of an implicit document.
 
410
        yaml_PARSE_DOCUMENT_START_STATE                    // Expect DOCUMENT-START.
 
411
        yaml_PARSE_DOCUMENT_CONTENT_STATE                  // Expect the content of a document.
 
412
        yaml_PARSE_DOCUMENT_END_STATE                      // Expect DOCUMENT-END.
 
413
        yaml_PARSE_BLOCK_NODE_STATE                        // Expect a block node.
 
414
        yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE // Expect a block node or indentless sequence.
 
415
        yaml_PARSE_FLOW_NODE_STATE                         // Expect a flow node.
 
416
        yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE        // Expect the first entry of a block sequence.
 
417
        yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE              // Expect an entry of a block sequence.
 
418
        yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE         // Expect an entry of an indentless sequence.
 
419
        yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE           // Expect the first key of a block mapping.
 
420
        yaml_PARSE_BLOCK_MAPPING_KEY_STATE                 // Expect a block mapping key.
 
421
        yaml_PARSE_BLOCK_MAPPING_VALUE_STATE               // Expect a block mapping value.
 
422
        yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE         // Expect the first entry of a flow sequence.
 
423
        yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE               // Expect an entry of a flow sequence.
 
424
        yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE   // Expect a key of an ordered mapping.
 
425
        yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE // Expect a value of an ordered mapping.
 
426
        yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE   // Expect the and of an ordered mapping entry.
 
427
        yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE            // Expect the first key of a flow mapping.
 
428
        yaml_PARSE_FLOW_MAPPING_KEY_STATE                  // Expect a key of a flow mapping.
 
429
        yaml_PARSE_FLOW_MAPPING_VALUE_STATE                // Expect a value of a flow mapping.
 
430
        yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE          // Expect an empty value of a flow mapping.
 
431
        yaml_PARSE_END_STATE                               // Expect nothing.
 
432
)
 
433
 
 
434
func (ps yaml_parser_state_t) String() string {
 
435
        switch ps {
 
436
        case yaml_PARSE_STREAM_START_STATE:
 
437
                return "yaml_PARSE_STREAM_START_STATE"
 
438
        case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE:
 
439
                return "yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE"
 
440
        case yaml_PARSE_DOCUMENT_START_STATE:
 
441
                return "yaml_PARSE_DOCUMENT_START_STATE"
 
442
        case yaml_PARSE_DOCUMENT_CONTENT_STATE:
 
443
                return "yaml_PARSE_DOCUMENT_CONTENT_STATE"
 
444
        case yaml_PARSE_DOCUMENT_END_STATE:
 
445
                return "yaml_PARSE_DOCUMENT_END_STATE"
 
446
        case yaml_PARSE_BLOCK_NODE_STATE:
 
447
                return "yaml_PARSE_BLOCK_NODE_STATE"
 
448
        case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE:
 
449
                return "yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE"
 
450
        case yaml_PARSE_FLOW_NODE_STATE:
 
451
                return "yaml_PARSE_FLOW_NODE_STATE"
 
452
        case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE:
 
453
                return "yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE"
 
454
        case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE:
 
455
                return "yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE"
 
456
        case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE:
 
457
                return "yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE"
 
458
        case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE:
 
459
                return "yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE"
 
460
        case yaml_PARSE_BLOCK_MAPPING_KEY_STATE:
 
461
                return "yaml_PARSE_BLOCK_MAPPING_KEY_STATE"
 
462
        case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE:
 
463
                return "yaml_PARSE_BLOCK_MAPPING_VALUE_STATE"
 
464
        case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE:
 
465
                return "yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE"
 
466
        case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE:
 
467
                return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE"
 
468
        case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE:
 
469
                return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE"
 
470
        case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE:
 
471
                return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE"
 
472
        case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE:
 
473
                return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE"
 
474
        case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE:
 
475
                return "yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE"
 
476
        case yaml_PARSE_FLOW_MAPPING_KEY_STATE:
 
477
                return "yaml_PARSE_FLOW_MAPPING_KEY_STATE"
 
478
        case yaml_PARSE_FLOW_MAPPING_VALUE_STATE:
 
479
                return "yaml_PARSE_FLOW_MAPPING_VALUE_STATE"
 
480
        case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE:
 
481
                return "yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE"
 
482
        case yaml_PARSE_END_STATE:
 
483
                return "yaml_PARSE_END_STATE"
 
484
        }
 
485
        return "<unknown parser state>"
 
486
}
 
487
 
 
488
// This structure holds aliases data.
 
489
type yaml_alias_data_t struct {
 
490
        anchor []byte      // The anchor.
 
491
        index  int         // The node id.
 
492
        mark   yaml_mark_t // The anchor mark.
 
493
}
 
494
 
 
495
// The parser structure.
 
496
//
 
497
// All members are internal. Manage the structure using the
 
498
// yaml_parser_ family of functions.
 
499
type yaml_parser_t struct {
 
500
 
 
501
        // Error handling
 
502
 
 
503
        error yaml_error_type_t // Error type.
 
504
 
 
505
        problem string // Error description.
 
506
 
 
507
        // The byte about which the problem occured.
 
508
        problem_offset int
 
509
        problem_value  int
 
510
        problem_mark   yaml_mark_t
 
511
 
 
512
        // The error context.
 
513
        context      string
 
514
        context_mark yaml_mark_t
 
515
 
 
516
        // Reader stuff
 
517
 
 
518
        read_handler yaml_read_handler_t // Read handler.
 
519
 
 
520
        input_file io.Reader // File input data.
 
521
        input      []byte    // String input data.
 
522
        input_pos  int
 
523
 
 
524
        eof bool // EOF flag
 
525
 
 
526
        buffer     []byte // The working buffer.
 
527
        buffer_pos int    // The current position of the buffer.
 
528
 
 
529
        unread int // The number of unread characters in the buffer.
 
530
 
 
531
        raw_buffer     []byte // The raw buffer.
 
532
        raw_buffer_pos int    // The current position of the buffer.
 
533
 
 
534
        encoding yaml_encoding_t // The input encoding.
 
535
 
 
536
        offset int         // The offset of the current position (in bytes).
 
537
        mark   yaml_mark_t // The mark of the current position.
 
538
 
 
539
        // Scanner stuff
 
540
 
 
541
        stream_start_produced bool // Have we started to scan the input stream?
 
542
        stream_end_produced   bool // Have we reached the end of the input stream?
 
543
 
 
544
        flow_level int // The number of unclosed '[' and '{' indicators.
 
545
 
 
546
        tokens          []yaml_token_t // The tokens queue.
 
547
        tokens_head     int            // The head of the tokens queue.
 
548
        tokens_parsed   int            // The number of tokens fetched from the queue.
 
549
        token_available bool           // Does the tokens queue contain a token ready for dequeueing.
 
550
 
 
551
        indent  int   // The current indentation level.
 
552
        indents []int // The indentation levels stack.
 
553
 
 
554
        simple_key_allowed bool                // May a simple key occur at the current position?
 
555
        simple_keys        []yaml_simple_key_t // The stack of simple keys.
 
556
 
 
557
        // Parser stuff
 
558
 
 
559
        state          yaml_parser_state_t    // The current parser state.
 
560
        states         []yaml_parser_state_t  // The parser states stack.
 
561
        marks          []yaml_mark_t          // The stack of marks.
 
562
        tag_directives []yaml_tag_directive_t // The list of TAG directives.
 
563
 
 
564
        // Dumper stuff
 
565
 
 
566
        aliases []yaml_alias_data_t // The alias data.
 
567
 
 
568
        document *yaml_document_t // The currently parsed document.
 
569
}
 
570
 
 
571
// Emitter Definitions
 
572
 
 
573
// The prototype of a write handler.
 
574
//
 
575
// The write handler is called when the emitter needs to flush the accumulated
 
576
// characters to the output.  The handler should write @a size bytes of the
 
577
// @a buffer to the output.
 
578
//
 
579
// @param[in,out]   data        A pointer to an application data specified by
 
580
//                              yaml_emitter_set_output().
 
581
// @param[in]       buffer      The buffer with bytes to be written.
 
582
// @param[in]       size        The size of the buffer.
 
583
//
 
584
// @returns On success, the handler should return @c 1.  If the handler failed,
 
585
// the returned value should be @c 0.
 
586
//
 
587
type yaml_write_handler_t func(emitter *yaml_emitter_t, buffer []byte) error
 
588
 
 
589
type yaml_emitter_state_t int
 
590
 
 
591
// The emitter states.
 
592
const (
 
593
        // Expect STREAM-START.
 
594
        yaml_EMIT_STREAM_START_STATE yaml_emitter_state_t = iota
 
595
 
 
596
        yaml_EMIT_FIRST_DOCUMENT_START_STATE       // Expect the first DOCUMENT-START or STREAM-END.
 
597
        yaml_EMIT_DOCUMENT_START_STATE             // Expect DOCUMENT-START or STREAM-END.
 
598
        yaml_EMIT_DOCUMENT_CONTENT_STATE           // Expect the content of a document.
 
599
        yaml_EMIT_DOCUMENT_END_STATE               // Expect DOCUMENT-END.
 
600
        yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE   // Expect the first item of a flow sequence.
 
601
        yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE         // Expect an item of a flow sequence.
 
602
        yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE     // Expect the first key of a flow mapping.
 
603
        yaml_EMIT_FLOW_MAPPING_KEY_STATE           // Expect a key of a flow mapping.
 
604
        yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE  // Expect a value for a simple key of a flow mapping.
 
605
        yaml_EMIT_FLOW_MAPPING_VALUE_STATE         // Expect a value of a flow mapping.
 
606
        yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE  // Expect the first item of a block sequence.
 
607
        yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE        // Expect an item of a block sequence.
 
608
        yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE    // Expect the first key of a block mapping.
 
609
        yaml_EMIT_BLOCK_MAPPING_KEY_STATE          // Expect the key of a block mapping.
 
610
        yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a block mapping.
 
611
        yaml_EMIT_BLOCK_MAPPING_VALUE_STATE        // Expect a value of a block mapping.
 
612
        yaml_EMIT_END_STATE                        // Expect nothing.
 
613
)
 
614
 
 
615
// The emitter structure.
 
616
//
 
617
// All members are internal.  Manage the structure using the @c yaml_emitter_
 
618
// family of functions.
 
619
type yaml_emitter_t struct {
 
620
 
 
621
        // Error handling
 
622
 
 
623
        error   yaml_error_type_t // Error type.
 
624
        problem string            // Error description.
 
625
 
 
626
        // Writer stuff
 
627
 
 
628
        write_handler yaml_write_handler_t // Write handler.
 
629
 
 
630
        output_buffer *[]byte   // String output data.
 
631
        output_file   io.Writer // File output data.
 
632
 
 
633
        buffer     []byte // The working buffer.
 
634
        buffer_pos int    // The current position of the buffer.
 
635
 
 
636
        raw_buffer     []byte // The raw buffer.
 
637
        raw_buffer_pos int    // The current position of the buffer.
 
638
 
 
639
        encoding yaml_encoding_t // The stream encoding.
 
640
 
 
641
        // Emitter stuff
 
642
 
 
643
        canonical   bool         // If the output is in the canonical style?
 
644
        best_indent int          // The number of indentation spaces.
 
645
        best_width  int          // The preferred width of the output lines.
 
646
        unicode     bool         // Allow unescaped non-ASCII characters?
 
647
        line_break  yaml_break_t // The preferred line break.
 
648
 
 
649
        state  yaml_emitter_state_t   // The current emitter state.
 
650
        states []yaml_emitter_state_t // The stack of states.
 
651
 
 
652
        events      []yaml_event_t // The event queue.
 
653
        events_head int            // The head of the event queue.
 
654
 
 
655
        indents []int // The stack of indentation levels.
 
656
 
 
657
        tag_directives []yaml_tag_directive_t // The list of tag directives.
 
658
 
 
659
        indent int // The current indentation level.
 
660
 
 
661
        flow_level int // The current flow level.
 
662
 
 
663
        root_context       bool // Is it the document root context?
 
664
        sequence_context   bool // Is it a sequence context?
 
665
        mapping_context    bool // Is it a mapping context?
 
666
        simple_key_context bool // Is it a simple mapping key context?
 
667
 
 
668
        line       int  // The current line.
 
669
        column     int  // The current column.
 
670
        whitespace bool // If the last character was a whitespace?
 
671
        indention  bool // If the last character was an indentation character (' ', '-', '?', ':')?
 
672
        open_ended bool // If an explicit document end is required?
 
673
 
 
674
        // Anchor analysis.
 
675
        anchor_data struct {
 
676
                anchor []byte // The anchor value.
 
677
                alias  bool   // Is it an alias?
 
678
        }
 
679
 
 
680
        // Tag analysis.
 
681
        tag_data struct {
 
682
                handle []byte // The tag handle.
 
683
                suffix []byte // The tag suffix.
 
684
        }
 
685
 
 
686
        // Scalar analysis.
 
687
        scalar_data struct {
 
688
                value                 []byte              // The scalar value.
 
689
                multiline             bool                // Does the scalar contain line breaks?
 
690
                flow_plain_allowed    bool                // Can the scalar be expessed in the flow plain style?
 
691
                block_plain_allowed   bool                // Can the scalar be expressed in the block plain style?
 
692
                single_quoted_allowed bool                // Can the scalar be expressed in the single quoted style?
 
693
                block_allowed         bool                // Can the scalar be expressed in the literal or folded styles?
 
694
                style                 yaml_scalar_style_t // The output style.
 
695
        }
 
696
 
 
697
        // Dumper stuff
 
698
 
 
699
        opened bool // If the stream was already opened?
 
700
        closed bool // If the stream was already closed?
 
701
 
 
702
        // The information associated with the document nodes.
 
703
        anchors *struct {
 
704
                references int  // The number of references.
 
705
                anchor     int  // The anchor id.
 
706
                serialized bool // If the node has been emitted?
 
707
        }
 
708
 
 
709
        last_anchor_id int // The last assigned anchor id.
 
710
 
 
711
        document *yaml_document_t // The currently emitted document.
 
712
}