basename supports pragmaexpr (#13045)
* basename supports pragmaexpr * update changelog
This commit is contained in:
parent
291608045c
commit
8bcc7e8b9e
2 changed files with 6 additions and 3 deletions
|
|
@ -16,7 +16,8 @@
|
|||
- `set[T].len` is now an alias for `set[T].card` (cardinality)
|
||||
|
||||
## Library changes
|
||||
|
||||
- `macros.basename` and `basename=` got support for `PragmaExpr`,
|
||||
so that an expression like `MyEnum {.pure.}` is handled correctly.
|
||||
|
||||
## Language additions
|
||||
|
||||
|
|
|
|||
|
|
@ -1328,8 +1328,9 @@ proc insert*(a: NimNode; pos: int; b: NimNode) {.compileTime.} =
|
|||
proc basename*(a: NimNode): NimNode =
|
||||
## Pull an identifier from prefix/postfix expressions.
|
||||
case a.kind
|
||||
of nnkIdent: return a
|
||||
of nnkPostfix, nnkPrefix: return a[1]
|
||||
of nnkIdent: result = a
|
||||
of nnkPostfix, nnkPrefix: result = a[1]
|
||||
of nnkPragmaExpr: result = basename(a[0])
|
||||
else:
|
||||
error("Do not know how to get basename of (" & treeRepr(a) & ")\n" &
|
||||
repr(a), a)
|
||||
|
|
@ -1340,6 +1341,7 @@ proc `basename=`*(a: NimNode; val: string) {.compileTime.}=
|
|||
a.strVal = val
|
||||
of nnkPostfix, nnkPrefix:
|
||||
a[1] = ident(val)
|
||||
of nnkPragmaExpr: `basename=`(a[0], val)
|
||||
else:
|
||||
error("Do not know how to get basename of (" & treeRepr(a) & ")\n" &
|
||||
repr(a), a)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue