diff --git a/src/filter/lexer.rs b/src/filter/lexer.rs index 4e672e5..51f29cd 100644 --- a/src/filter/lexer.rs +++ b/src/filter/lexer.rs @@ -23,7 +23,7 @@ impl<'a> Scanner<'a> { if let Some((idx, c)) = self.chars.peek() { if *c == '\n' { self.line += 1; - self.line_start = *idx; + self.line_start = *idx + 1; } if *c == next { @@ -40,7 +40,7 @@ impl<'a> Scanner<'a> { while let Some((idx, c)) = self.chars.peek() { if *c == '\n' { self.line += 1; - self.line_start = *idx; + self.line_start = *idx + 1; } if !f(*idx, *c) { @@ -60,7 +60,7 @@ impl<'a> Scanner<'a> { match c { '\n' => { self.line += 1; - self.line_start = idx; + self.line_start = idx + 1; } '"' => { return Ok(Token::String(start_loc, &self.source[start + 1..idx])); @@ -126,7 +126,7 @@ impl<'a> Iterator for Scanner<'a> { ' ' | '\t' => {} '\n' => { self.line += 1; - self.line_start = idx; + self.line_start = idx + 1; } '(' => { return Some(Ok(Token::LeftParen(Loc::new( @@ -236,7 +236,7 @@ mod tests { $( match scanner.next() { Some(Ok($item)) => {}, - Some(Ok(item)) => panic!("Expected '{}' but got '{}'", stringify!($item), item), + Some(Ok(item)) => panic!("Expected '{}' but got '{:?}'", stringify!($item), item), Some(Err(e)) => panic!("Error: {}", e), None => panic!("Expected '{}' but got the end of the parse sequence instead", stringify!($item)), } @@ -338,4 +338,14 @@ mod tests { Token::Property(.., "artifact.source-code"), ); } + + #[test] + fn test_location() { + assert_sequence!( + "true !=\nfalse", + Token::True(Loc { line: 1, column: 1 }), + Token::NotEquals(Loc { line: 1, column: 6 }), + Token::False(Loc { line: 2, column: 1 }) + ); + } } diff --git a/src/filter/location.rs b/src/filter/location.rs index 9e29bfd..22145a7 100644 --- a/src/filter/location.rs +++ b/src/filter/location.rs @@ -2,8 +2,8 @@ use std::fmt::Display; #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Clone, Hash, Default)] pub struct Loc { - line: usize, - column: usize, + pub line: usize, + pub column: usize, } impl Loc {