import streams, unicode, lexbase, tables, strutils, json, hashes, queues type YamlTypeHint* = enum yTypeInteger, yTypeFloat, yTypeBoolean, yTypeNull, yTypeString, yTypeUnknown YamlStreamEventKind* = enum yamlStartDocument, yamlEndDocument, yamlStartMap, yamlEndMap, yamlStartSequence, yamlEndSequence, yamlScalar, yamlAlias, yamlError, yamlWarning TagId* = distinct int AnchorId* = distinct int YamlStreamEvent* = object case kind*: YamlStreamEventKind of yamlStartMap: mapAnchor* : AnchorId mapTag* : TagId mapMayHaveKeyObjects* : bool of yamlStartSequence: seqAnchor* : AnchorId seqTag* : TagId of yamlScalar: scalarAnchor* : AnchorId scalarTag* : TagId scalarContent*: string # may not be nil (but empty) scalarType* : YamlTypeHint of yamlEndMap, yamlEndSequence, yamlStartDocument, yamlEndDocument: discard of yamlAlias: aliasTarget* : AnchorId of yamlError, yamlWarning: description* : string line* : int column* : int YamlStream* = iterator(): YamlStreamEvent YamlTagLibrary* = object tags: Table[string, TagId] nextCustomTagId*: TagId YamlSequentialParser* = ref object tagLib: YamlTagLibrary anchors: OrderedTable[string, AnchorId] YamlDumpStyle* = enum yDumpMinimal, yDumpCanonical, yDumpDefault, yDumpJson, yDumpBlockOnly const # failsafe schema tagExclamationMark*: TagId = 0.TagId ## ``!`` non-specific tag tagQuestionMark* : TagId = 1.TagId ## ``?`` non-specific tag tagString* : TagId = 2.TagId ## \ ## `!!str `_ tag tagSequence* : TagId = 3.TagId ## \ ## `!!seq `_ tag tagMap* : TagId = 4.TagId ## \ ## `!!map `_ tag # json & core schema tagNull* : TagId = 5.TagId ## \ ## `!!null `_ tag tagBoolean* : TagId = 6.TagId ## \ ## `!!bool `_ tag tagInteger* : TagId = 7.TagId ## \ ## `!!int `_ tag tagFloat* : TagId = 8.TagId ## \ ## `!!float `_ tag # other language-independent YAML types (from http://yaml.org/type/ ) tagOrderedMap* : TagId = 9.TagId ## \ ## `!!omap `_ tag tagPairs* : TagId = 10.TagId ## \ ## `!!pairs `_ tag tagSet* : TagId = 11.TagId ## \ ## `!!set `_ tag tagBinary* : TagId = 12.TagId ## \ ## `!!binary `_ tag tagMerge* : TagId = 13.TagId ## \ ## `!!merge `_ tag tagTimestamp* : TagId = 14.TagId ## \ ## `!!timestamp `_ tag tagValue* : TagId = 15.TagId ## \ ## `!!value `_ tag tagYaml* : TagId = 16.TagId ## \ ## `!!yaml `_ tag anchorNone*: AnchorId = (-1).AnchorId # no anchor defined # interface proc `==`*(left: YamlStreamEvent, right: YamlStreamEvent): bool proc `==`*(left, right: TagId): bool {.borrow.} proc `$`*(id: TagId): string {.borrow.} proc hash*(id: TagId): Hash {.borrow.} proc `==`*(left, right: AnchorId): bool {.borrow.} proc `$`*(id: AnchorId): string {.borrow.} proc hash*(id: AnchorId): Hash {.borrow.} proc initTagLibrary*(): YamlTagLibrary proc registerUri*(tagLib: var YamlTagLibrary, uri: string): TagId proc uri*(tagLib: YamlTagLibrary, id: TagId): string # these should be consts, but the Nim VM still has problems handling tables # properly, so we use constructor procs instead. proc failsafeTagLibrary*(): YamlTagLibrary proc coreTagLibrary*(): YamlTagLibrary proc extendedTagLibrary*(): YamlTagLibrary proc newParser*(tagLib: YamlTagLibrary): YamlSequentialParser proc anchor*(parser: YamlSequentialParser, id: AnchorId): string proc parse*(parser: YamlSequentialParser, s: Stream): YamlStream proc parseToJson*(s: Stream): seq[JsonNode] proc parseToJson*(s: string): seq[JsonNode] proc dump*(s: YamlStream, target: Stream, tagLib: YamlTagLibrary, style: YamlDumpStyle = yDumpDefault, indentationStep: int = 2) proc transform*(input: Stream, output: Stream, style: YamlDumpStyle, indentationStep: int = 2) # implementation include private.lexer include private.tagLibrary include private.sequential include private.json include private.dumper