From 558c5dcaf7bcc32cfe5672c4113962e3bcd19188 Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Thu, 7 May 2026 17:46:44 +0300 Subject: Add lexer --- compiler/src/span.rs | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 compiler/src/span.rs (limited to 'compiler/src/span.rs') diff --git a/compiler/src/span.rs b/compiler/src/span.rs new file mode 100644 index 0000000..0644c1c --- /dev/null +++ b/compiler/src/span.rs @@ -0,0 +1,61 @@ +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct Pos { + line: usize, + column: usize, + cursor: usize, +} + +impl Pos { + pub fn new(line: usize, column: usize, cursor: usize) -> Self { + Self { + line, + column, + cursor, + } + } + + pub fn line(self) -> usize { + self.line + } + + pub fn column(self) -> usize { + self.column + } + + pub fn cursor(self) -> usize { + self.cursor + } +} + +#[derive(Clone, Debug)] +pub struct Span { + inner: T, + start: Pos, + end: Pos, +} + +impl Span { + pub fn new(inner: T, start: Pos, end: Pos) -> Self { + Self { inner, start, end } + } + + pub fn inner(&self) -> &T { + &self.inner + } + + pub fn inner_mut(&mut self) -> &mut T { + &mut self.inner + } + + pub fn into_inner(self) -> T { + self.inner + } + + pub fn start(&self) -> Pos { + self.start + } + + pub fn end(&self) -> Pos { + self.end + } +} -- cgit v1.3