[][src]Derive Macro sana_derive::Sana

#[derive(Sana)]
{
    // Attributes available to this derive:
    #[backend]
    #[error]
    #[regex]
    #[token]
}

Derives lexer for the given enum

Attributes

  • #[backend(be)]: set the lexer backend. Valid values are rust and vm. This attribute must be placed before the enum definiton.
  • #[error]: mark the given variant as the error variant. There must be exactly one error variant for a given enum
  • #[regex(re)]: specify the regular expression corresponding to the given variant
  • #[token(tok)]: specify the string corresponding to the given variant

Attributes regex and token can also receive the following parameters:

  • priority = <integer> (default is 0): the priority for the rule

Regular expression syntax

Regular expression, passed to attribute regex, has the following syntax:

regex =
    regex '|' regex
    / regex '&' regex
    / regex '.' regex
    / '!' regex
    / '(' regex ')'
    / literal

Here, literal is rust string literal containing regular expression using the regex crate syntax. | denotes the union of regular expressions, & denotes the intersection, and . denotes the concatenation. ! denotes the complement of a regular expression.

The priorities of the operations match the order in the syntax definiton. So a | b . c is the same as a | (b . c).