Parser: Fix location (line, col) for diagnostics
Previously parser was using lexMessage which was taking location from current buffer position which was pointing after recently consumed token. But since parser shows diagnostics about that token it should point to the location where token starts. This makes diagnostics like: `test.nim(2, 2) Error: ':' expected` point properly at the beginning of the wrong token.
This commit is contained in:
parent
69ed78b30f
commit
07b13251d1
2 changed files with 7 additions and 3 deletions
|
|
@ -221,6 +221,10 @@ proc dispMessage(L: TLexer; info: TLineInfo; msg: TMsgKind; arg: string) =
|
|||
proc lexMessage*(L: TLexer, msg: TMsgKind, arg = "") =
|
||||
L.dispMessage(getLineInfo(L), msg, arg)
|
||||
|
||||
proc lexMessageTok*(L: TLexer, msg: TMsgKind, tok: TToken, arg = "") =
|
||||
var info = newLineInfo(L.fileIdx, tok.line, tok.col)
|
||||
L.dispMessage(info, msg, arg)
|
||||
|
||||
proc lexMessagePos(L: var TLexer, msg: TMsgKind, pos: int, arg = "") =
|
||||
var info = newLineInfo(L.fileIdx, L.lineNumber, pos - L.lineStart)
|
||||
L.dispMessage(info, msg, arg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue