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