Rename library to nomo
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
d691fb9198
commit
d2e0405033
28 changed files with 92 additions and 92 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use crate::ast::TemplateAstExpr;
|
||||
use crate::input::TempleInput;
|
||||
use crate::input::NomoInput;
|
||||
|
||||
pub struct EmitMachine {
|
||||
current_index: usize,
|
||||
|
|
@ -25,10 +25,10 @@ pub struct VariableSlot {
|
|||
#[derive(Debug)]
|
||||
pub enum Instruction {
|
||||
AppendContent {
|
||||
content: TempleInput,
|
||||
content: NomoInput,
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: TempleInput,
|
||||
name: NomoInput,
|
||||
slot: VariableSlot,
|
||||
},
|
||||
EmitFromSlot {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ use thiserror::Error;
|
|||
|
||||
use crate::Context;
|
||||
use crate::emit::Instruction;
|
||||
use crate::input::TempleInput;
|
||||
use crate::input::NomoInput;
|
||||
|
||||
#[derive(Debug, Error, Display)]
|
||||
pub enum EvaluationError {
|
||||
/// An unknown variable was encountered: .0
|
||||
UnknownVariable(TempleInput),
|
||||
UnknownVariable(NomoInput),
|
||||
/// An explicit abort was requested
|
||||
ExplicitAbort,
|
||||
}
|
||||
|
|
|
|||
50
src/input.rs
50
src/input.rs
|
|
@ -9,14 +9,14 @@ use winnow::stream::Stream;
|
|||
use winnow::stream::StreamIsPartial;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct TempleInput {
|
||||
pub struct NomoInput {
|
||||
backing: Arc<str>,
|
||||
range: Range<usize>,
|
||||
}
|
||||
|
||||
impl TempleInput {
|
||||
pub fn from_parts(backing: Arc<str>, range: Range<usize>) -> TempleInput {
|
||||
TempleInput { backing, range }
|
||||
impl NomoInput {
|
||||
pub fn from_parts(backing: Arc<str>, range: Range<usize>) -> NomoInput {
|
||||
NomoInput { backing, range }
|
||||
}
|
||||
|
||||
pub fn into_parts(self) -> (Arc<str>, Range<usize>) {
|
||||
|
|
@ -24,43 +24,43 @@ impl TempleInput {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for TempleInput {
|
||||
impl std::fmt::Debug for NomoInput {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\"{}\"", self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for TempleInput {
|
||||
impl From<String> for NomoInput {
|
||||
fn from(value: String) -> Self {
|
||||
let range = 0..value.len();
|
||||
let backing = Arc::from(value);
|
||||
|
||||
TempleInput { backing, range }
|
||||
NomoInput { backing, range }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for TempleInput {
|
||||
impl From<&str> for NomoInput {
|
||||
fn from(value: &str) -> Self {
|
||||
let backing = Arc::from(value.to_string());
|
||||
let range = 0..value.len();
|
||||
|
||||
TempleInput { backing, range }
|
||||
NomoInput { backing, range }
|
||||
}
|
||||
}
|
||||
|
||||
impl FindSlice<&str> for TempleInput {
|
||||
impl FindSlice<&str> for NomoInput {
|
||||
fn find_slice(&self, substr: &str) -> Option<core::ops::Range<usize>> {
|
||||
self.as_str().find_slice(substr)
|
||||
}
|
||||
}
|
||||
|
||||
impl Compare<&str> for TempleInput {
|
||||
impl Compare<&str> for NomoInput {
|
||||
fn compare(&self, t: &str) -> winnow::stream::CompareResult {
|
||||
self.as_str().compare(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for TempleInput {
|
||||
impl Deref for NomoInput {
|
||||
type Target = str;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
|
@ -68,24 +68,24 @@ impl Deref for TempleInput {
|
|||
}
|
||||
}
|
||||
|
||||
impl TempleInput {
|
||||
impl NomoInput {
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.deref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Offset for TempleInput {
|
||||
impl Offset for NomoInput {
|
||||
fn offset_from(&self, start: &Self) -> usize {
|
||||
self.as_str().offset_from(&start.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TempleInputIter {
|
||||
pub struct NomoInputIter {
|
||||
idx: usize,
|
||||
input: TempleInput,
|
||||
input: NomoInput,
|
||||
}
|
||||
|
||||
impl Iterator for TempleInputIter {
|
||||
impl Iterator for NomoInputIter {
|
||||
type Item = (usize, char);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
|
@ -95,7 +95,7 @@ impl Iterator for TempleInputIter {
|
|||
}
|
||||
}
|
||||
|
||||
impl StreamIsPartial for TempleInput {
|
||||
impl StreamIsPartial for NomoInput {
|
||||
type PartialState = ();
|
||||
|
||||
fn complete(&mut self) -> Self::PartialState {
|
||||
|
|
@ -109,17 +109,17 @@ impl StreamIsPartial for TempleInput {
|
|||
}
|
||||
}
|
||||
|
||||
impl Stream for TempleInput {
|
||||
impl Stream for NomoInput {
|
||||
type Token = char;
|
||||
|
||||
type Slice = TempleInput;
|
||||
type Slice = NomoInput;
|
||||
|
||||
type IterOffsets = TempleInputIter;
|
||||
type IterOffsets = NomoInputIter;
|
||||
|
||||
type Checkpoint = TempleInput;
|
||||
type Checkpoint = NomoInput;
|
||||
|
||||
fn iter_offsets(&self) -> Self::IterOffsets {
|
||||
TempleInputIter {
|
||||
NomoInputIter {
|
||||
idx: 0,
|
||||
input: self.clone(),
|
||||
}
|
||||
|
|
@ -187,11 +187,11 @@ impl Stream for TempleInput {
|
|||
mod tests {
|
||||
use winnow::stream::Stream;
|
||||
|
||||
use crate::input::TempleInput;
|
||||
use crate::input::NomoInput;
|
||||
|
||||
#[test]
|
||||
fn check_stream_impl() {
|
||||
let mut stream = TempleInput::from("checking");
|
||||
let mut stream = NomoInput::from("checking");
|
||||
|
||||
let checkpoint = stream.checkpoint();
|
||||
|
||||
|
|
|
|||
28
src/lib.rs
28
src/lib.rs
|
|
@ -6,7 +6,7 @@ use serde::Serialize;
|
|||
use thiserror::Error;
|
||||
|
||||
use crate::emit::Instruction;
|
||||
use crate::input::TempleInput;
|
||||
use crate::input::NomoInput;
|
||||
|
||||
pub mod ast;
|
||||
pub mod emit;
|
||||
|
|
@ -15,7 +15,7 @@ pub mod input;
|
|||
pub mod parser;
|
||||
|
||||
#[derive(Debug, Error, Display)]
|
||||
pub enum TempleError {
|
||||
pub enum NomoError {
|
||||
/// Could not parse the given template
|
||||
ParseError {
|
||||
#[from]
|
||||
|
|
@ -37,19 +37,19 @@ pub enum TempleError {
|
|||
UnknownTemplate(String),
|
||||
}
|
||||
|
||||
pub struct Temple {
|
||||
pub struct Nomo {
|
||||
templates: HashMap<String, Template>,
|
||||
}
|
||||
|
||||
impl Default for Temple {
|
||||
impl Default for Nomo {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Temple {
|
||||
pub fn new() -> Temple {
|
||||
Temple {
|
||||
impl Nomo {
|
||||
pub fn new() -> Nomo {
|
||||
Nomo {
|
||||
templates: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -57,8 +57,8 @@ impl Temple {
|
|||
pub fn add_template(
|
||||
&mut self,
|
||||
name: impl Into<String>,
|
||||
value: impl Into<TempleInput>,
|
||||
) -> Result<(), TempleError> {
|
||||
value: impl Into<NomoInput>,
|
||||
) -> Result<(), NomoError> {
|
||||
let source = value.into();
|
||||
let parse = parser::parse(source.clone())?;
|
||||
let ast = ast::parse(parse.tokens())?;
|
||||
|
|
@ -76,11 +76,11 @@ impl Temple {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render(&self, name: &str, ctx: &Context) -> Result<String, TempleError> {
|
||||
pub fn render(&self, name: &str, ctx: &Context) -> Result<String, NomoError> {
|
||||
let template = self
|
||||
.templates
|
||||
.get(name)
|
||||
.ok_or_else(|| TempleError::UnknownTemplate(name.to_string()))?;
|
||||
.ok_or_else(|| NomoError::UnknownTemplate(name.to_string()))?;
|
||||
|
||||
let res = eval::execute(&template.instructions, ctx)?;
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ impl Temple {
|
|||
}
|
||||
|
||||
struct Template {
|
||||
source: TempleInput,
|
||||
source: NomoInput,
|
||||
instructions: Vec<Instruction>,
|
||||
}
|
||||
|
||||
|
|
@ -186,11 +186,11 @@ where
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::Context;
|
||||
use crate::Temple;
|
||||
use crate::Nomo;
|
||||
|
||||
#[test]
|
||||
fn check_simple_template() {
|
||||
let mut temp = Temple::new();
|
||||
let mut temp = Nomo::new();
|
||||
|
||||
temp.add_template("base", "Hello {{= name }}").unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -33,10 +33,10 @@ use winnow::token::take_until;
|
|||
use winnow::token::take_while;
|
||||
|
||||
use crate::SourceSpan;
|
||||
use crate::input::TempleInput;
|
||||
use crate::input::NomoInput;
|
||||
use crate::resume_after_cut;
|
||||
|
||||
type Input<'input> = Recoverable<LocatingSlice<TempleInput>, ParseError>;
|
||||
type Input<'input> = Recoverable<LocatingSlice<NomoInput>, ParseError>;
|
||||
type PResult<'input, T> = Result<T, ParseError>;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
@ -52,7 +52,7 @@ impl std::fmt::Display for ParseFailure {
|
|||
}
|
||||
|
||||
impl ParseFailure {
|
||||
fn from_errors(errors: Vec<ParseError>, input: TempleInput) -> ParseFailure {
|
||||
fn from_errors(errors: Vec<ParseError>, input: NomoInput) -> ParseFailure {
|
||||
ParseFailure {
|
||||
input: Arc::from(input.to_string()),
|
||||
errors,
|
||||
|
|
@ -248,13 +248,13 @@ impl<const LEN: usize> winnow::stream::ContainsToken<&'_ TemplateToken> for [Tok
|
|||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TemplateToken {
|
||||
kind: TokenKind,
|
||||
source: TempleInput,
|
||||
source: NomoInput,
|
||||
}
|
||||
|
||||
macro_rules! impl_token_kind_builders {
|
||||
($($name:ident => $kind:expr),+ $(,)?) => {
|
||||
$(
|
||||
fn $name(source: TempleInput) -> Self {
|
||||
fn $name(source: NomoInput) -> Self {
|
||||
TemplateToken {
|
||||
kind: $kind,
|
||||
source,
|
||||
|
|
@ -277,7 +277,7 @@ impl TemplateToken {
|
|||
end => TokenKind::End,
|
||||
}
|
||||
|
||||
pub fn literal(literal: TokenLiteral, source: TempleInput) -> Self {
|
||||
pub fn literal(literal: TokenLiteral, source: NomoInput) -> Self {
|
||||
TemplateToken {
|
||||
kind: TokenKind::Literal(literal),
|
||||
source,
|
||||
|
|
@ -288,12 +288,12 @@ impl TemplateToken {
|
|||
self.kind
|
||||
}
|
||||
|
||||
pub fn source(&self) -> TempleInput {
|
||||
pub fn source(&self) -> NomoInput {
|
||||
self.source.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(input: TempleInput) -> Result<ParsedTemplate, ParseFailure> {
|
||||
pub fn parse(input: NomoInput) -> Result<ParsedTemplate, ParseFailure> {
|
||||
let (_remaining, val, errors) =
|
||||
parse_tokens.recoverable_parse(LocatingSlice::new(input.clone()));
|
||||
|
||||
|
|
@ -335,7 +335,7 @@ fn parse_interpolate<'input>(input: &mut Input<'input>) -> PResult<'input, Vec<T
|
|||
.resume_after(recover)
|
||||
.with_taken()
|
||||
.map(|(val, taken)| {
|
||||
val.unwrap_or_else(|| (vec![TemplateToken::invalid(taken)], TempleInput::from("")))
|
||||
val.unwrap_or_else(|| (vec![TemplateToken::invalid(taken)], NomoInput::from("")))
|
||||
})
|
||||
.parse_next(input)?;
|
||||
|
||||
|
|
@ -419,7 +419,7 @@ fn parse_ident<'input>(input: &mut Input<'input>) -> PResult<'input, TemplateTok
|
|||
.parse_next(input)
|
||||
}
|
||||
|
||||
fn ident<'input>(input: &mut Input<'input>) -> PResult<'input, TempleInput> {
|
||||
fn ident<'input>(input: &mut Input<'input>) -> PResult<'input, NomoInput> {
|
||||
peek(not(parse_literal))
|
||||
.context(ParseError::ctx().msg("Expected an ident, but found a literal instead"))
|
||||
.parse_next(input)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue