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>

source

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,
		}
	}
}
source

pub fn get_source(&self) -> &Source<'s>

source

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.