yamlh.go 25 KB

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