Nim icon indicating copy to clipboard operation
Nim copied to clipboard

hope to support the syntax: allow pragmas in the front of field definition

Open lost22git opened this issue 1 year ago • 2 comments

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

lost22git avatar Jan 24 '24 07:01 lost22git

There was a suggestion to use the reserved [. and .] for this purpose

metagn avatar Jan 24 '24 09:01 metagn

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

hamidb80 avatar Jan 30 '24 04:01 hamidb80