Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "technique"
version = "0.3.4"
version = "0.3.5"
edition = "2021"
description = "A domain specific language for procedures."
authors = [ "Andrew Cowie" ]
Expand Down
209 changes: 0 additions & 209 deletions src/error/display.rs

This file was deleted.

6 changes: 0 additions & 6 deletions src/error/mod.rs

This file was deleted.

1 change: 1 addition & 0 deletions src/formatting/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ impl Formatter {
}
}


impl ToString for Formatter {
fn to_string(&self) -> String {
let mut result = String::new();
Expand Down
10 changes: 5 additions & 5 deletions src/formatting/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ pub enum Syntax {
/// Trait for different rendering backends (the no-op no-markup one, ANSI
/// escapes for terminal colouring, Typst markup for documents)
pub trait Render {
/// Render content with the specified type/style
fn render(&self, content_type: Syntax, content: &str) -> String;
/// Apply styling to content with the specified syntax type
fn style(&self, content_type: Syntax, content: &str) -> String;
}

/// Returns content unchanged, with no markup applied
pub struct Identity;

impl Render for Identity {
fn render(&self, _syntax: Syntax, content: &str) -> String {
fn style(&self, _syntax: Syntax, content: &str) -> String {
content.to_string()
}
}
Expand All @@ -68,12 +68,12 @@ fn format_to_fragments(technique: &Document, width: u8) -> Vec<(Syntax, String)>
crate::formatting::formatter::format_with_renderer(technique, width)
}

/// Pass 2: apply markup to fragments via render() and combine.
/// Pass 2: apply markup to fragments via style() and combine.
fn render_to_string(renderer: &impl Render, fragments: Vec<(Syntax, String)>) -> String {
let mut output = String::new();

for (syntax, content) in fragments {
let rendered = renderer.render(syntax, &content);
let rendered = renderer.style(syntax, &content);
output.push_str(&rendered);
}

Expand Down
15 changes: 15 additions & 0 deletions src/language/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::{fmt, path::Path};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LoadingError<'i> {
pub problem: String,
pub details: String,
pub filename: &'i Path,
}


impl<'i> fmt::Display for LoadingError<'i> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.problem, self.details)
}
}
2 changes: 2 additions & 0 deletions src/language/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Types representing the Technique procedures language

mod error;
mod quantity;
mod types;

// Re-export all public symbols
pub use error::*;
pub use quantity::*;
pub use types::*;
42 changes: 21 additions & 21 deletions src/language/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,6 @@ pub fn convert_superscript(input: &str) -> String {
.collect()
}

fn to_superscript(num: i8) -> String {
num.to_string()
.chars()
.map(|c| match c {
'0' => '⁰',
'1' => '¹',
'2' => '²',
'3' => '³',
'4' => '⁴',
'5' => '⁵',
'6' => '⁶',
'7' => '⁷',
'8' => '⁸',
'9' => '⁹',
'-' => '⁻',
_ => c,
})
.collect()
}

impl Display for Decimal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.precision == 0 {
Expand Down Expand Up @@ -230,8 +210,28 @@ impl<'i> Display for Quantity<'i> {
}
}

fn to_superscript(num: i8) -> String {
num.to_string()
.chars()
.map(|c| match c {
'0' => '⁰',
'1' => '¹',
'2' => '²',
'3' => '³',
'4' => '⁴',
'5' => '⁵',
'6' => '⁶',
'7' => '⁷',
'8' => '⁸',
'9' => '⁹',
'-' => '⁻',
_ => c,
})
.collect()
}

#[cfg(test)]
mod tests {
mod check {
use super::*;

#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod error;
pub mod formatting;
pub mod language;
pub mod parsing;
pub mod regex;
pub mod formatting;
Loading