Add pragma accessors

This library requires a forked macros module, so export accessors
that would prevent a downstream library from having the same
problems with std/macros.
This commit is contained in:
Emery Hemingway 2022-04-25 11:33:37 -05:00
parent f32e783e0b
commit ddc26f0c71
1 changed files with 20 additions and 0 deletions

View File

@ -635,6 +635,18 @@ template preservesRecord*(label: string) {.pragma.}
## Serialize this object or tuple as a record.
## See ``toPreserve``.
proc hasPreservesRecordPragma*(T: typedesc): bool =
## Test if a type has a `{.preservesRecord: "…".}` pragma attached.
hasCustomPragma(T, preservesRecord)
proc recordLabel*(T: typedesc): string =
## Get the record label set by a pragma on a type.
runnableExamples:
type Foo {.preservesRecord: "bar".} = object
n: int
assert recordLabel(Foo) == "bar"
T.getCustomPragmaVal(preservesRecord)
template preservesTuple*() {.pragma.}
## Serialize this object or tuple as a tuple.
## See ``toPreserve``.
@ -643,10 +655,18 @@ template preservesTupleTail*() {.pragma.}
## Serialize this object field to the end of its containing tuple.
## See ``toPreserve``.
proc hasPreservesTuplePragma*(T: typedesc): bool =
## Test if a type has a `preservesTuple` pragma attached.
hasCustomPragma(T, preservesTuple)
template preservesDictionary*() {.pragma.}
## Serialize this object or tuple as a dictionary.
## See ``toPreserve``.
proc hasPreservesDictionaryPragma*(T: typedesc): bool =
## Test if a type has a `preservesDictionary` pragma attached.
hasCustomPragma(T, preservesDictionary)
template preservesOr*() {.pragma.}
## Serialize this object as an ``or`` alternative.
## See ``toPreserve``.