From b5b5e6e76df228f573ae86780c66889f4b426301 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 26 Aug 2012 02:47:17 +0200 Subject: distinguish properly between nkOpen and nkClosedSymChoice --- lib/core/macros.nim | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'lib/core') diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 30248528e..fac935430 100755 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -27,7 +27,10 @@ type nnkBracket, nnkBracketExpr, nnkPragmaExpr, nnkRange, nnkDotExpr, nnkCheckedFieldExpr, nnkDerefExpr, nnkIfExpr, nnkElifExpr, nnkElseExpr, nnkLambda, nnkDo, nnkAccQuoted, - nnkTableConstr, nnkBind, nnkSymChoice, nnkHiddenStdConv, + nnkTableConstr, nnkBind, + nnkClosedSymChoice, + nnkOpenSymChoice, + nnkHiddenStdConv, nnkHiddenSubConv, nnkHiddenCallConv, nnkConv, nnkCast, nnkStaticExpr, nnkAddr, nnkHiddenAddr, nnkHiddenDeref, nnkObjDownConv, nnkObjUpConv, nnkChckRangeF, nnkChckRange64, nnkChckRange, @@ -186,12 +189,29 @@ proc newIdentNode*(i: string): PNimrodNode {.compileTime.} = result = newNimNode(nnkIdent) result.ident = !i -proc bindSym*(ident: string): PNimrodNode {.magic: "NBindSym".} +type + TBindSymRule* = enum ## specifies how ``bindSym`` behaves + brClosed, ## only the symbols in current scope are bound + brOpen, ## open wrt overloaded symbols, but may be a single + ## symbol if not ambiguous (the rules match that of + ## binding in generics) + brForceOpen ## same as brOpen, but it will always be open even + ## if not ambiguous (this cannot be achieved with + ## any other means in the language currently) + +proc bindSym*(ident: string, rule: TBindSymRule = brClosed): PNimrodNode {. + magic: "NBindSym".} ## creates a node that binds `ident` to a symbol node. The bound symbol - ## needs to be predeclared in a ``bind`` statement! + ## may be an overloaded symbol. + ## If ``rule == brClosed`` either an ``nkClosedSymChoice`` tree is + ## returned or ``nkSym`` if the symbol is not ambiguous. + ## If ``rule == brOpen`` either an ``nkOpenSymChoice`` tree is + ## returned or ``nkSym`` if the symbol is not ambiguous. + ## If ``rule == brForceOpen`` always an ``nkOpenSymChoice`` tree is + ## returned even if the symbol is not ambiguous. proc toStrLit*(n: PNimrodNode): PNimrodNode {.compileTime.} = - ## converts the AST `n` to the concrete Nimrod code and wraps that + ## converts the AST `n` to the concrete Nimrod code and wraps that ## in a string literal node return newStrLitNode(repr(n)) -- cgit 1.4.1-2-gfad0