Skip to content

Commit

Permalink
If you have 4 billion lines, you'll need a faster parser anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed May 22, 2023
1 parent 19abd0e commit 4fcfab2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

use std::fmt;

pub(crate) type PosUInt = u32;

/// Represents a position inside some textual document.
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct TextPosition {
/// Row, counting from 0
pub row: u64,
pub row: PosUInt,
/// Column, counting from 0
pub column: u64,
pub column: PosUInt,
}

impl TextPosition {
Expand All @@ -22,13 +24,13 @@ impl TextPosition {
/// Advances the position in a line
#[inline]
pub fn advance(&mut self, count: u8) {
self.column += u64::from(count);
self.column += PosUInt::from(count);
}

/// Advances the position in a line to the next tab position
#[inline]
pub fn advance_to_tab(&mut self, width: u8) {
let width = u64::from(width);
let width = PosUInt::from(width);
self.column += width - self.column % width;
}

Expand Down
5 changes: 3 additions & 2 deletions src/reader/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ impl Lexer {

#[cfg(test)]
mod tests {
use crate::common::PosUInt;
use crate::common::Position;
use std::io::{BufReader, Cursor};

Expand All @@ -667,8 +668,8 @@ mod tests {
let err = $lex.next_token(&mut $buf);
assert!(err.is_err());
let err = err.unwrap_err();
assert_eq!($r as u64, err.position().row);
assert_eq!($c as u64, err.position().column);
assert_eq!($r as PosUInt, err.position().row);
assert_eq!($c as PosUInt, err.position().column);
})
);

Expand Down

0 comments on commit 4fcfab2

Please sign in to comment.