Formatting 🛀

This commit is contained in:
Laurenz 2020-01-06 12:50:20 +01:00
parent 2ee5810fec
commit a93b1ab003
22 changed files with 27 additions and 19 deletions

View File

@ -1,13 +1,13 @@
use std::fs::{File, read_to_string}; use std::fs::{File, read_to_string};
use std::io::BufWriter; use std::io::BufWriter;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use futures_executor::block_on; use futures_executor::block_on;
use typstc::Typesetter; use typstc::Typesetter;
use typstc::toddle::query::FileSystemFontProvider; use typstc::toddle::query::FileSystemFontProvider;
use typstc::export::pdf::PdfExporter; use typstc::export::pdf::PdfExporter;
fn main() { fn main() {
if let Err(err) = run() { if let Err(err) = run() {
eprintln!("error: {}", err); eprintln!("error: {}", err);

View File

@ -22,6 +22,7 @@ use toddle::tables::{
use crate::layout::{MultiLayout, Layout, LayoutAction}; use crate::layout::{MultiLayout, Layout, LayoutAction};
use crate::size::Size; use crate::size::Size;
/// Exports layouts into _PDFs_. /// Exports layouts into _PDFs_.
pub struct PdfExporter {} pub struct PdfExporter {}

View File

@ -1,5 +1,6 @@
//! Helper types and macros for creating custom functions. //! Helper types and macros for creating custom functions.
/// Defines function types concisely. /// Defines function types concisely.
#[macro_export] #[macro_export]
macro_rules! function { macro_rules! function {
@ -121,6 +122,7 @@ macro_rules! function {
'life1: 'async_trait, 'life1: 'async_trait,
Self: 'async_trait, Self: 'async_trait,
{ {
#[allow(unreachable_code)]
Box::pin(async move { Ok($code) }) Box::pin(async move { Ok($code) })
} }
} }

View File

@ -3,8 +3,8 @@
use std::any::Any; use std::any::Any;
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::{self, Debug, Formatter}; use std::fmt::{self, Debug, Formatter};
use async_trait::async_trait; use async_trait::async_trait;
use self::prelude::*; use self::prelude::*;
#[macro_use] #[macro_use]

View File

@ -6,6 +6,7 @@ use toddle::query::FontIndex;
use super::*; use super::*;
use LayoutAction::*; use LayoutAction::*;
/// A layouting action. /// A layouting action.
#[derive(Clone)] #[derive(Clone)]
pub enum LayoutAction { pub enum LayoutAction {

View File

@ -1,5 +1,6 @@
use super::*; use super::*;
/// The line layouter arranges boxes next to each other along a primary axis /// The line layouter arranges boxes next to each other along a primary axis
/// and arranges the resulting lines using an underlying stack layouter. /// and arranges the resulting lines using an underlying stack layouter.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -181,7 +182,7 @@ impl LineLayouter {
/// Finish the run and add secondary spacing to the underlying stack. /// Finish the run and add secondary spacing to the underlying stack.
pub fn add_secondary_spacing( pub fn add_secondary_spacing(
&mut self, &mut self,
mut spacing: Size, spacing: Size,
kind: SpacingKind kind: SpacingKind
) -> LayoutResult<()> { ) -> LayoutResult<()> {
self.finish_line_if_not_empty()?; self.finish_line_if_not_empty()?;

View File

@ -39,6 +39,7 @@ pub use self::actions::{LayoutAction, LayoutActions};
pub use self::layouters::*; pub use self::layouters::*;
pub use self::prelude::*; pub use self::prelude::*;
/// The result type for layouting. /// The result type for layouting.
pub type LayoutResult<T> = crate::TypesetResult<T>; pub type LayoutResult<T> = crate::TypesetResult<T>;

View File

@ -2,6 +2,7 @@ use smallvec::smallvec;
use crate::size::ValueBox; use crate::size::ValueBox;
use super::*; use super::*;
/// The stack layouter stack boxes onto each other along the secondary layouting /// The stack layouter stack boxes onto each other along the secondary layouting
/// axis. /// axis.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -5,6 +5,7 @@ use crate::size::{Size, Size2D};
use crate::style::TextStyle; use crate::style::TextStyle;
use super::*; use super::*;
/// The context for text layouting. /// The context for text layouting.
/// ///
/// See [`LayoutContext`] for details about the fields. /// See [`LayoutContext`] for details about the fields.

View File

@ -4,7 +4,6 @@ use smallvec::smallvec;
use crate::func::Command; use crate::func::Command;
use crate::syntax::{SyntaxTree, Node, FuncCall}; use crate::syntax::{SyntaxTree, Node, FuncCall};
use crate::style::TextStyle;
use super::*; use super::*;
@ -148,7 +147,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> {
} }
SetAlignment(alignment) => self.ctx.alignment = alignment, SetAlignment(alignment) => self.ctx.alignment = alignment,
SetAxes(axes) => { SetAxes(axes) => {
self.layouter.set_axes(axes); self.layouter.set_axes(axes)?;
self.ctx.axes = axes; self.ctx.axes = axes;
} }
} }

View File

@ -16,7 +16,7 @@
//! format is _PDF_. Alternatively, the layout can be serialized to pass it to //! format is _PDF_. Alternatively, the layout can be serialized to pass it to
//! a suitable renderer. //! a suitable renderer.
#![allow(unused)] // #![allow(unused)]
pub extern crate toddle; pub extern crate toddle;
@ -42,6 +42,7 @@ pub mod syntax;
pub mod size; pub mod size;
pub mod style; pub mod style;
/// Transforms source code into typesetted layouts. /// Transforms source code into typesetted layouts.
/// ///
/// A typesetter can be configured through various methods. /// A typesetter can be configured through various methods.

View File

@ -1,6 +1,7 @@
use super::*; use super::*;
use AlignmentKey::*; use AlignmentKey::*;
/// An argument key which describes a target alignment. /// An argument key which describes a target alignment.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum AlignmentKey { pub enum AlignmentKey {

View File

@ -1,6 +1,7 @@
use super::*; use super::*;
use AxisKey::*; use AxisKey::*;
/// An argument key which identifies a layouting axis. /// An argument key which identifies a layouting axis.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum AxisKey { pub enum AxisKey {

View File

@ -5,6 +5,7 @@ use std::hash::Hash;
use crate::func::prelude::*; use crate::func::prelude::*;
macro_rules! key { macro_rules! key {
($type:ty, $name:expr, $($patterns:tt)*) => { ($type:ty, $name:expr, $($patterns:tt)*) => {
impl $type { impl $type {

View File

@ -3,6 +3,7 @@ use AxisKey::*;
use AlignmentKey::*; use AlignmentKey::*;
use PaddingKey::*; use PaddingKey::*;
/// An argument key which identifies a margin or padding target. /// An argument key which identifies a margin or padding target.
/// ///
/// A is the used axis type. /// A is the used axis type.

View File

@ -58,7 +58,7 @@ function! {
list: Vec<String>, list: Vec<String>,
} }
parse(args, body, ctx, meta) { parse(args, body, ctx) {
FontFamilyFunc { FontFamilyFunc {
body: parse!(optional: body, ctx), body: parse!(optional: body, ctx),
list: { list: {
@ -114,7 +114,7 @@ function! {
weight: FontWeight, weight: FontWeight,
} }
parse(args, body, ctx, meta) { parse(args, body, ctx) {
FontWeightFunc { FontWeightFunc {
body: parse!(optional: body, ctx), body: parse!(optional: body, ctx),
weight: match args.get_pos::<Expression>()? { weight: match args.get_pos::<Expression>()? {
@ -195,7 +195,7 @@ function! {
} }
} }
layout(self, mut ctx) { layout(self, ctx) {
let mut style = ctx.style.text.clone(); let mut style = ctx.style.text.clone();
match self.content { match self.content {
ContentKind::Word => style.word_spacing_scale = self.spacing, ContentKind::Word => style.word_spacing_scale = self.spacing,

View File

@ -1,5 +1,6 @@
//! Auxiliary macros. //! Auxiliary macros.
/// Create trait implementations for an error type. /// Create trait implementations for an error type.
macro_rules! error_type { macro_rules! error_type {
( (
@ -36,16 +37,6 @@ macro_rules! error_type {
}; };
} }
/// Shorthand for checking whether an expression matches a pattern.
macro_rules! matches {
($expr:expr, $($pattern:tt)*) => {
match $expr {
$($pattern)* => true,
_ => false,
}
};
}
/// Create a `Debug` implementation from a `Display` implementation. /// Create a `Debug` implementation from a `Display` implementation.
macro_rules! debug_display { macro_rules! debug_display {
($type:ident) => ( ($type:ident) => (

View File

@ -7,6 +7,7 @@ use std::str::FromStr;
use crate::layout::prelude::*; use crate::layout::prelude::*;
/// A general spacing type. /// A general spacing type.
#[derive(Default, Copy, Clone, PartialEq, PartialOrd)] #[derive(Default, Copy, Clone, PartialEq, PartialOrd)]
pub struct Size { pub struct Size {

View File

@ -10,6 +10,7 @@ pub_use_mod!(tokens);
pub_use_mod!(parsing); pub_use_mod!(parsing);
pub_use_mod!(span); pub_use_mod!(span);
/// A logical unit of the incoming text stream. /// A logical unit of the incoming text stream.
#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Token<'s> { pub enum Token<'s> {

View File

@ -4,6 +4,7 @@ use crate::func::Scope;
use crate::size::Size; use crate::size::Size;
use super::*; use super::*;
/// The result type for parsing. /// The result type for parsing.
pub type ParseResult<T> = crate::TypesetResult<T>; pub type ParseResult<T> = crate::TypesetResult<T>;

View File

@ -2,6 +2,7 @@
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
/// Annotates a value with the part of the source code it corresponds to. /// Annotates a value with the part of the source code it corresponds to.
#[derive(Copy, Clone, Eq, PartialEq)] #[derive(Copy, Clone, Eq, PartialEq)]
pub struct Spanned<T> { pub struct Spanned<T> {

View File

@ -5,6 +5,7 @@ use smallvec::SmallVec;
use super::*; use super::*;
/// Builds an iterator over the tokens of the source code. /// Builds an iterator over the tokens of the source code.
pub fn tokenize(src: &str) -> Tokens { pub fn tokenize(src: &str) -> Tokens {
Tokens::new(src) Tokens::new(src)