From 2655d4205fb2873bd927e487ca3ff5feb9644465 Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Wed, 14 Sep 2016 14:53:13 +0200 Subject: [PATCH] Improved error reporting, fixes #23 --- private/lex.nim | 5 ++--- private/parse.nim | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/private/lex.nim b/private/lex.nim index cc13dc6..06b1a06 100644 --- a/private/lex.nim +++ b/private/lex.nim @@ -195,7 +195,7 @@ proc lineWithMarker(lex: YamlLexer, t: typedesc[BaseLexer], marker: bool): if lex.curStartPos.line == lex.blSource.lineNumber: result = lex.blSource.getCurrentLine(false) if marker: result.add(spaces(lex.curStartPos.column - 1) & "^\n") - else: result = nil + else: result = "" proc lineWithMarker(lex: YamlLexer, t: typedesc[StringSource], marker: bool): string = @@ -219,8 +219,7 @@ proc lineWithMarker(lex: YamlLexer, t: typedesc[StringSource], marker: bool): dec(lineStartIndex) dec(lineEndIndex) dec(curLine) - result = lex.sSource.src.substr(lineStartIndex, - lineEndIndex - lineStartIndex - 1) & "\n" + result = lex.sSource.src.substr(lineStartIndex, lineEndIndex - 1) & "\n" if marker: result.add(spaces(lex.curStartPos.column - 1) & "^\n") # lexer states diff --git a/private/parse.nim b/private/parse.nim index 217c1e0..2ed696a 100644 --- a/private/parse.nim +++ b/private/parse.nim @@ -523,6 +523,7 @@ parserState blockObjectStart: state = scalarEnd of ltScalarPart: result = c.handleBlockItemStart(e) + let cachedPos = c.lex.curStartPos while true: c.advance() case c.lex.cur @@ -532,6 +533,7 @@ parserState blockObjectStart: of ltScalarPart: discard of ltEmptyLine: c.lex.newlines.inc() else: break + c.lex.curStartPos = cachedPos c.lex.newlines = 0 state = plainScalarEnd stored = blockAfterObject