summary refs log tree commit diff stats
path: root/compiler/parser.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2013-05-26 01:36:34 +0300
committerZahary Karadjov <zahary@gmail.com>2013-05-26 11:14:23 +0300
commitbfff1ac8b2435595351194f6c4b1268d38301401 (patch)
treed523f18a63b849bd24b241c73abd803d5d5e1859 /compiler/parser.nim
parentaea27a7ce4a263122e0a053afa864ee76baaf8d5 (diff)
downloadNim-bfff1ac8b2435595351194f6c4b1268d38301401.tar.gz
allow keyword params for the `[]` and `{}` operators
conceptually, these operators are not very different from regular procs in the way
they are defined and overloaded. keyword params for them are admittedly less useful,
but they improve consistency and may help with generic instantiations once default
generic parameters are supported.
Diffstat (limited to 'compiler/parser.nim')
-rw-r--r--compiler/parser.nim20
1 files changed, 12 insertions, 8 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim
index 7cfd35a41..e400f4bb5 100644
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -627,6 +627,13 @@ proc identOrLiteral(p: var TParser, mode: TPrimaryMode): PNode =
     getTok(p)  # we must consume a token here to prevend endless loops!
     result = ast.emptyNode
 
+proc namedParams(p: var TParser, callee: PNode,
+                 kind: TNodeKind, endTok: TTokType): PNode =
+  let a = callee
+  result = newNodeP(kind, p)
+  addSon(result, a)
+  exprColonEqExprListAux(p, endTok, result)
+
 proc primarySuffix(p: var TParser, r: PNode): PNode =
   #| primarySuffix = '(' (exprColonEqExpr comma?)* ')' doBlocks?
   #|               | doBlocks
@@ -636,11 +643,8 @@ proc primarySuffix(p: var TParser, r: PNode): PNode =
   result = r
   while p.tok.indent < 0:
     case p.tok.tokType
-    of tkParLe: 
-      var a = result
-      result = newNodeP(nkCall, p)
-      addSon(result, a)
-      exprColonEqExprListAux(p, tkParRi, result)
+    of tkParLe:
+      result = namedParams(p, result, nkCall, tkParRi)
       if result.len > 1 and result.sons[1].kind == nkExprColonExpr:
         result.kind = nkObjConstr
       else:
@@ -653,10 +657,10 @@ proc primarySuffix(p: var TParser, r: PNode): PNode =
     of tkDot:
       result = dotExpr(p, result)
       result = parseGStrLit(p, result)
-    of tkBracketLe: 
-      result = indexExprList(p, result, nkBracketExpr, tkBracketRi)
+    of tkBracketLe:
+      result = namedParams(p, result, nkBracketExpr, tkBracketRi)
     of tkCurlyLe:
-      result = indexExprList(p, result, nkCurlyExpr, tkCurlyRi)
+      result = namedParams(p, result, nkCurlyExpr, tkCurlyRi)
     else: break
 
 proc primary(p: var TParser, mode: TPrimaryMode): PNode