Skip to content

Commit

Permalink
basename supports pragmaexpr (#13045)
Browse files Browse the repository at this point in the history
* basename supports pragmaexpr

* update changelog
  • Loading branch information
planetis-m authored and Araq committed Jan 7, 2020
1 parent 2916080 commit 8bcc7e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion changelogs/changelog_X_XX_X.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8bcc7e8

Please sign in to comment.