I feel like this should be allowed. I'm rewriting some two year old code and wanted to move from an external code generator to using a macro. However, I can't tag the proper serialization values on to the enums due to this restriction.
template id_key(value: int) {.pragma.}
type
MajorType* = enum
mtPositiveInteger {.id_key: 0.}
mtNegativeInteger {.id_key: 1.}
mtBinaryString {.id_key: 2.}
mtUnicodeString {.id_key: 3.}
mtArray {.id_key: 4.}
mtMap {.id_key: 5.}
mtSemantic {.id_key: 6.}
mtSpecial {.id_key: 7.}
I'll have to work around this either by bringing the code generator back, or working around it with a different kind of macro. But it's somewhat annoying that enum elements cannot be tagged in this way.
Not quite sure what you're trying to do, but you are aware you can change the value Nim enums serialize to like this right?
type
MajorType* = enum
mtPositiveInteger = 0
mtNegativeInteger = 1
mtBinaryString = 2
mtUnicodeString = 3
mtArray = 4
mtMap = 5
mtSemantic = 6
mtSpecial = 7
That being said those are the values this particular enum would have for these fields anyways. So you could simply not specify them. Again, not entirely sure what you're trying to do, so this might not apply, but thought I'd mention it just in case.
Oh, and the code-generator should be possible to write as a macro ;)
Also :
type
MajorType* = enum
mtPositiveInteger
mtNegativeInteger
mtBinaryString
mtUnicodeString
mtArray
mtMap
mtSemantic
mtSpecial
const id_key = [
mtPositiveInteger: 0,
mtNegativeInteger: 1,
mtBinaryString: 2,
mtUnicodeString: 3,
mtArray: 4,
mtMap: 5,
mtSemantic: 6,
mtSpecial: 7
]
echo id_key[mtSpecial]
Not quite sure what you're trying to do, but you are aware you can change the value Nim enums serialize to like this right?
I thought it was obvious? The compiler docs specifically use this example for writing ORMs and using macros to specify the relationships to fields. It works fine (and is literally documented) for records, just not enum fields.