Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/jsony.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import jsony/objvar, std/json, std/options, std/parseutils, std/sets,
std/strutils, std/tables, std/typetraits, std/unicode

type JsonError* = object of ValueError
offset*: int

const whiteSpace = {' ', '\n', '\t', '\r'}

Expand All @@ -27,7 +28,9 @@ proc parseHook*[T: distinct](s: string, i: var int, v: var T)

template error(msg: string, i: int) =
## Shortcut to raise an exception.
raise newException(JsonError, msg & " At offset: " & $i)
var e = newException(JsonError, msg)
e.offset = i
raise e

template eatSpace*(s: string, i: var int) =
## Will consume whitespace.
Expand Down