Add offset to Location type
This commit is contained in:
parent
f9349edf77
commit
b7f796322b
@ -226,7 +226,7 @@ struct TokenHandler {
|
|||||||
impl TokenHandler {
|
impl TokenHandler {
|
||||||
fn new(tokens: Vec<Token>) -> TokenHandler {
|
fn new(tokens: Vec<Token>) -> TokenHandler {
|
||||||
let end_of_file = match tokens.last() {
|
let end_of_file = match tokens.last() {
|
||||||
None => Location { line_num: 0, char_num: 0 },
|
None => Location { line_num: 0, char_num: 0, offset: 0 },
|
||||||
Some(t) => t.location,
|
Some(t) => t.location,
|
||||||
};
|
};
|
||||||
TokenHandler { idx: 0, tokens, end_of_file }
|
TokenHandler { idx: 0, tokens, end_of_file }
|
||||||
|
@ -17,6 +17,7 @@ use itertools::Itertools;
|
|||||||
pub struct Location {
|
pub struct Location {
|
||||||
pub(crate) line_num: u32,
|
pub(crate) line_num: u32,
|
||||||
pub(crate) char_num: u16,
|
pub(crate) char_num: u16,
|
||||||
|
pub(crate) offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Location {
|
impl fmt::Display for Location {
|
||||||
@ -221,8 +222,11 @@ pub fn tokenize(input: &str) -> Vec<Token> {
|
|||||||
c if is_operator(&c) => handle_operator(c, &mut input),
|
c if is_operator(&c) => handle_operator(c, &mut input),
|
||||||
unknown => Error(format!("Unexpected character: {}", unknown)),
|
unknown => Error(format!("Unexpected character: {}", unknown)),
|
||||||
};
|
};
|
||||||
let location =
|
let location = Location {
|
||||||
Location { line_num: line_num.try_into().unwrap(), char_num: char_num.try_into().unwrap() };
|
offset: 0,
|
||||||
|
line_num: line_num.try_into().unwrap(),
|
||||||
|
char_num: char_num.try_into().unwrap(),
|
||||||
|
};
|
||||||
tokens.push(Token { kind: cur_tok_kind, location });
|
tokens.push(Token { kind: cur_tok_kind, location });
|
||||||
}
|
}
|
||||||
tokens
|
tokens
|
||||||
|
Loading…
Reference in New Issue
Block a user