yamlh.go 22 KB

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