implemented backslash for continuation comments
This commit is contained in:
parent
c4c0c41d61
commit
bdf3bee055
6 changed files with 46 additions and 10 deletions
|
|
@ -172,7 +172,7 @@ proc tokToStr*(tok: TToken): string =
|
||||||
of tkParLe..tkColon, tkEof, tkInd, tkSad, tkDed, tkAccent:
|
of tkParLe..tkColon, tkEof, tkInd, tkSad, tkDed, tkAccent:
|
||||||
result = tokTypeToStr[tok.tokType]
|
result = tokTypeToStr[tok.tokType]
|
||||||
else:
|
else:
|
||||||
if (tok.ident != nil):
|
if tok.ident != nil:
|
||||||
result = tok.ident.s
|
result = tok.ident.s
|
||||||
else:
|
else:
|
||||||
InternalError("tokToStr")
|
InternalError("tokToStr")
|
||||||
|
|
@ -654,19 +654,29 @@ proc scanComment(L: var TLexer, tok: var TToken) =
|
||||||
# column after only whitespace
|
# column after only whitespace
|
||||||
tok.tokType = tkComment
|
tok.tokType = tkComment
|
||||||
var col = getColNumber(L, pos)
|
var col = getColNumber(L, pos)
|
||||||
while true:
|
while true:
|
||||||
while not (buf[pos] in {CR, LF, lexbase.EndOfFile}):
|
var lastBackslash = -1
|
||||||
|
while buf[pos] notin {CR, LF, lexbase.EndOfFile}:
|
||||||
|
if buf[pos] == '\\': lastBackslash = pos+1
|
||||||
add(tok.literal, buf[pos])
|
add(tok.literal, buf[pos])
|
||||||
inc(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)
|
pos = handleCRLF(L, pos)
|
||||||
buf = L.buf
|
buf = L.buf
|
||||||
var indent = 0
|
var indent = 0
|
||||||
while buf[pos] == ' ':
|
while buf[pos] == ' ':
|
||||||
inc(pos)
|
inc(pos)
|
||||||
inc(indent)
|
inc(indent)
|
||||||
if (buf[pos] == '#') and (col == indent):
|
if buf[pos] == '#' and (col == indent or lastBackslash > 0):
|
||||||
tok.literal = tok.literal & "\n"
|
tok.literal.add "\n"
|
||||||
else:
|
else:
|
||||||
if buf[pos] > ' ':
|
if buf[pos] > ' ':
|
||||||
L.indentAhead = indent
|
L.indentAhead = indent
|
||||||
inc(L.dedent)
|
inc(L.dedent)
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,16 @@ aligned to the preceding one, it does not start a new comment:
|
||||||
# statement.
|
# statement.
|
||||||
i = i + 1 # This a new comment that is NOT
|
i = i + 1 # This a new comment that is NOT
|
||||||
echo(i) # continued here, because this comment refers to the echo statement
|
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
|
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
|
as they belong to the syntax tree! This feature enables perfect source-to-source
|
||||||
|
|
|
||||||
11
doc/tut1.txt
11
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
|
i = i + 1 # This a new comment that is NOT
|
||||||
echo(i) # continued here, because this comment refers to the echo statement
|
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
|
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
|
as they belong to the syntax tree! This feature enables perfect source-to-source
|
||||||
transformations (such as pretty-printing) and simpler documentation generators.
|
transformations (such as pretty-printing) and simpler documentation generators.
|
||||||
|
|
|
||||||
|
|
@ -648,8 +648,8 @@ proc parseBackslash(p: var TRstParser, father: PRstNode) =
|
||||||
# XXX: Unicode?
|
# XXX: Unicode?
|
||||||
inc(p.idx)
|
inc(p.idx)
|
||||||
if p.tok[p.idx].kind != tkWhite: add(father, newLeaf(p))
|
if p.tok[p.idx].kind != tkWhite: add(father, newLeaf(p))
|
||||||
inc(p.idx)
|
if p.tok[p.idx].kind != tkEof: inc(p.idx)
|
||||||
else:
|
else:
|
||||||
add(father, newLeaf(p))
|
add(father, newLeaf(p))
|
||||||
inc(p.idx)
|
inc(p.idx)
|
||||||
|
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -3,7 +3,6 @@ version 0.9.0
|
||||||
|
|
||||||
- make 'bind' default for templates and introduce 'mixin'
|
- make 'bind' default for templates and introduce 'mixin'
|
||||||
- implement 'bind' for macros
|
- implement 'bind' for macros
|
||||||
- use ``\`` for comment continuations
|
|
||||||
- ``final`` should be the default for objects
|
- ``final`` should be the default for objects
|
||||||
- implement "closure tuple consists of a single 'ref'" optimization
|
- implement "closure tuple consists of a single 'ref'" optimization
|
||||||
- implement for loop transformation for first class iterators
|
- implement for loop transformation for first class iterators
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ Library Additions
|
||||||
- Added ``system.clamp`` to limit a value within an interval ``[a, b]``.
|
- Added ``system.clamp`` to limit a value within an interval ``[a, b]``.
|
||||||
- Added ``strutils.continuesWith``.
|
- Added ``strutils.continuesWith``.
|
||||||
- Added ``system.getStackTrace``.
|
- 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``
|
- The GC supports (soft) realtime systems via ``GC_setMaxPause``
|
||||||
and ``GC_step`` procs.
|
and ``GC_step`` procs.
|
||||||
- The sockets module now supports ssl through the OpenSSL library, ``recvLine``
|
- 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
|
Activate the warning ``ImplicitClosure`` to make the compiler list the
|
||||||
occurances of proc types which are affected.
|
occurances of proc types which are affected.
|
||||||
- The Nimrod type system now distinguishes ``openarray`` from ``varargs``.
|
- The Nimrod type system now distinguishes ``openarray`` from ``varargs``.
|
||||||
|
- Templates are now ``hygienic``. Use the ``dirty`` pragma to get the old
|
||||||
|
behaviour.
|
||||||
|
|
||||||
|
|
||||||
Compiler Additions
|
Compiler Additions
|
||||||
|
|
@ -151,6 +153,10 @@ Language Additions
|
||||||
line: ``inc i; inc j``.
|
line: ``inc i; inc j``.
|
||||||
- ``bind`` supports overloaded symbols and operators.
|
- ``bind`` supports overloaded symbols and operators.
|
||||||
- A ``distinct`` type can now borrow from generic procs.
|
- 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
|
2012-02-09 Version 0.8.14 released
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue