preparations for dealing with the 'echo $foo' gotcha

This commit is contained in:
Araq 2015-03-27 02:14:27 +01:00
commit e80840c40a
4 changed files with 19 additions and 9 deletions

View file

@ -241,9 +241,15 @@ proc isOperator(tok: TToken): bool =
proc isUnary(p: TParser): bool = proc isUnary(p: TParser): bool =
## Check if the current parser token is a unary operator ## Check if the current parser token is a unary operator
p.strongSpaces and p.tok.tokType in {tkOpr, tkDotDot} and if p.tok.tokType in {tkOpr, tkDotDot} and
p.tok.strongSpaceB == 0 and p.tok.strongSpaceB == 0 and
p.tok.strongSpaceA > 0 p.tok.strongSpaceA > 0:
# XXX change this after 0.10.4 is out
if p.strongSpaces:
result = true
else:
parMessage(p, warnDeprecated,
"will be parsed as unary operator; inconsistent spacing")
proc checkBinary(p: TParser) {.inline.} = proc checkBinary(p: TParser) {.inline.} =
## Check if the current parser token is a binary operator. ## Check if the current parser token is a binary operator.

View file

@ -253,16 +253,16 @@ proc product*[T](x: openArray[seq[T]]): seq[seq[T]] =
while true: while true:
while indexes[index] == -1: while indexes[index] == -1:
indexes[index] = initial[index] indexes[index] = initial[index]
index +=1 index += 1
if index == x.len: return if index == x.len: return
indexes[index] -=1 indexes[index] -= 1
for ni, i in indexes: for ni, i in indexes:
next[ni] = x[ni][i] next[ni] = x[ni][i]
var res: seq[T] var res: seq[T]
shallowCopy(res, next) shallowCopy(res, next)
result.add(res) result.add(res)
index = 0 index = 0
indexes[index] -=1 indexes[index] -= 1
proc nextPermutation*[T](x: var openarray[T]): bool {.discardable.} = proc nextPermutation*[T](x: var openarray[T]): bool {.discardable.} =
## Calculates the next lexicographic permutation, directly modifying ``x``. ## Calculates the next lexicographic permutation, directly modifying ``x``.

View file

@ -1,16 +1,16 @@
version 0.10.4 version 0.10.4
============== ==============
- improve the parser; deal with echo $foo gotcha
- improve GC-unsafety warnings - improve GC-unsafety warnings
- make 'nil' work for 'add' and 'len' - make 'nil' work for 'add' and 'len'
- add "all threads are blocked" detection to 'spawn'
- overloading of '=' - overloading of '='
version 1.0 version 1.0
=========== ===========
- remove echo $foo gotcha
- add "all threads are blocked" detection to 'spawn'
- figure out why C++ bootstrapping is so much slower - figure out why C++ bootstrapping is so much slower
- nimsuggest: auto-completion needs to work in 'class' macros - nimsuggest: auto-completion needs to work in 'class' macros
- The bitwise 'not' operator will be renamed to 'bnot' to - The bitwise 'not' operator will be renamed to 'bnot' to

View file

@ -42,7 +42,7 @@ News
structure; for immediate macro parameters ``nkCall('addr', 'x')`` is structure; for immediate macro parameters ``nkCall('addr', 'x')`` is
produced instead of ``nkAddr('x')``. produced instead of ``nkAddr('x')``.
- ``concept`` is now a keyword and is used instead of ``generic``. - ``concept`` is now a keyword and is used instead of ``generic``.
- The ``inc``, ``dec``, ``+=``, ``-=`` builtins now produces OverflowError - The ``inc``, ``dec``, ``+=``, ``-=`` builtins now produce OverflowError
exceptions. This means code like the following: exceptions. This means code like the following:
.. code-block:: nim .. code-block:: nim
@ -64,6 +64,10 @@ News
use ``a[0.. ^1]``. This also works with accessing a single use ``a[0.. ^1]``. This also works with accessing a single
element ``a[^1]``. Note that we cannot detect this reliably as it is element ``a[^1]``. Note that we cannot detect this reliably as it is
determined at **runtime** whether negative indexing is used! determined at **runtime** whether negative indexing is used!
- The compiler now warns about code like ``foo +=1`` which uses inconsistent
spacing around binary operators. Later versions of the language will parse
these as unary operators instead so that ``echo $foo`` finally can do what
people expect it to do.
Language Additions Language Additions