pub struct Rules {
pub symbols: Vec<char>,
pub region_tree: Region,
pub escape_symbol: char,
pub compounds: Vec<(char, char)>,
}Expand description
Determine lexing rules for the parser
Rules struct that contains list of symbols as well as region tree
This struct requires two things:
- List of symbols
- Region Tree
More on those below in the Fields section
§Example
let symbols = vec!['+', '-', '*', '/', '(', ')', '&', '|', '!'];
let compounds = vec![('&', '&'), ('|', '|')];
let region = reg![
reg!(str as "string literal" => {
begin: "'",
end: "'"
})
];
Rules::new(symbols, compounds, region);Fields§
§symbols: Vec<char>Symbols that should be separated (most commonly: (, ), +, -, …)
This handles situations like for instance if we want to parse 1+1 as
three tokens 1 + 1 and not single 1+1 token.
region_tree: RegionRegion tree that determines what code regions should remain untokenized. Most common case is a string where we want to preserve all the spaces and words inside.
escape_symbol: charEscape symbol
compounds: Vec<(char, char)>Vector of pairs of symbols that should be merged together
Implementations§
Trait Implementations§
impl StructuralPartialEq for Rules
Auto Trait Implementations§
impl Freeze for Rules
impl RefUnwindSafe for Rules
impl Send for Rules
impl Sync for Rules
impl Unpin for Rules
impl UnwindSafe for Rules
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more