katex-parser 0.1.0

A port of the KaTeX parser: lexing and parsing LaTeX math expressions with macro expansion into a typed AST, plus a Unicode rendering backend
Documentation
use std::sync::Arc;

/// A span of the original input. `start`/`end` are char offsets into `input`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceLocation {
    pub input: Arc<str>,
    pub start: usize,
    pub end: usize,
}

impl SourceLocation {
    pub fn new(input: impl Into<Arc<str>>, start: usize, end: usize) -> Self {
        SourceLocation {
            input: input.into(),
            start,
            end,
        }
    }

    pub fn range(start_loc: &SourceLocation, end_loc: &SourceLocation) -> Self {
        SourceLocation {
            input: start_loc.input.clone(),
            start: start_loc.start,
            end: end_loc.end,
        }
    }
}