2015-12-28 21:24:05 +00:00
|
|
|
# NimYAML - YAML implementation in Nim
|
|
|
|
# (c) Copyright 2015 Felix Krause
|
|
|
|
#
|
|
|
|
# See the file "copying.txt", included in this
|
|
|
|
# distribution, for details about the copyright.
|
|
|
|
|
2015-12-26 17:40:23 +00:00
|
|
|
proc initTagLibrary*(): YamlTagLibrary =
|
|
|
|
result.tags = initTable[string, TagId]()
|
2015-12-27 22:40:27 +00:00
|
|
|
result.nextCustomTagId = yFirstCustomTagId
|
2016-01-04 20:46:33 +00:00
|
|
|
result.secondaryPrefix = yamlTagRepositoryPrefix
|
2015-12-26 17:40:23 +00:00
|
|
|
|
|
|
|
proc registerUri*(tagLib: var YamlTagLibrary, uri: string): TagId =
|
|
|
|
tagLib.tags[uri] = tagLib.nextCustomTagId
|
|
|
|
result = tagLib.nextCustomTagId
|
|
|
|
tagLib.nextCustomTagId = cast[TagId](cast[int](tagLib.nextCustomTagId) + 1)
|
2016-01-05 15:54:14 +00:00
|
|
|
echo "registered ", uri, " as: ", result
|
2015-12-26 17:40:23 +00:00
|
|
|
|
|
|
|
proc uri*(tagLib: YamlTagLibrary, id: TagId): string =
|
|
|
|
for iUri, iId in tagLib.tags.pairs:
|
|
|
|
if iId == id:
|
|
|
|
return iUri
|
|
|
|
raise newException(KeyError, "Unknown tag id: " & $id)
|
|
|
|
|
|
|
|
proc failsafeTagLibrary*(): YamlTagLibrary =
|
|
|
|
result = initTagLibrary()
|
2015-12-27 22:40:27 +00:00
|
|
|
result.tags["!"] = yTagExclamationMark
|
|
|
|
result.tags["?"] = yTagQuestionMark
|
|
|
|
result.tags["tag:yaml.org,2002:str"] = yTagString
|
|
|
|
result.tags["tag:yaml.org,2002:seq"] = yTagSequence
|
|
|
|
result.tags["tag:yaml.org,2002:map"] = yTagMap
|
2015-12-26 17:40:23 +00:00
|
|
|
|
|
|
|
proc coreTagLibrary*(): YamlTagLibrary =
|
|
|
|
result = failsafeTagLibrary()
|
2015-12-27 22:40:27 +00:00
|
|
|
result.tags["tag:yaml.org,2002:null"] = yTagNull
|
|
|
|
result.tags["tag:yaml.org,2002:bool"] = yTagBoolean
|
|
|
|
result.tags["tag:yaml.org,2002:int"] = yTagInteger
|
|
|
|
result.tags["tag:yaml.org,2002:float"] = yTagFloat
|
2015-12-26 17:40:23 +00:00
|
|
|
|
|
|
|
proc extendedTagLibrary*(): YamlTagLibrary =
|
|
|
|
result = coreTagLibrary()
|
2015-12-27 22:40:27 +00:00
|
|
|
result.tags["tag:yaml.org,2002:omap"] = yTagOrderedMap
|
|
|
|
result.tags["tag:yaml.org,2002:pairs"] = yTagPairs
|
|
|
|
result.tags["tag:yaml.org,2002:binary"] = yTagBinary
|
|
|
|
result.tags["tag:yaml.org,2002:merge"] = yTagMerge
|
|
|
|
result.tags["tag:yaml.org,2002:timestamp"] = yTagTimestamp
|
|
|
|
result.tags["tag:yaml.org,2002:value"] = yTagValue
|
|
|
|
result.tags["tag:yaml.org,2002:yaml"] = yTagYaml
|