diff options
author | Araq <rumpf_a@web.de> | 2012-08-26 02:47:17 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-08-26 02:47:17 +0200 |
commit | b5b5e6e76df228f573ae86780c66889f4b426301 (patch) | |
tree | 10471ab5c2d742e6ea09974b1420002112459b3a /lib/core | |
parent | 9a7f0cd8510a534a3f1e9d4275b8abd7825a94c6 (diff) | |
download | Nim-b5b5e6e76df228f573ae86780c66889f4b426301.tar.gz |
distinguish properly between nkOpen and nkClosedSymChoice
Diffstat (limited to 'lib/core')
-rwxr-xr-x | lib/core/macros.nim | 28 |
1 files changed, 24 insertions, 4 deletions
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)) |