diff options
Diffstat (limited to 'compiler/lexer.nim')
-rwxr-xr-x | compiler/lexer.nim | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/compiler/lexer.nim b/compiler/lexer.nim index abb25541b..02f63aee8 100755 --- a/compiler/lexer.nim +++ b/compiler/lexer.nim @@ -126,7 +126,7 @@ proc pushInd*(L: var TLexer, indent: int) proc popInd*(L: var TLexer) proc isKeyword*(kind: TTokType): bool -proc openLexer*(lex: var TLexer, filename: string, inputstream: PLLStream) +proc openLexer*(lex: var TLexer, fileidx: int32, inputstream: PLLStream) proc rawGetTok*(L: var TLexer, tok: var TToken) # reads in the next token into tok and skips it proc getColumn*(L: TLexer): int @@ -135,6 +135,9 @@ proc closeLexer*(lex: var TLexer) proc PrintTok*(tok: TToken) proc tokToStr*(tok: TToken): string +proc openLexer*(lex: var TLexer, filename: string, inputstream: PLLStream) = + OpenLexer(lex, filename.fileInfoIdx, inputStream) + proc lexMessage*(L: TLexer, msg: TMsgKind, arg = "") proc isKeyword(kind: TTokType): bool = @@ -211,10 +214,10 @@ proc fillToken(L: var TToken) = L.base = base10 L.ident = dummyIdent -proc openLexer(lex: var TLexer, filename: string, inputstream: PLLStream) = +proc openLexer(lex: var TLexer, fileIdx: int32, inputstream: PLLStream) = openBaseLexer(lex, inputstream) lex.indentStack = @[0] - lex.fileIdx = filename.fileInfoIdx + lex.fileIdx = fileIdx lex.indentAhead = - 1 inc(lex.Linenumber, inputstream.lineOffset) @@ -505,16 +508,31 @@ proc getEscapedChar(L: var TLexer, tok: var TToken) = if (xi <= 255): add(tok.literal, Chr(xi)) else: lexMessage(L, errInvalidCharacterConstant) else: lexMessage(L, errInvalidCharacterConstant) + +proc newString(s: cstring, len: int): string = + ## XXX, how come there is no support for this? + result = newString(len) + for i in 0 .. <len: + result[i] = s[i] + +proc HandleCRLF(L: var TLexer, pos: int): int = + template registerLine = + let col = L.getColNumber(pos) + + if col > MaxLineLength: + lexMessagePos(L, hintLineTooLong, pos) + + if optEmbedOrigSrc in gGlobalOptions: + let lineStart = cast[TAddress](L.buf) + L.lineStart + let line = newString(cast[cstring](lineStart), col) + addSourceLine(L.fileIdx, line) -proc HandleCRLF(L: var TLexer, pos: int): int = case L.buf[pos] - of CR: - if getColNumber(L, pos) > MaxLineLength: - lexMessagePos(L, hintLineTooLong, pos) + of CR: + registerLine() result = lexbase.HandleCR(L, pos) - of LF: - if getColNumber(L, pos) > MaxLineLength: - lexMessagePos(L, hintLineTooLong, pos) + of LF: + registerLine() result = lexbase.HandleLF(L, pos) else: result = pos |