nervosnetwork / molecule

Another serialization system: minimalist and canonicalization.
MIT License
36 stars 23 forks source link

Proposed new syntax to support custom implementation of union id #59

Closed driftluo closed 1 year ago

driftluo commented 2 years ago

Currently, the scheme of the union type is:

union DiscoveryPayload {
    A,
    B,
    C,
    D,
}

The parser implicitly sets the id of the union child to increment from 0. The scheme above can be translated as:

union DiscoveryPayload {
    A = 0,
    B = 1,
    C = 2,
    D = 3,
}

Unfortunately, the current union syntax does not support customizing this id, with the consequence that the generated code cannot be deleted if the preceding child is disambiguated because the id is automatically generated by the parser

From the perspective of real projects, it is relatively common for union subclauses to be deprecated, and it is good for users to support the new syntax for customizing ids