Preparation for sharing

- rustfmt
- clippy
- comments
- README
This commit is contained in:
2023-05-25 19:14:24 +01:00
parent e99ade92ba
commit bc2714aad8
144 changed files with 3734 additions and 3243 deletions

View File

@@ -3,46 +3,53 @@ use std::rc::Rc;
use crate::interner::Interner;
/// Trait enclosing all context features
///
///
/// Hiding type parameters in associated types allows for simpler
/// parser definitions
pub trait Context: Clone {
type Op: AsRef<str>;
fn ops<'a>(&'a self) -> &'a [Self::Op];
fn ops(&self) -> &[Self::Op];
fn file(&self) -> Rc<Vec<String>>;
fn interner<'a>(&'a self) -> &'a Interner;
fn interner(&self) -> &Interner;
}
/// Struct implementing context
///
///
/// Hiding type parameters in associated types allows for simpler
/// parser definitions
pub struct ParsingContext<'a, Op> {
pub ops: &'a [Op],
pub interner: &'a Interner,
pub file: Rc<Vec<String>>
pub file: Rc<Vec<String>>,
}
impl<'a, Op> ParsingContext<'a, Op> {
pub fn new(ops: &'a [Op], interner: &'a Interner, file: Rc<Vec<String>>)
-> Self { Self { ops, interner, file } }
pub fn new(
ops: &'a [Op],
interner: &'a Interner,
file: Rc<Vec<String>>,
) -> Self {
Self { ops, interner, file }
}
}
impl<'a, Op> Clone for ParsingContext<'a, Op> {
fn clone(&self) -> Self {
Self {
ops: self.ops,
interner: self.interner,
file: self.file.clone()
}
Self { ops: self.ops, interner: self.interner, file: self.file.clone() }
}
}
impl<Op: AsRef<str>> Context for ParsingContext<'_, Op> {
type Op = Op;
fn interner<'a>(&'a self) -> &'a Interner { self.interner }
fn file(&self) -> Rc<Vec<String>> {self.file.clone()}
fn ops<'a>(&'a self) -> &'a [Self::Op] { self.ops }
}
fn interner(&self) -> &Interner {
self.interner
}
fn file(&self) -> Rc<Vec<String>> {
self.file.clone()
}
fn ops(&self) -> &[Self::Op] {
self.ops
}
}