Skip to content

Allow any attributes on rules #383

@Mingun

Description

@Mingun

I want to feature gate some rules in grammar, so tried to place #[cfg(feature = "...")] on it, but grammar! does not accept that. It would be nice if I could do that:

peg::parser! {
  /// Contains generated parser for Kaitai Struct expression language.
  grammar parser() for str {
    /// Entry point for parsing enum values (keys of `number: enum_variant_name`).
    // TODO: It is better to use integer() rule to parse that
    // See https://github.com/kaitai-io/kaitai_struct/issues/1132
    #[cfg(feature = "compatible")] //<<<<<<<<<<<<<<<<<<<<<< impossible
    pub rule parse_enum_value() -> BigInt
      = "0x" n:$(hex()+) {? to_int(n, 16) }
      / n:$(['0'..='9' | '_']+) {? to_int(n, 10) }
      ;
    #[cfg(not(feature = "compatible"))] //<<<<<<<<<<<<<<<<<<<<<< impossible
    pub rule parse_enum_value() -> BigInt
      = "-" n:integer() { -n }
      / integer()
      ;
  }
}

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