Struct slr_parser::Lexer
source · pub struct Lexer<'l, 's>where
's: 'l,{
pub cur_token: Option<Result<Token<'s>, Error>>,
pub next_token: Option<Result<Token<'s>, Error>>,
/* private fields */
}
Expand description
A type handling the lexing.
Fields§
§cur_token: Option<Result<Token<'s>, Error>>
§next_token: Option<Result<Token<'s>, Error>>
Implementations§
source§impl<'l, 's> Lexer<'l, 's>
impl<'l, 's> Lexer<'l, 's>
sourcepub fn new(source: &'l mut Source<'s>) -> Lexer<'l, 's>
pub fn new(source: &'l mut Source<'s>) -> Lexer<'l, 's>
Creates a new lexer from a source. The source will be reset by this operation, and must not be used with any spans created from a previous lexing done with that source.
Examples found in repository?
src/lexer_test.rs (line 27)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
fn main()
{
let mut args = env::args();
if args.len() < 2
{
panic!("Pass a file to test with");
}
args.next();
let filename = args.next().unwrap();
let mut src = String::new();
File::open(&filename)
.unwrap()
.read_to_string(&mut src)
.unwrap();
let mut src = Source::new(Path::new(&filename), &src);
let mut lexer = Lexer::new(&mut src);
loop
{
let tok = lexer.next();
match tok.as_ref()
{
Some(res) => match res.as_ref()
{
Ok(tok) => println!("{:?}", tok.kind),
Err(err) =>
{
println!("{}", err.text);
break;
}
},
None => break,
}
}
}
pub fn get_source(&self) -> &Source<'s> ⓘ
sourcepub fn next(&mut self) -> Option<Result<Token<'s>, Error>>
pub fn next(&mut self) -> Option<Result<Token<'s>, Error>>
Examples found in repository?
src/lexer_test.rs (line 31)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
fn main()
{
let mut args = env::args();
if args.len() < 2
{
panic!("Pass a file to test with");
}
args.next();
let filename = args.next().unwrap();
let mut src = String::new();
File::open(&filename)
.unwrap()
.read_to_string(&mut src)
.unwrap();
let mut src = Source::new(Path::new(&filename), &src);
let mut lexer = Lexer::new(&mut src);
loop
{
let tok = lexer.next();
match tok.as_ref()
{
Some(res) => match res.as_ref()
{
Ok(tok) => println!("{:?}", tok.kind),
Err(err) =>
{
println!("{}", err.text);
break;
}
},
None => break,
}
}
}
Auto Trait Implementations§
impl<'l, 's> RefUnwindSafe for Lexer<'l, 's>
impl<'l, 's> Send for Lexer<'l, 's>
impl<'l, 's> Sync for Lexer<'l, 's>
impl<'l, 's> Unpin for Lexer<'l, 's>
impl<'l, 's> !UnwindSafe for Lexer<'l, 's>
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