diff options
author | Araq <rumpf_a@web.de> | 2012-08-23 08:45:40 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-08-23 08:45:40 +0200 |
commit | bdf3bee05510718581510cb78fa70ca183039d55 (patch) | |
tree | 62565e928efae42082004f904c1d4467f51ce013 /compiler | |
parent | c4c0c41d616f1859aa588f50a422aed608df6b77 (diff) | |
download | Nim-bdf3bee05510718581510cb78fa70ca183039d55.tar.gz |
implemented backslash for continuation comments
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/lexer.nim | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/compiler/lexer.nim b/compiler/lexer.nim index 01d284692..488c30f92 100755 --- a/compiler/lexer.nim +++ b/compiler/lexer.nim @@ -172,7 +172,7 @@ proc tokToStr*(tok: TToken): string = of tkParLe..tkColon, tkEof, tkInd, tkSad, tkDed, tkAccent: result = tokTypeToStr[tok.tokType] else: - if (tok.ident != nil): + if tok.ident != nil: result = tok.ident.s else: InternalError("tokToStr") @@ -654,19 +654,29 @@ proc scanComment(L: var TLexer, tok: var TToken) = # column after only whitespace tok.tokType = tkComment var col = getColNumber(L, pos) - while true: - while not (buf[pos] in {CR, LF, lexbase.EndOfFile}): + while true: + var lastBackslash = -1 + while buf[pos] notin {CR, LF, lexbase.EndOfFile}: + if buf[pos] == '\\': lastBackslash = pos+1 add(tok.literal, buf[pos]) inc(pos) + if lastBackslash > 0: + # a backslash is a continuation character if only followed by spaces + # plus a newline: + while buf[lastBackslash] == ' ': inc(lastBackslash) + if buf[lastBackslash] notin {CR, LF, lexbase.EndOfFile}: + # false positive: + lastBackslash = -1 + pos = handleCRLF(L, pos) buf = L.buf var indent = 0 while buf[pos] == ' ': inc(pos) inc(indent) - if (buf[pos] == '#') and (col == indent): - tok.literal = tok.literal & "\n" - else: + if buf[pos] == '#' and (col == indent or lastBackslash > 0): + tok.literal.add "\n" + else: if buf[pos] > ' ': L.indentAhead = indent inc(L.dedent) |