Skip to content

Support constant-folded expressions as enum values #2191

@evantypanski

Description

@evantypanski

from @Mohan-Dhawan on Slack

Spicy does not allow enum fields to be defined using expressions, for example:

type MyPolicy = enum {
  NONE = 0,
  SUCCESS = 1,
  FAILURE = 2,
  ALL = (SUCCESS | FAILURE),
  CLEAR = 4,
};

Is there an easy workaround for this limitation? I am translating from an existing DSL specification in which such expressions are common. Allowing expressions in enum definitions would be a useful enhancement to Spicy

I agree with this. Right now, the enum_label is parsed to only be CUINTEGER (which is just ints and character literals). It'd be nice to have more flexibility.

There are a couple hurdles here, namely that we would need to fold the SUCCESS | FAILURE constant at some point, then validate that to ensure that it's not overlapping with another enum label and whatnot. I think that problem and some related ones would make this tricky, but doable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions