diff options
-rwxr-xr-x | compiler/lexer.nim | 22 | ||||
-rwxr-xr-x | doc/manual.txt | 10 | ||||
-rwxr-xr-x | doc/tut1.txt | 11 | ||||
-rwxr-xr-x | packages/docutils/rst.nim | 4 | ||||
-rwxr-xr-x | todo.txt | 1 | ||||
-rwxr-xr-x | web/news.txt | 8 |
6 files changed, 46 insertions, 10 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) diff --git a/doc/manual.txt b/doc/manual.txt index 07be0c492..ee275fbce 100755 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -135,6 +135,16 @@ aligned to the preceding one, it does not start a new comment: # statement. i = i + 1 # This a new comment that is NOT echo(i) # continued here, because this comment refers to the echo statement + + +The alignment requirement does not hold if the preceding comment piece ends in +a backslash (followed by optional whitespace): + +.. code-block:: nimrod + type + TMyObject {.final, pure, acyclic.} = object # comment continues: \ + # we have lots of space here to comment 'TMyObject'. + # This line belongs to the comment as it's properly aligned. Comments are tokens; they are only allowed at certain places in the input file as they belong to the syntax tree! This feature enables perfect source-to-source diff --git a/doc/tut1.txt b/doc/tut1.txt index a5554cffc..833d364df 100755 --- a/doc/tut1.txt +++ b/doc/tut1.txt @@ -130,6 +130,17 @@ comments need to be aligned at the same column: i = i + 1 # This a new comment that is NOT echo(i) # continued here, because this comment refers to the echo statement + +The alignment requirement does not hold if the preceding comment piece ends in +a backslash: + +.. code-block:: nimrod + type + TMyObject {.final, pure, acyclic.} = object # comment continues: \ + # we have lots of space here to comment 'TMyObject'. + # This line belongs to the comment as it's properly aligned. + + Comments are tokens; they are only allowed at certain places in the input file as they belong to the syntax tree! This feature enables perfect source-to-source transformations (such as pretty-printing) and simpler documentation generators. diff --git a/packages/docutils/rst.nim b/packages/docutils/rst.nim index ed8e2b7a9..333ef11d9 100755 --- a/packages/docutils/rst.nim +++ b/packages/docutils/rst.nim @@ -648,8 +648,8 @@ proc parseBackslash(p: var TRstParser, father: PRstNode) = # XXX: Unicode? inc(p.idx) if p.tok[p.idx].kind != tkWhite: add(father, newLeaf(p)) - inc(p.idx) - else: + if p.tok[p.idx].kind != tkEof: inc(p.idx) + else: add(father, newLeaf(p)) inc(p.idx) diff --git a/todo.txt b/todo.txt index 686be1b4a..c251cc5de 100755 --- a/todo.txt +++ b/todo.txt @@ -3,7 +3,6 @@ version 0.9.0 - make 'bind' default for templates and introduce 'mixin' - implement 'bind' for macros -- use ``\`` for comment continuations - ``final`` should be the default for objects - implement "closure tuple consists of a single 'ref'" optimization - implement for loop transformation for first class iterators diff --git a/web/news.txt b/web/news.txt index e9e00a321..ac8b0585b 100755 --- a/web/news.txt +++ b/web/news.txt @@ -51,7 +51,7 @@ Library Additions - Added ``system.clamp`` to limit a value within an interval ``[a, b]``. - Added ``strutils.continuesWith``. - Added ``system.getStackTrace``. -- Added ``system.||`` for parallel for loop support. +- Added ``system.||`` for parallel ``for`` loop support. - The GC supports (soft) realtime systems via ``GC_setMaxPause`` and ``GC_step`` procs. - The sockets module now supports ssl through the OpenSSL library, ``recvLine`` @@ -106,6 +106,8 @@ Changes affecting backwards compatibility Activate the warning ``ImplicitClosure`` to make the compiler list the occurances of proc types which are affected. - The Nimrod type system now distinguishes ``openarray`` from ``varargs``. +- Templates are now ``hygienic``. Use the ``dirty`` pragma to get the old + behaviour. Compiler Additions @@ -151,6 +153,10 @@ Language Additions line: ``inc i; inc j``. - ``bind`` supports overloaded symbols and operators. - A ``distinct`` type can now borrow from generic procs. +- Added the pragmas ``gensym``, ``inject`` and ``dirty`` for hygiene + in templates. +- Comments can be continued with a backslash continuation character so that + comment pieces don't have to align on the same column. 2012-02-09 Version 0.8.14 released |