commit
9f18a4f448
3 changed files with 31 additions and 1 deletions
|
|
@ -25,6 +25,8 @@
|
||||||
- Added `split`, `splitWhitespace`, `size`, `alignLeft`, `align`,
|
- Added `split`, `splitWhitespace`, `size`, `alignLeft`, `align`,
|
||||||
`strip`, `repeat` procs and iterators to `unicode.nim`.
|
`strip`, `repeat` procs and iterators to `unicode.nim`.
|
||||||
|
|
||||||
|
- Added `or` for `NimNode` in `macros`.
|
||||||
|
|
||||||
### Library changes
|
### Library changes
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,21 @@ proc `[]=`*(n: NimNode, i: BackwardsIndex, child: NimNode) =
|
||||||
## set `n`'s `i`'th child to `child`.
|
## set `n`'s `i`'th child to `child`.
|
||||||
n[n.len - i.int] = child
|
n[n.len - i.int] = child
|
||||||
|
|
||||||
|
template `or`*(x, y: NimNode): NimNode =
|
||||||
|
## Evaluate ``x`` and when it is not an empty node, return
|
||||||
|
## it. Otherwise evaluate to ``y``. Can be used to chain several
|
||||||
|
## expressions to get the first expression that is not empty.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
##
|
||||||
|
## let node = mightBeEmpty() or mightAlsoBeEmpty() or fallbackNode
|
||||||
|
|
||||||
|
let arg = x
|
||||||
|
if arg != nil and arg.kind != nnkEmpty:
|
||||||
|
arg
|
||||||
|
else:
|
||||||
|
y
|
||||||
|
|
||||||
proc add*(father, child: NimNode): NimNode {.magic: "NAdd", discardable,
|
proc add*(father, child: NimNode): NimNode {.magic: "NAdd", discardable,
|
||||||
noSideEffect, locks: 0.}
|
noSideEffect, locks: 0.}
|
||||||
## Adds the `child` to the `father` node. Returns the
|
## Adds the `child` to the `father` node. Returns the
|
||||||
|
|
@ -1433,4 +1448,3 @@ proc getProjectPath*(): string = discard
|
||||||
## Returns the path to the currently compiling project, not to
|
## Returns the path to the currently compiling project, not to
|
||||||
## be confused with ``system.currentSourcePath`` which returns
|
## be confused with ``system.currentSourcePath`` which returns
|
||||||
## the path of the current module.
|
## the path of the current module.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,3 +79,17 @@ static:
|
||||||
assert fooSym.kind in {nnkOpenSymChoice, nnkClosedSymChoice}
|
assert fooSym.kind in {nnkOpenSymChoice, nnkClosedSymChoice}
|
||||||
assert fooSym.eqIdent("fOO")
|
assert fooSym.eqIdent("fOO")
|
||||||
assertNot fooSym.eqIdent("bar")
|
assertNot fooSym.eqIdent("bar")
|
||||||
|
|
||||||
|
var empty: NimNode
|
||||||
|
var myLit = newLit("str")
|
||||||
|
|
||||||
|
assert( (empty or myLit) == myLit )
|
||||||
|
|
||||||
|
empty = newEmptyNode()
|
||||||
|
|
||||||
|
assert( (empty or myLit) == myLit )
|
||||||
|
|
||||||
|
proc bottom(): NimNode =
|
||||||
|
quit("may not be evaluated")
|
||||||
|
|
||||||
|
assert( (myLit or bottom()) == myLit )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue