mirror of https://github.com/status-im/NimYAML.git
Got rid of lots of compiler warnings
This commit is contained in:
parent
30365d2f17
commit
34cbe61479
|
@ -135,7 +135,7 @@ proc serializeNode(n: YamlNode, c: SerializationContext, a: AnchorStyle,
|
|||
yield event
|
||||
yield endMapEvent()
|
||||
|
||||
template processAnchoredEvent(target: expr, c: SerializationContext): stmt =
|
||||
template processAnchoredEvent(target: untyped, c: SerializationContext): typed =
|
||||
let anchorId = c.refs.getOrDefault(cast[pointer](target))
|
||||
if anchorId != yAnchorNone: target = anchorId
|
||||
else: target = yAnchorNone
|
||||
|
|
|
@ -28,7 +28,7 @@ type
|
|||
|
||||
ythMinus, yth0, ythInt, ythDecimal, ythNumE, ythNumEPlusMinus, ythExponent
|
||||
|
||||
macro typeHintStateMachine(c: untyped, content: untyped): stmt =
|
||||
macro typeHintStateMachine(c: untyped, content: untyped): typed =
|
||||
yAssert content.kind == nnkStmtList
|
||||
result = newNimNode(nnkCaseStmt, content).add(copyNimNode(c))
|
||||
for branch in content.children:
|
||||
|
@ -43,7 +43,7 @@ macro typeHintStateMachine(c: untyped, content: untyped): stmt =
|
|||
inc(i)
|
||||
for rule in branch[i].children:
|
||||
yAssert rule.kind == nnkInfix
|
||||
yAssert ($rule[0].ident == "=>")
|
||||
yAssert $rule[0].ident == "=>"
|
||||
var stateBranch = newNimNode(nnkOfBranch, rule)
|
||||
case rule[1].kind
|
||||
of nnkBracket:
|
||||
|
|
|
@ -886,14 +886,18 @@ proc handleFlowPlainScalar(c: ParserContext, e: var YamlStreamEvent) =
|
|||
|
||||
# --- macros for defining parser states ---
|
||||
|
||||
macro parserStates(names: varargs[untyped]): stmt =
|
||||
template capitalize(s: string): string =
|
||||
when declared(strutils.capitalizeAscii): strutils.capitalizeAscii(s)
|
||||
else: strutils.capitalize(s)
|
||||
|
||||
macro parserStates(names: varargs[untyped]): typed =
|
||||
## generates proc declaration for each state in list like this:
|
||||
##
|
||||
## proc name(s: YamlStream, e: var YamlStreamEvent):
|
||||
## bool {.raises: [YamlParserError].}
|
||||
result = newStmtList()
|
||||
for name in names:
|
||||
let nameId = newIdentNode("state" & strutils.capitalize($name.ident))
|
||||
let nameId = newIdentNode("state" & capitalize($name.ident))
|
||||
result.add(newProc(nameId, [ident("bool"), newIdentDefs(ident("s"),
|
||||
ident("YamlStream")), newIdentDefs(ident("e"), newNimNode(nnkVarTy).add(
|
||||
ident("YamlStreamEvent")))], newEmptyNode()))
|
||||
|
@ -912,14 +916,14 @@ proc processStateAsgns(source, target: NimNode) {.compileTime.} =
|
|||
newNameId = newDotExpr(ident("c"), ident("storedState"))
|
||||
else:
|
||||
newNameId =
|
||||
newIdentNode("state" & strutils.capitalize($child[1].ident))
|
||||
newIdentNode("state" & capitalize($child[1].ident))
|
||||
target.add(newAssignment(newDotExpr(
|
||||
newIdentNode("s"), newIdentNode("nextImpl")), newNameId))
|
||||
continue
|
||||
elif $child[0].ident == "stored":
|
||||
assert child[1].kind == nnkIdent
|
||||
let newNameId =
|
||||
newIdentNode("state" & strutils.capitalize($child[1].ident))
|
||||
newIdentNode("state" & capitalize($child[1].ident))
|
||||
target.add(newAssignment(newDotExpr(newIdentNode("c"),
|
||||
newIdentNode("storedState")), newNameId))
|
||||
continue
|
||||
|
@ -927,7 +931,7 @@ proc processStateAsgns(source, target: NimNode) {.compileTime.} =
|
|||
processStateAsgns(child, processed)
|
||||
target.add(processed)
|
||||
|
||||
macro parserState(name: untyped, impl: untyped): stmt =
|
||||
macro parserState(name: untyped, impl: untyped): typed =
|
||||
## Creates a parser state. Every parser state is a proc with the signature
|
||||
##
|
||||
## proc(s: YamlStream, e: var YamlStreamEvent):
|
||||
|
@ -941,7 +945,7 @@ macro parserState(name: untyped, impl: untyped): stmt =
|
|||
## The [newState] must have been declared with states(...) previously.
|
||||
let
|
||||
nameStr = $name.ident
|
||||
nameId = newIdentNode("state" & strutils.capitalize(nameStr))
|
||||
nameId = newIdentNode("state" & capitalize(nameStr))
|
||||
var procImpl = quote do:
|
||||
debug("state: " & `nameStr`)
|
||||
procImpl.add(newLetStmt(ident("c"), newCall("ParserContext", ident("s"))))
|
||||
|
|
|
@ -29,7 +29,7 @@ proc safeTagUri(id: TagId): string {.raises: [].} =
|
|||
else: return uri
|
||||
except KeyError: internalError("Unexpected KeyError for TagId " & $id)
|
||||
|
||||
template constructScalarItem*(s: var YamlStream, i: expr,
|
||||
template constructScalarItem*(s: var YamlStream, i: untyped,
|
||||
t: typedesc, content: untyped) =
|
||||
## Helper template for implementing ``constructObject`` for types that
|
||||
## are constructed from a scalar. ``i`` is the identifier that holds
|
||||
|
@ -422,8 +422,8 @@ proc yamlTag*(T: typedesc[tuple]):
|
|||
try: serializationTagLibrary.tags[uri]
|
||||
except KeyError: serializationTagLibrary.registerUri(uri)
|
||||
|
||||
macro constructFieldValue(t: typedesc, stream: expr, context: expr,
|
||||
name: expr, o: expr): stmt =
|
||||
macro constructFieldValue(t: typedesc, stream: untyped, context: untyped,
|
||||
name: untyped, o: untyped): typed =
|
||||
let tDesc = getType(getType(t)[1])
|
||||
result = newNimNode(nnkCaseStmt).add(name)
|
||||
for child in tDesc[2].children:
|
||||
|
@ -459,6 +459,9 @@ macro constructFieldValue(t: typedesc, stream: expr, context: expr,
|
|||
let field = newDotExpr(o, newIdentNode($child))
|
||||
ob.add(newStmtList(newCall("constructChild", stream, context, field)))
|
||||
result.add(ob)
|
||||
# TODO: is this correct?
|
||||
result.add(newNimNode(nnkElse).add(newNimNode(nnkDiscardStmt).add(
|
||||
newEmptyNode())))
|
||||
|
||||
proc isVariantObject(t: typedesc): bool {.compileTime.} =
|
||||
let tDesc = getType(t)
|
||||
|
@ -556,15 +559,13 @@ proc representObject*[O: enum](value: O, ts: TagStyle,
|
|||
|
||||
proc yamlTag*[O](T: typedesc[ref O]): TagId {.inline, raises: [].} = yamlTag(O)
|
||||
|
||||
macro constructImplicitVariantObject(s, c, r, possibleTagIds: expr,
|
||||
t: typedesc): stmt =
|
||||
macro constructImplicitVariantObject(s, c, r, possibleTagIds: untyped,
|
||||
t: typedesc): typed =
|
||||
let tDesc = getType(getType(t)[1])
|
||||
yAssert tDesc.kind == nnkObjectTy
|
||||
let recCase = tDesc[2][0]
|
||||
yAssert recCase.kind == nnkRecCase
|
||||
let
|
||||
discriminant = newDotExpr(r, newIdentNode($recCase[0]))
|
||||
discType = newCall("type", discriminant)
|
||||
let discriminant = newDotExpr(r, newIdentNode($recCase[0]))
|
||||
var ifStmt = newNimNode(nnkIfStmt)
|
||||
for i in 1 .. recCase.len - 1:
|
||||
yAssert recCase[i].kind == nnkOfBranch
|
||||
|
@ -856,7 +857,7 @@ proc represent*[T](value: T, ts: TagStyle = tsRootOnly,
|
|||
if a == asTidy:
|
||||
var objQueue = newSeq[YamlStreamEvent]()
|
||||
for event in objStream(): objQueue.add(event)
|
||||
var backend = iterator(): YamlStreamEvent {.raises: [YamlStreamError].} =
|
||||
var backend = iterator(): YamlStreamEvent {.raises: [].} =
|
||||
for i in countup(0, objQueue.len - 1):
|
||||
var event = objQueue[i]
|
||||
case event.kind
|
||||
|
|
|
@ -39,7 +39,7 @@ type
|
|||
barkometer: int
|
||||
|
||||
proc `$`(v: BetterInt): string {.borrow.}
|
||||
proc `==`(l, r: BetterInt): bool {.borrow.}
|
||||
proc `==`(left, right: BetterInt): bool {.borrow.}
|
||||
|
||||
setTagUri(TrafficLight, "!tl")
|
||||
setTagUri(Node, "!example.net:Node")
|
||||
|
@ -75,10 +75,9 @@ proc newNode(v: string): ref Node =
|
|||
result.value = v
|
||||
result.next = nil
|
||||
|
||||
suite "Serialization":
|
||||
setup:
|
||||
let blockOnly = defineOptions(style=psBlockOnly)
|
||||
|
||||
suite "Serialization":
|
||||
test "Serialization: Load integer without fixed length":
|
||||
var input = newStringStream("-4247")
|
||||
var result: int
|
||||
|
|
10
yaml.nim
10
yaml.nim
|
@ -603,7 +603,7 @@ proc constructChild*[T](s: var YamlStream, c: ConstructionContext,
|
|||
|
||||
proc constructChild*[O](s: var YamlStream, c: ConstructionContext,
|
||||
result: var ref O)
|
||||
{.raises: [YamlConstructionError, YamlStreamError].}
|
||||
{.raises: [YamlStreamError].}
|
||||
## Constructs an arbitrary Nim value from a part of a YAML stream.
|
||||
## The stream will advance until after the finishing token that was used
|
||||
## for constructing the value. The object may be constructed from an alias
|
||||
|
@ -624,7 +624,7 @@ proc representChild*[O](value: O, ts: TagStyle,
|
|||
## Represents an arbitrary Nim object as YAML object.
|
||||
|
||||
proc construct*[T](s: var YamlStream, target: var T)
|
||||
{.raises: [YamlConstructionError, YamlStreamError].}
|
||||
{.raises: [YamlStreamError].}
|
||||
## Constructs a Nim value from a YAML stream.
|
||||
|
||||
proc load*[K](input: Stream, target: var K)
|
||||
|
@ -660,7 +660,7 @@ var
|
|||
## registered URIs here to be able to generate a static compiler error
|
||||
## when the user tries to register an URI more than once.
|
||||
|
||||
template setTagUri*(t: typedesc, uri: string): stmt =
|
||||
template setTagUri*(t: typedesc, uri: string): typed =
|
||||
## Associate the given uri with a certain type. This uri is used as YAML tag
|
||||
## when loading and dumping values of this type.
|
||||
when uri in registeredUris:
|
||||
|
@ -675,7 +675,7 @@ template setTagUri*(t: typedesc, uri: string): stmt =
|
|||
proc yamlTag*(T: typedesc[t]): TagId {.inline, raises: [].} = id
|
||||
## autogenerated
|
||||
|
||||
template setTagUri*(t: typedesc, uri: string, idName: expr): stmt =
|
||||
template setTagUri*(t: typedesc, uri: string, idName: untyped): typed =
|
||||
## Like `setTagUri <#setTagUri.t,typedesc,string>`_, but lets
|
||||
## you choose a symbol for the `TagId <#TagId>`_ of the uri. This is only
|
||||
## necessary if you want to implement serialization / construction yourself.
|
||||
|
@ -704,7 +704,7 @@ proc canBeImplicit(t: typedesc): bool {.compileTime.} =
|
|||
else: return false
|
||||
return true
|
||||
|
||||
template markAsImplicit*(t: typedesc): stmt =
|
||||
template markAsImplicit*(t: typedesc): typed =
|
||||
## Mark a variant object type as implicit. This requires the type to consist
|
||||
## of nothing but a case expression and each branch of the case expression
|
||||
## containing exactly one field - with the exception that one branch may
|
||||
|
|
Loading…
Reference in New Issue