From aedc0b4b44d9b5958a467cebb9c8c313684a79b3 Mon Sep 17 00:00:00 2001 From: Amitabh Ranjan <152239636+amitabhcs01@users.noreply.github.com> Date: Tue, 11 Feb 2025 23:14:27 +0530 Subject: [PATCH] Update input.rs (Added Location struct) 1)Added Location struct 2) Ensured Location updates correctly (tracking both lines and columns) 3) Retained test functionality --- src/input.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/input.rs b/src/input.rs index bee0d3c..cdedb5e 100644 --- a/src/input.rs +++ b/src/input.rs @@ -4,7 +4,34 @@ use source::Location; use std::str::Chars; use std::fmt; use std::collections::VecDeque; +pub struct Location { + line: usize, + column: usize, +} + +impl Location { + pub fn new(line: usize, column: usize) -> Self { + Self { line, column } + } + pub fn start() -> Self { + Self { line: 1, column: 0 } + } + + pub fn next(&self) -> Self { + Self { + line: self.line, + column: self.column + 1, + } + } + + pub fn next_line(&self) -> Self { + Self { + line: self.line + 1, + column: 0, + } + } +} pub struct CharsReader<'a> { input_chars: Chars<'a>, lookahead: VecDeque,