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
|
|
@ -1364,19 +1364,28 @@ proc semSetConstr(c: PContext, n: PNode): PNode =
|
|||
m = fitNode(c, typ, n.sons[i])
|
||||
addSon(result, m)
|
||||
|
||||
proc semTableConstr(c: PContext, n: PNode): PNode =
|
||||
# we simply transform ``{key: value, key2: value}`` to
|
||||
# ``[(key, value), (key2, value2)]``
|
||||
proc semTableConstr(c: PContext, n: PNode): PNode =
|
||||
# we simply transform ``{key: value, key2, key3: value}`` to
|
||||
# ``[(key, value), (key2, value2), (key3, value2)]``
|
||||
result = newNodeI(nkBracket, n.info)
|
||||
var lastKey = 0
|
||||
for i in 0..n.len-1:
|
||||
var x = n.sons[i]
|
||||
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)
|
||||
pair.add(x[0])
|
||||
pair.add(x[1])
|
||||
result.add(pair)
|
||||
else:
|
||||
illFormedAst(x)
|
||||
|
||||
lastKey = i+1
|
||||
|
||||
if lastKey != n.len: illFormedAst(n)
|
||||
result = semExpr(c, result)
|
||||
|
||||
type
|
||||
|
|
|
|||
|
|
@ -2244,10 +2244,10 @@ Table constructor
|
|||
A `table constructor`:idx: is syntactic sugar for an array constructor:
|
||||
|
||||
.. code-block:: nimrod
|
||||
{"key1": "value1", "key2": "value2"}
|
||||
{"key1": "value1", "key2", "key3": "value2"}
|
||||
|
||||
# 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
|
||||
|
|
|
|||
31
web/news.txt
31
web/news.txt
|
|
@ -2,6 +2,37 @@
|
|||
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
|
||||
=================================
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue