diff --git a/doc/rstPreproc.nim b/doc/rstPreproc.nim index 92dfae4..e8efd29 100644 --- a/doc/rstPreproc.nim +++ b/doc/rstPreproc.nim @@ -17,11 +17,11 @@ ## available as source files for automatic testing. This way, we can make sure ## that the code in the docs actually works. -import parseopt2, streams, tables, strutils, os +import parseopt2, streams, tables, strutils, os, options var infile = "" - path: string = nil + path = none(string) for kind, key, val in getopt(): case kind of cmdArgument: @@ -36,7 +36,7 @@ for kind, key, val in getopt(): of cmdLongOption, cmdShortOption: case key of "out", "o": - if isNil(path): path = val + if path.isNone: path = some(val) else: echo "Duplicate output path!" quit 1 @@ -49,15 +49,15 @@ if infile == "": echo "Missing input file!" quit 1 -if isNil(path): +if path.isNone: for i in countdown(infile.len - 1, 0): if infile[i] == '.': - if infile[i..^1] == ".rst": path = infile & ".rst" - else: path = infile[0..i] & "rst" + if infile[i..^1] == ".rst": path = some(infile & ".rst") + else: path = some(infile[0..i] & "rst") break - if isNil(path): path = infile & ".rst" + if path.isNone: path = some(infile & ".rst") -var tmpOut = newFileStream(path, fmWrite) +var tmpOut = newFileStream(path.get(), fmWrite) proc append(s: string) = tmpOut.writeLine(s) @@ -118,17 +118,17 @@ var lineNum = 0 for line in infile.lines(): if line.len > 0 and line[0] == '%': var - srcPath: string = nil + srcPath = none(string) level = 0 for i in 1..yaml.parser
  • yaml.presenter
  • yaml.serialization
  • +
  • yaml.annotations
  • yaml.stream
  • yaml.taglib
  • yaml.tojson
  • diff --git a/yaml/annotations.nim b/yaml/annotations.nim index b43fdaa..646d27b 100644 --- a/yaml/annotations.nim +++ b/yaml/annotations.nim @@ -13,7 +13,7 @@ template defaultVal*(value : typed) {.pragma.} ## This annotation can be assigned to an object field. During deserialization, - ## if no value for this field is given, the `value` parameter of this + ## if no value for this field is given, the ``value`` parameter of this ## annotation is used as value. ## ## Example usage: @@ -24,7 +24,7 @@ template defaultVal*(value : typed) {.pragma.} ## c {.defaultVal: (1,2).}: tuple[x, y: int] template transient*() {.pragma.} - ## This annotation can be assigned to an object field. Any object field + ## This annotation can be put on an object field. Any object field ## carrying this annotation will not be serialized to YAML and cannot be given ## a value when deserializing. Giving a value for this field during ## deserialization is an error. @@ -39,14 +39,17 @@ template transient*() {.pragma.} ## markAsTransient(MyObject, c) template ignore*(keys : openarray[string]) {.pragma.} - ## This annotation can be assigned to an object type. All keys with the given + ## This annotation can be put on an object type. All keys with the given ## names in the input YAML mapping will be ignored when deserializing a value ## of this type. This can be used to ignore parts of the YAML structure. ## + ## You may use it with an empty list (``{.ignore: [].}``) to ignore *all* + ## unknown keys. + ## ## Example usage: ## ## .. code-block:: - ## type MyObject {.ignore("c").} = object + ## type MyObject {.ignore: ["c"].} = object ## a, b: string template implicit*() {.pragma.}