lexer-rs 0.0.4

Lexical anaylzer framework for context-free text parsing into tokens
Documentation
//a Imports
use crate::UserPosn;

//a PosnIn traits
//tt PosnInCharStream
/// Trait for location within a character stream
///
/// This tracks a byte offset within the stream so that strings can be
/// retrieved from the stream. Byte offsets *must* always be on UTF8
/// boundaries.
pub trait PosnInCharStream: UserPosn {
    //mp byte_ofs
    /// Return the byte offset into the stream of the position.
    ///
    /// This must *always* be a UTF8 character boundary; it will be so
    fn byte_ofs(&self) -> usize;

    //mp move_by_char
    /// Move on by a character
    fn move_by_char(self, ch: char) -> Self {
        let n = ch.len_utf8();
        if ch == '\n' {
            self.advance_line(n)
        } else {
            self.advance_cols(n, 1)
        }
    }
}

//ip PosnInCharStream for usize
impl PosnInCharStream for usize {
    fn byte_ofs(&self) -> usize {
        *self
    }
}