Add flag for model printing

This commit is contained in:
Laurenz 2022-11-20 20:57:40 +01:00
parent f69c3fb1e5
commit 72361106bc
2 changed files with 15 additions and 24 deletions

View File

@ -144,7 +144,7 @@ impl<const L: ListKind> LayoutBlock for ListNode<L> {
} }
/// An item in a list. /// An item in a list.
#[derive(Clone, PartialEq, Hash)] #[derive(Debug, Clone, Hash)]
pub enum ListItem { pub enum ListItem {
/// An item of an unordered list. /// An item of an unordered list.
List(Box<Content>), List(Box<Content>),
@ -183,24 +183,11 @@ impl ListItem {
} }
} }
impl Debug for ListItem {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::List(body) => write!(f, "- {body:?}"),
Self::Enum(number, body) => match number {
Some(n) => write!(f, "{n}. {body:?}"),
None => write!(f, "+ {body:?}"),
},
Self::Desc(item) => item.fmt(f),
}
}
}
#[node] #[node]
impl ListItem {} impl ListItem {}
/// A description list item. /// A description list item.
#[derive(Clone, PartialEq, Hash)] #[derive(Debug, Clone, Hash)]
pub struct DescItem { pub struct DescItem {
/// The term described by the list item. /// The term described by the list item.
pub term: Content, pub term: Content,
@ -218,12 +205,6 @@ castable! {
}, },
} }
impl Debug for DescItem {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "/ {:?}: {:?}", self.term, self.body)
}
}
/// How to label a list. /// How to label a list.
pub type ListKind = usize; pub type ListKind = usize;

View File

@ -7,7 +7,7 @@ use std::io::Read;
use std::ops::Range; use std::ops::Range;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use comemo::Prehashed; use comemo::{Prehashed, Track};
use elsa::FrozenVec; use elsa::FrozenVec;
use once_cell::unsync::OnceCell; use once_cell::unsync::OnceCell;
use tiny_skia as sk; use tiny_skia as sk;
@ -100,6 +100,7 @@ struct Args {
#[derive(Default, Copy, Clone, Eq, PartialEq)] #[derive(Default, Copy, Clone, Eq, PartialEq)]
struct PrintConfig { struct PrintConfig {
syntax: bool, syntax: bool,
model: bool,
frames: bool, frames: bool,
} }
@ -120,6 +121,8 @@ impl Args {
"--pdf" => pdf = true, "--pdf" => pdf = true,
// Debug print the syntax trees. // Debug print the syntax trees.
"--syntax" => print.syntax = true, "--syntax" => print.syntax = true,
// Debug print the model.
"--model" => print.model = true,
// Debug print the frames. // Debug print the frames.
"--frames" => print.frames = true, "--frames" => print.frames = true,
// Everything else is a file filter. // Everything else is a file filter.
@ -355,7 +358,7 @@ fn test(
if world.print.frames { if world.print.frames {
for frame in &frames { for frame in &frames {
println!("Frame: {:#?}", frame); println!("Frame:\n{:#?}\n", frame);
} }
} }
@ -405,7 +408,7 @@ fn test_part(
let id = world.set(src_path, text); let id = world.set(src_path, text);
let source = world.source(id); let source = world.source(id);
if world.print.syntax { if world.print.syntax {
println!("Syntax Tree: {:#?}", source.root()) println!("Syntax Tree:\n{:#?}\n", source.root())
} }
let (local_compare_ref, mut ref_errors) = parse_metadata(&source); let (local_compare_ref, mut ref_errors) = parse_metadata(&source);
@ -414,6 +417,13 @@ fn test_part(
ok &= test_spans(source.root()); ok &= test_spans(source.root());
ok &= test_reparse(world.source(id).text(), i, rng); ok &= test_reparse(world.source(id).text(), i, rng);
if world.print.model {
let tracked = (world as &dyn World).track();
let route = typst::model::Route::default();
let module = typst::model::eval(tracked, route.track(), id).unwrap();
println!("Model:\n{:#?}\n", module.content);
}
let (mut frames, errors) = match typst::typeset(world, id) { let (mut frames, errors) = match typst::typeset(world, id) {
Ok(frames) => (frames, vec![]), Ok(frames) => (frames, vec![]),
Err(errors) => (vec![], *errors), Err(errors) => (vec![], *errors),