[−][src]Struct string_parser::Parser
Main struct of the crate
Example
./text being "...'foo'..."
use std::rc::Rc; extern crate string_parser; use string_parser::Parser; fn end_filter(c : Vec<char>) -> bool{ if c.last().unwrap()== &'\'' { return true; } else { return false; } } //can also use closures let callback = |s : String, line : usize, file : &str| { assert_eq!(String::from("foo"), s); }; let mut string_parser = Parser::new(); string_parser.add(String::from("'"), Rc::new(Box::from(end_filter)), Rc::new(Box::from(callback))); string_parser.parse("./text");
Fields
keywords: Vec<String>
The list of keyword to parse
end_filters: HashMap<String, Rc<Box<dyn Fn(Vec<char>) -> bool>>>
Filter funtions for each keyword (indexed by keyword)
callbacks: HashMap<String, Rc<Box<dyn Fn(String, usize, &str)>>>
Callback funtions for each keyword (indexed by keyword)
Implementations
impl Parser
[src]
pub fn new() -> Parser
[src]
Instanciante a new empty Parser
pub fn add(
&mut self,
keyword: String,
end_filter: Rc<Box<dyn Fn(Vec<char>) -> bool>>,
callback: Rc<Box<dyn Fn(String, usize, &str)>>
) -> &Parser
[src]
&mut self,
keyword: String,
end_filter: Rc<Box<dyn Fn(Vec<char>) -> bool>>,
callback: Rc<Box<dyn Fn(String, usize, &str)>>
) -> &Parser
Add a new token to parse
Arguments
text
- the text to searchend_filter
- the function called at each character to check if we're still within the token. Sould return true when out of the token. It receives the vector of characters inside the token- Should return true when at the end of the token
Example
fn end_filter(c : Vec<char>) -> bool{ if c.last().unwrap() == &'\'' { println!("end filter"); return true; } else { return false; } }
callback
- the function called when the text is exited. take the inside of the token as argument it should takes 3 arguments- The text inside the token
- The line Number of the token
- The file
Example
let callback = |s : String, line : usize, file : String| { println!("{} {} : {}", file, line, s); };
pub fn get_keywords(self) -> Vec<String>
[src]
pub fn get_end_filters(
self
) -> HashMap<String, Rc<Box<dyn Fn(Vec<char>) -> bool>>>
[src]
self
) -> HashMap<String, Rc<Box<dyn Fn(Vec<char>) -> bool>>>
pub fn get_callbacks(
self
) -> HashMap<String, Rc<Box<dyn Fn(String, usize, &str)>>>
[src]
self
) -> HashMap<String, Rc<Box<dyn Fn(String, usize, &str)>>>
pub fn parse(&self, path: &str) -> Result<(), Error>
[src]
Open the file and parse every token of the Parser
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Parser
impl !Send for Parser
impl !Sync for Parser
impl Unpin for Parser
impl !UnwindSafe for Parser
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,