Reorganized symbols related to position

This commit is contained in:
Andrew Golovashevich 2025-11-19 01:49:18 +03:00
parent 856bb308d9
commit b6bef111c1
10 changed files with 49 additions and 42 deletions

View File

@ -2,8 +2,9 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::{ use crate::{
CollectedSubstring, Keyword, KeywordComparatorIterator, Pos, Predicate, SourceStream, CollectedSubstring, Keyword, KeywordComparatorIterator, Predicate, SourceStream,
}; };
use crate::pos::Pos;
use std::marker::PhantomData; use std::marker::PhantomData;
pub trait StreamConverter_Char<C: Copy> { pub trait StreamConverter_Char<C: Copy> {

View File

@ -7,15 +7,12 @@ mod ascii;
mod converter; mod converter;
pub mod pos; pub mod pos;
use pos::Pos;
pub trait Predicate<C: Copy> { pub trait Predicate<C: Copy> {
fn check(&mut self, chr: C) -> bool; fn check(&mut self, chr: C) -> bool;
} }
pub trait Pos<'pos> {}
impl Pos<'static> for () {}
impl Pos<'static> for usize {}
pub trait KeywordComparatorIterator<'keyword, C> { pub trait KeywordComparatorIterator<'keyword, C> {
fn consume(&mut self, c: C) -> bool; fn consume(&mut self, c: C) -> bool;
} }

View File

@ -0,0 +1,8 @@
mod index;
mod newline;
mod noop;
pub use index::IndexPosCounter;
pub use newline::PosLineCol;
pub use newline::NewLinePosCounter;
pub use noop::NoopPosCounter;

View File

@ -1,5 +1,4 @@
use crate::Pos; use crate::pos::{PosCounter, Pos};
use crate::pos::PosCounter;
pub struct PosLineCol { pub struct PosLineCol {
pub row: usize, pub row: usize,

View File

@ -0,0 +1,17 @@
use crate::pos::PosCounter;
pub struct NoopPosCounter {}
impl Default for NoopPosCounter {
fn default() -> Self {
return NoopPosCounter {};
}
}
impl<C: Copy> PosCounter<'static, C> for NoopPosCounter {
type P = ();
fn update(&mut self, _: C) {}
fn export(&self) {}
}

View File

@ -1,19 +1,7 @@
use crate::Pos; mod pos;
mod pos_counter;
pub trait PosCounter<'pos, C: Copy> { pub use pos::Pos;
type P: Pos<'pos>; pub use pos_counter::PosCounter;
fn update(&mut self, c: C); pub mod default_counters;
fn export(&self) -> Self::P;
}
mod index;
mod newline;
mod nop;
pub use index::IndexPosCounter;
pub use newline::PosLineCol;
pub use newline::NewLinePosCounter;
pub use nop::NopPosCounter;

View File

@ -1,17 +0,0 @@
use crate::pos::PosCounter;
pub struct NopPosCounter {}
impl Default for NopPosCounter {
fn default() -> Self {
return NopPosCounter {};
}
}
impl<C: Copy> PosCounter<'static, C> for NopPosCounter {
type P = ();
fn update(&mut self, _: C) {}
fn export(&self) {}
}

4
src/pos/pos.rs Normal file
View File

@ -0,0 +1,4 @@
pub trait Pos<'pos> {}
impl Pos<'static> for () {}
impl Pos<'static> for usize {}

10
src/pos/pos_counter.rs Normal file
View File

@ -0,0 +1,10 @@
use crate::pos::Pos;
pub trait PosCounter<'pos, C: Copy> {
type P: Pos<'pos>;
fn update(&mut self, c: C);
fn export(&self) -> Self::P;
}