diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-09-29 18:43:41 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-10-03 01:59:49 +0300 |
commit | 92f70b08f9c4d6108f61f37c29c1b001c6173a19 (patch) | |
tree | d300dc678f8371b73d19d0286a78722616cd07cf /compiler | |
parent | f8184e349027dc0273a3552526af18dc03df0f79 (diff) | |
download | Nim-92f70b08f9c4d6108f61f37c29c1b001c6173a19.tar.gz |
table constructors now mimic more closely the syntax of case... of...
see the safePrintF example in the manual as a motivation
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/semexprs.nim | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 4608d38ef..17e6e8048 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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 |