pub struct LexemeDescriptor<LexemeType> {
pub lexeme_type: LexemeType,
pub pattern: Regex,
}
Expand description
Describes a category of lexemes with similar syntactic meanings.
This is used as part of a lexical-analyzer’s specification, as it is built to recognize different types of lexemes.
Fields§
§lexeme_type: LexemeType
The type of lexemes being described.
pattern: Regex
A regular-expression pattern that matches the lexemes of the specified type.
Implementations§
Source§impl<LexemeType> LexemeDescriptor<LexemeType>
impl<LexemeType> LexemeDescriptor<LexemeType>
Sourcepub fn new(lexeme_type: LexemeType, pattern: Regex) -> Self
pub fn new(lexeme_type: LexemeType, pattern: Regex) -> Self
Creates a LexemeDescriptor describing the specified lexeme_type
with the specified
pattern
.
Sourcepub fn keyword(lexeme_type: LexemeType, name: &str) -> Self
pub fn keyword(lexeme_type: LexemeType, name: &str) -> Self
Creates a new LexemeDescriptor that describes a keyword.
A keyword is a type of lexeme that only matches some hard-coded string (such as if
or
int
). This function can be used to efficiently describe such keywords.
§Example
enum MyLexemeType { If, While }
let my_lexeme_descriptors = vec![
LexemeDescriptor::keyword(MyLexemeType::If, "if"),
LexemeDescriptor::keyword(MyLexemeType::While, "while"),
];
Sourcepub fn special_char(lexeme_type: LexemeType, value: char) -> Self
pub fn special_char(lexeme_type: LexemeType, value: char) -> Self
Creates a new LexemeDescriptor that describes a special character.
A special character is a type of lexeme that only matches some hard-coded character (such as
operators: +
, *
). This function can be used to efficiently describe such characters.
§Example
enum MyLexemeType { Addition, Subtraction }
let my_lexeme_descriptors = vec![
LexemeDescriptor::special_char(MyLexemeType::Addition, '+'),
LexemeDescriptor::special_char(MyLexemeType::Subtraction, '-'),
];