Nim
Nim copied to clipboard
hope to support the syntax: allow pragmas in the front of field definition
Summary
I think this will be easier to read (like rust/c# attributes or java annotations)
current: If there are multiple pragmas, you may not find Field Type under a screen (there is only one pragma for example)
type
Book = object
isbn {.valid: @[regex(pattern = r"ISBN \d{3}-\d{10}", tags = ["show"])].}: string
tags {.valid: @[length(min = 2, max = 4, tags = ["show"])].}: seq[string]
price {.valid: @[frange(min = 5, max = 50, tags = ["hide"])].}: float
expected:
type
Book = object
{.valid: @[regex(pattern = r"ISBN \d{3}-\d{10}", tags = ["show"])].}
isbn : string
{.valid: @[length(min = 2, max = 4, tags = ["show"])].}
tags: seq[string]
{.valid: @[frange(min = 5, max = 50, tags = ["hide"])].}
price : float
Description
none
Alternatives
No response
Examples
No response
Backwards Compatibility
No response
Links
No response
There was a suggestion to use the reserved [. and .] for this purpose
not a big deal, you can just write:
template valid*(r: untyped) {.pragma.}
type
Book = object
isbn
{.valid: @[regex(pattern = r"ISBN \d{3}-\d{10}", tags = ["show"])].}:
string
tags
{.valid: @[length(min = 2, max = 4, tags = ["show"])].}:
seq[string]
price
{.valid: @[frange(min = 5, max = 50, tags = ["hide"])].}:
float
which is not much different