In error messages, display the start position of strings instead of the end pos
This commit is contained in:
parent
943501f941
commit
0c12b0f42d
|
@ -75,10 +75,13 @@ proc isDigit(c: char): bool {.inline.} =
|
|||
proc col*(lexer: JsonLexer): int =
|
||||
lexer.stream[].pos - lexer.lineStartPos
|
||||
|
||||
proc tokenStartCol*(lexer: JsonLexer): int =
|
||||
1 + lexer.tokenStart - lexer.lineStartPos
|
||||
|
||||
proc init*(T: type JsonLexer, stream: ref AsciiStream, mode = defaultJsonMode): T =
|
||||
T(stream: stream,
|
||||
mode: mode,
|
||||
line: 0,
|
||||
line: 1,
|
||||
lineStartPos: 0,
|
||||
tokenStart: -1,
|
||||
tok: tkError,
|
||||
|
|
|
@ -52,18 +52,18 @@ method formatMsg*(err: ref GenericJsonReaderError, filename: string): string =
|
|||
template init*(T: type JsonReader, stream: ByteStreamVar, mode = defaultJsonMode): auto =
|
||||
init JsonReader, AsciiStreamVar(stream), mode
|
||||
|
||||
proc assignLineNumber(ex: ref JsonReaderError, r: JsonReader) =
|
||||
proc assignLineNumber*(ex: ref JsonReaderError, r: JsonReader) =
|
||||
ex.line = r.lexer.line
|
||||
ex.col = r.lexer.col
|
||||
ex.col = r.lexer.tokenStartCol
|
||||
|
||||
proc raiseUnexpectedToken(r: JsonReader, expected: ExpectedTokenCategory) =
|
||||
proc raiseUnexpectedToken*(r: JsonReader, expected: ExpectedTokenCategory) =
|
||||
var ex = new UnexpectedToken
|
||||
ex.assignLineNumber(r)
|
||||
ex.encountedToken = r.lexer.tok
|
||||
ex.expectedToken = expected
|
||||
raise ex
|
||||
|
||||
proc raiseUnexpectedField(r: JsonReader, fieldName, deserializedType: cstring) =
|
||||
proc raiseUnexpectedField*(r: JsonReader, fieldName, deserializedType: cstring) =
|
||||
var ex = new UnexpectedField
|
||||
ex.assignLineNumber(r)
|
||||
ex.encounteredField = fieldName
|
||||
|
|
Loading…
Reference in New Issue