table constructors now mimic more closely the syntax of case... of...
see the safePrintF example in the manual as a motivation
This commit is contained in:
parent
f8184e3490
commit
92f70b08f9
3 changed files with 47 additions and 7 deletions
|
|
@ -1365,18 +1365,27 @@ proc semSetConstr(c: PContext, n: PNode): PNode =
|
||||||
addSon(result, m)
|
addSon(result, m)
|
||||||
|
|
||||||
proc semTableConstr(c: PContext, n: PNode): PNode =
|
proc semTableConstr(c: PContext, n: PNode): PNode =
|
||||||
# we simply transform ``{key: value, key2: value}`` to
|
# we simply transform ``{key: value, key2, key3: value}`` to
|
||||||
# ``[(key, value), (key2, value2)]``
|
# ``[(key, value), (key2, value2), (key3, value2)]``
|
||||||
result = newNodeI(nkBracket, n.info)
|
result = newNodeI(nkBracket, n.info)
|
||||||
|
var lastKey = 0
|
||||||
for i in 0..n.len-1:
|
for i in 0..n.len-1:
|
||||||
var x = n.sons[i]
|
var x = n.sons[i]
|
||||||
if x.kind == nkExprColonExpr and sonsLen(x) == 2:
|
if x.kind == nkExprColonExpr and sonsLen(x) == 2:
|
||||||
|
for j in countup(lastKey, i-1):
|
||||||
|
var pair = newNodeI(nkPar, x.info)
|
||||||
|
pair.add(n.sons[j])
|
||||||
|
pair.add(x[1])
|
||||||
|
result.add(pair)
|
||||||
|
|
||||||
var pair = newNodeI(nkPar, x.info)
|
var pair = newNodeI(nkPar, x.info)
|
||||||
pair.add(x[0])
|
pair.add(x[0])
|
||||||
pair.add(x[1])
|
pair.add(x[1])
|
||||||
result.add(pair)
|
result.add(pair)
|
||||||
else:
|
|
||||||
illFormedAst(x)
|
lastKey = i+1
|
||||||
|
|
||||||
|
if lastKey != n.len: illFormedAst(n)
|
||||||
result = semExpr(c, result)
|
result = semExpr(c, result)
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -2244,10 +2244,10 @@ Table constructor
|
||||||
A `table constructor`:idx: is syntactic sugar for an array constructor:
|
A `table constructor`:idx: is syntactic sugar for an array constructor:
|
||||||
|
|
||||||
.. code-block:: nimrod
|
.. code-block:: nimrod
|
||||||
{"key1": "value1", "key2": "value2"}
|
{"key1": "value1", "key2", "key3": "value2"}
|
||||||
|
|
||||||
# is the same as:
|
# is the same as:
|
||||||
[("key1", "value1"), ("key2", "value2")]
|
[("key1", "value1"), ("key2", "value2"), ("key3", "value")]
|
||||||
|
|
||||||
|
|
||||||
The empty table can be written ``{:}`` (in contrast to the empty set
|
The empty table can be written ``{:}`` (in contrast to the empty set
|
||||||
|
|
|
||||||
31
web/news.txt
31
web/news.txt
|
|
@ -2,6 +2,37 @@
|
||||||
News
|
News
|
||||||
====
|
====
|
||||||
|
|
||||||
|
2012-XX-XX Version 0.9.XX released
|
||||||
|
==================================
|
||||||
|
|
||||||
|
Version 0.8.XX has been released! Get it `here <download.html>`_.
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
--------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Library Additions
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Changes affecting backwards compatibility
|
||||||
|
-----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Compiler Additions
|
||||||
|
------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Language Additions
|
||||||
|
------------------
|
||||||
|
|
||||||
|
- table constructors now mimic more closely the syntax of case... of...
|
||||||
|
|
||||||
|
|
||||||
2012-09-23 Version 0.9.0 released
|
2012-09-23 Version 0.9.0 released
|
||||||
=================================
|
=================================
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue