http urls monitor.

yamlh.go 25KB

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