Make Lex less mutable
This commit is contained in:
parent
f31094d115
commit
ddf13f9bae
1 changed files with 9 additions and 5 deletions
|
@ -19,17 +19,21 @@ pub enum Token {
|
||||||
String(String),
|
String(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Lex is a Token extracted from a specific position in an input stream. It
|
/// A Lex is a Token extracted from a specific position in an input string. It contains useful
|
||||||
/// contains useful information about the token's place.
|
/// information about the token's place in that input.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Lex {
|
pub struct Lex {
|
||||||
pub token: Token,
|
token: Token,
|
||||||
pub line: usize,
|
line: usize,
|
||||||
pub offset: usize,
|
offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Lex {
|
impl Lex {
|
||||||
pub fn new(token: Token, line: usize, offset: usize) -> Lex {
|
pub fn new(token: Token, line: usize, offset: usize) -> Lex {
|
||||||
Lex { token: token, line: line, offset: offset }
|
Lex { token: token, line: line, offset: offset }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn token(&self) -> &Token { &self.token }
|
||||||
|
pub fn line(&self) -> usize { self.line }
|
||||||
|
pub fn offset(&self) -> usize { self.offset }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue