mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Track line start separately
This commit is contained in:
parent
5ac3394a73
commit
422cdea112
2 changed files with 17 additions and 3 deletions
|
@ -14,6 +14,8 @@ pub struct State<'a> {
|
|||
/// Length of the original input in bytes
|
||||
input_len: usize,
|
||||
|
||||
line_start: Position,
|
||||
|
||||
/// Current position within the input (line/column)
|
||||
pub xyzlcol: JustColumn,
|
||||
|
||||
|
@ -33,6 +35,7 @@ impl<'a> State<'a> {
|
|||
State {
|
||||
bytes,
|
||||
input_len: bytes.len(),
|
||||
line_start: Position::zero(),
|
||||
xyzlcol: JustColumn { column: 0 },
|
||||
indent_column: 0,
|
||||
}
|
||||
|
@ -49,6 +52,13 @@ impl<'a> State<'a> {
|
|||
state
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn advance_newline(&self) -> State<'a> {
|
||||
let mut state = self.advance(1);
|
||||
state.line_start = state.pos();
|
||||
state
|
||||
}
|
||||
|
||||
/// Returns the current position
|
||||
pub const fn pos(&self) -> Position {
|
||||
Position::new((self.input_len - self.bytes.len()) as u32)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue