From 566e28dcc541f1d89ce751d2e4b30a595b0cdfc2 Mon Sep 17 00:00:00 2001 From: Alexander Ivanov Date: Wed, 29 Aug 2018 19:50:20 +0300 Subject: [PATCH] Make it work with new not nil --- yaml/parser.nim | 2 +- yaml/private/lex.nim | 2 +- yaml/serialization.nim | 10 +++++----- yaml/stream.nim | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/yaml/parser.nim b/yaml/parser.nim index 0b91811..579ae01 100644 --- a/yaml/parser.nim +++ b/yaml/parser.nim @@ -158,7 +158,7 @@ proc currentScalar(c: ParserContext, e: var YamlStreamEvent) e = YamlStreamEvent(kind: yamlScalar, scalarTag: c.tag, scalarAnchor: c.anchor) shallowCopy(e.scalarContent, c.lex.buf) - c.lex.buf = cast[string not nil](newStringOfCap(256)) + c.lex.buf = cast[string](newStringOfCap(256)) c.tag = yTagQuestionMark c.anchor = yAnchorNone diff --git a/yaml/private/lex.nim b/yaml/private/lex.nim index 46cd581..68f0407 100644 --- a/yaml/private/lex.nim +++ b/yaml/private/lex.nim @@ -29,7 +29,7 @@ type curStartPos*: tuple[line, column: int] # ltScalarPart, ltQuotedScalar, ltYamlVersion, ltTagShorthand, ltTagUri, # ltLiteralTag, ltTagHandle, ltAnchor, ltAlias - buf*: string not nil + buf*: string # ltIndentation indentation*: int # ltTagHandle diff --git a/yaml/serialization.nim b/yaml/serialization.nim index 1e5d232..90e3163 100644 --- a/yaml/serialization.nim +++ b/yaml/serialization.nim @@ -672,7 +672,7 @@ proc markAsFound(i: int, matched: NimNode): NimNode {.compileTime.} = newLit(true)) proc ifNotTransient(tSym: NimNode, fieldIndex: int, content: openarray[NimNode], - elseError: bool = false, s: NimNode = nil, tName, fName: string = nil): + elseError: bool = false, s: NimNode = nil, tName, fName: string = ""): NimNode {.compileTime.} = var stmts = newStmtList(content) result = quote do: @@ -1150,7 +1150,7 @@ proc constructChild*(s: var YamlStream, c: ConstructionContext, if item.kind == yamlScalar: if item.scalarTag == yTagNimNilString: discard s.next() - result = nil + result = "" return elif item.scalarTag notin [yTagQuestionMark, yTagExclamationMark, yamlTag(string)]: @@ -1165,7 +1165,7 @@ proc constructChild*[T](s: var YamlStream, c: ConstructionContext, if item.kind == yamlScalar: if item.scalarTag == yTagNimNilSeq: discard s.next() - result = nil + result = @[] return elif item.kind == yamlStartSeq: if item.seqTag notin [yTagQuestionMark, yamlTag(seq[T])]: @@ -1231,7 +1231,7 @@ proc constructChild*[O](s: var YamlStream, c: ConstructionContext, raise e proc representChild*(value: string, ts: TagStyle, c: SerializationContext) = - if isNil(value): c.put(scalarEvent("", yTagNimNilString)) + if value.len == 0: c.put(scalarEvent("", yTagNimNilString)) else: let tag = presentTag(string, ts) representObject(value, ts, c, @@ -1239,7 +1239,7 @@ proc representChild*(value: string, ts: TagStyle, c: SerializationContext) = yTagExclamationMark else: tag) proc representChild*[T](value: seq[T], ts: TagStyle, c: SerializationContext) = - if isNil(value): c.put(scalarEvent("", yTagNimNilSeq)) + if value.len == 0: c.put(scalarEvent("", yTagNimNilSeq)) else: representObject(value, ts, c, presentTag(seq[T], ts)) proc representChild*[O](value: ref O, ts: TagStyle, c: SerializationContext) = diff --git a/yaml/stream.nim b/yaml/stream.nim index b107a65..1bfaf62 100644 --- a/yaml/stream.nim +++ b/yaml/stream.nim @@ -140,7 +140,7 @@ when not defined(JS): type BufferYamlStream* = ref object of YamlStream pos: int - buf: seq[YamlStreamEvent] not nil + buf: seq[YamlStreamEvent] proc newBufferYamlStream*(): BufferYamlStream not nil = result = cast[BufferYamlStream not nil](new(BufferYamlStream))