NimYAML/yaml/private/internal.nim

64 lines
1.8 KiB
Nim
Raw Normal View History

2016-09-20 19:53:38 +00:00
# NimYAML - YAML implementation in Nim
# (c) Copyright 2016 Felix Krause
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
template internalError*(s: string) =
# Note: to get the internal stacktrace that caused the error
# compile with the `d:debug` flag.
2016-09-20 19:53:38 +00:00
when not defined(release):
let ii = instantiationInfo()
echo "[NimYAML] Error in file ", ii.filename, " at line ", ii.line, ":"
echo s
when not defined(JS):
echo "[NimYAML] Stacktrace:"
try:
writeStackTrace()
let exc = getCurrentException()
if not isNil(exc.parent):
echo "Internal stacktrace:"
echo getStackTrace(exc.parent)
2016-09-20 19:53:38 +00:00
except: discard
echo "[NimYAML] Please report this bug."
quit 1
2016-09-20 19:53:38 +00:00
template yAssert*(e: typed) =
when not defined(release):
if not e:
let ii = instantiationInfo()
echo "[NimYAML] Error in file ", ii.filename, " at line ", ii.line, ":"
echo "assertion failed!"
when not defined(JS):
echo "[NimYAML] Stacktrace:"
try:
writeStackTrace()
let exc = getCurrentException()
if not isNil(exc.parent):
echo "Internal stacktrace:"
echo getStackTrace(exc.parent)
2016-09-20 19:53:38 +00:00
except: discard
echo "[NimYAML] Please report this bug."
quit 1
proc yamlTestSuiteEscape*(s: string): string =
result = ""
for c in s:
case c
of '\l': result.add("\\n")
2017-02-14 21:22:56 +00:00
of '\c': result.add("\\r")
of '\\': result.add("\\\\")
2017-02-14 21:22:56 +00:00
of '\b': result.add("\\b")
of '\t': result.add("\\t")
else: result.add(c)
proc nextAnchor*(s: var string, i: int) =
if s[i] == 'z':
s[i] = 'a'
if i == 0:
s.add('a')
else:
s[i] = 'a'
nextAnchor(s, i - 1)
else:
inc(s[i])