From ab841188e3d2687ee8f436336e6fde337985a83e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 1 Mar 2023 11:27:10 +0100 Subject: [PATCH] Bump `ecow` --- Cargo.lock | 3 ++- Cargo.toml | 2 +- library/Cargo.toml | 2 +- library/src/meta/numbering.rs | 2 +- library/src/meta/outline.rs | 2 +- library/src/meta/reference.rs | 2 +- library/src/prelude.rs | 2 +- src/diag.rs | 6 +++--- src/export/pdf/font.rs | 4 ++-- src/export/pdf/page.rs | 10 +++++----- src/ide/complete.rs | 16 ++++++++-------- src/model/array.rs | 8 ++++---- src/model/dict.rs | 8 ++++---- src/model/module.rs | 4 ++-- src/model/ops.rs | 6 +++--- src/model/str.rs | 10 +++++----- src/model/value.rs | 12 ++++++------ src/syntax/lexer.rs | 6 +++--- src/syntax/parser.rs | 14 +++++++------- 19 files changed, 60 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7306cdd1f..5a0784eee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -307,7 +307,8 @@ dependencies = [ [[package]] name = "ecow" version = "0.1.0" -source = "git+https://github.com/typst/ecow#36b624de42f12f90ebad3e0498d770e1700f2e90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e60e2840fbfc397c7972b11a6e6bd99a0248921cc1e31f293c5f6c5ac24831da" [[package]] name = "elsa" diff --git a/Cargo.toml b/Cargo.toml index bf5b772b9..9f693e836 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ typst-macros = { path = "macros" } bitflags = "1" bytemuck = "1" comemo = { git = "https://github.com/typst/comemo" } -ecow = { git = "https://github.com/typst/ecow" } +ecow = "0.1" flate2 = "1" if_chain = "1" image = { version = "0.24", default-features = false, features = ["png", "jpeg", "gif"] } diff --git a/library/Cargo.toml b/library/Cargo.toml index d725a3936..b532883be 100644 --- a/library/Cargo.toml +++ b/library/Cargo.toml @@ -13,7 +13,7 @@ bench = false typst = { path = ".." } comemo = { git = "https://github.com/typst/comemo" } csv = "1" -ecow = { git = "https://github.com/typst/ecow" } +ecow = "0.1" hypher = "0.1" kurbo = "0.8" lipsum = { git = "https://github.com/reknih/lipsum" } diff --git a/library/src/meta/numbering.rs b/library/src/meta/numbering.rs index c187c18db..5b7cd92b8 100644 --- a/library/src/meta/numbering.rs +++ b/library/src/meta/numbering.rs @@ -211,7 +211,7 @@ impl NumberingKind { let mut n = n.get(); match self { Self::Arabic => { - format_eco!("{n}") + eco_format!("{n}") } Self::Letter => { n -= 1; diff --git a/library/src/meta/outline.rs b/library/src/meta/outline.rs index 2d1cf185e..d9eea0a90 100644 --- a/library/src/meta/outline.rs +++ b/library/src/meta/outline.rs @@ -194,7 +194,7 @@ impl Show for OutlineNode { } // Add the page number and linebreak. - let end = TextNode::packed(format_eco!("{}", loc.page)); + let end = TextNode::packed(eco_format!("{}", loc.page)); seq.push(end.linked(Destination::Internal(loc))); seq.push(LinebreakNode { justify: false }.pack()); diff --git a/library/src/meta/reference.rs b/library/src/meta/reference.rs index 465a20ade..e64751f74 100644 --- a/library/src/meta/reference.rs +++ b/library/src/meta/reference.rs @@ -43,6 +43,6 @@ impl RefNode { impl Show for RefNode { fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult { - Ok(TextNode::packed(format_eco!("@{}", self.0))) + Ok(TextNode::packed(eco_format!("@{}", self.0))) } } diff --git a/library/src/prelude.rs b/library/src/prelude.rs index c8f6fe97c..22458a553 100644 --- a/library/src/prelude.rs +++ b/library/src/prelude.rs @@ -8,7 +8,7 @@ pub use std::num::NonZeroUsize; #[doc(no_inline)] pub use comemo::{Track, Tracked, TrackedMut}; #[doc(no_inline)] -pub use ecow::{format_eco, EcoString}; +pub use ecow::{eco_format, EcoString}; #[doc(no_inline)] pub use typst::diag::{bail, error, At, SourceResult, StrResult}; #[doc(no_inline)] diff --git a/src/diag.rs b/src/diag.rs index 2742a8724..eca6827c6 100644 --- a/src/diag.rs +++ b/src/diag.rs @@ -38,14 +38,14 @@ macro_rules! __error { }; ($span:expr, $fmt:expr, $($arg:expr),+ $(,)?) => { - $crate::diag::error!($span, $crate::diag::format_eco!($fmt, $($arg),+)) + $crate::diag::error!($span, $crate::diag::eco_format!($fmt, $($arg),+)) }; } #[doc(inline)] pub use crate::__error as error; #[doc(hidden)] -pub use ecow::format_eco; +pub use ecow::eco_format; /// A result that can carry multiple source errors. pub type SourceResult = Result>>; @@ -268,7 +268,7 @@ impl From for FileError { impl From for EcoString { fn from(error: FileError) -> Self { - format_eco!("{error}") + eco_format!("{error}") } } diff --git a/src/export/pdf/font.rs b/src/export/pdf/font.rs index 533911056..60e7f0bb2 100644 --- a/src/export/pdf/font.rs +++ b/src/export/pdf/font.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use ecow::format_eco; +use ecow::eco_format; use pdf_writer::types::{CidFontType, FontFlags, SystemInfo, UnicodeCmap}; use pdf_writer::{Filter, Finish, Name, Rect, Str}; use ttf_parser::{name_id, GlyphId, Tag}; @@ -26,7 +26,7 @@ pub fn write_fonts(ctx: &mut PdfContext) { .find_name(name_id::POST_SCRIPT_NAME) .unwrap_or_else(|| "unknown".to_string()); - let base_font = format_eco!("ABCDEF+{}", postscript_name); + let base_font = eco_format!("ABCDEF+{}", postscript_name); let base_font = Name(base_font.as_bytes()); let cmap_name = Name(b"Custom"); let system_info = SystemInfo { diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs index 7daf9d5ed..35cb6441c 100644 --- a/src/export/pdf/page.rs +++ b/src/export/pdf/page.rs @@ -1,4 +1,4 @@ -use ecow::format_eco; +use ecow::eco_format; use pdf_writer::types::{ActionType, AnnotationType, ColorSpaceOperand}; use pdf_writer::writers::ColorSpace; use pdf_writer::{Content, Filter, Finish, Name, Rect, Ref, Str}; @@ -80,7 +80,7 @@ pub fn write_page_tree(ctx: &mut PdfContext) { let mut fonts = resources.fonts(); for (font_ref, f) in ctx.font_map.pdf_indices(&ctx.font_refs) { - let name = format_eco!("F{}", f); + let name = eco_format!("F{}", f); fonts.pair(Name(name.as_bytes()), font_ref); } @@ -88,7 +88,7 @@ pub fn write_page_tree(ctx: &mut PdfContext) { let mut images = resources.x_objects(); for (image_ref, im) in ctx.image_map.pdf_indices(&ctx.image_refs) { - let name = format_eco!("Im{}", im); + let name = eco_format!("Im{}", im); images.pair(Name(name.as_bytes()), image_ref); } @@ -201,7 +201,7 @@ impl PageContext<'_, '_> { fn set_font(&mut self, font: &Font, size: Abs) { if self.state.font.as_ref().map(|(f, s)| (f, *s)) != Some((font, size)) { self.parent.font_map.insert(font.clone()); - let name = format_eco!("F{}", self.parent.font_map.map(font.clone())); + let name = eco_format!("F{}", self.parent.font_map.map(font.clone())); self.content.set_font(Name(name.as_bytes()), size.to_f32()); self.state.font = Some((font.clone(), size)); } @@ -439,7 +439,7 @@ fn write_path(ctx: &mut PageContext, x: f32, y: f32, path: &geom::Path) { /// Encode a vector or raster image into the content stream. fn write_image(ctx: &mut PageContext, x: f32, y: f32, image: &Image, size: Size) { ctx.parent.image_map.insert(image.clone()); - let name = format_eco!("Im{}", ctx.parent.image_map.map(image.clone())); + let name = eco_format!("Im{}", ctx.parent.image_map.map(image.clone())); let w = size.x.to_f32(); let h = size.y.to_f32(); ctx.content.save_state(); diff --git a/src/ide/complete.rs b/src/ide/complete.rs index 97427130e..fe1afe66b 100644 --- a/src/ide/complete.rs +++ b/src/ide/complete.rs @@ -1,6 +1,6 @@ use std::collections::{BTreeSet, HashSet}; -use ecow::{format_eco, EcoString}; +use ecow::{eco_format, EcoString}; use if_chain::if_chain; use super::{analyze_expr, analyze_import, plain_docs_sentence, summarize_font_family}; @@ -317,9 +317,9 @@ fn field_access_completions(ctx: &mut CompletionContext, value: &Value) { kind: CompletionKind::Func, label: method.into(), apply: Some(if args { - format_eco!("{method}(${{}})") + eco_format!("{method}(${{}})") } else { - format_eco!("{method}()${{}}") + eco_format!("{method}()${{}}") }), detail: None, }) @@ -612,7 +612,7 @@ fn param_completions( ctx.completions.push(Completion { kind: CompletionKind::Param, label: param.name.into(), - apply: Some(format_eco!("{}: ${{}}", param.name)), + apply: Some(eco_format!("{}: ${{}}", param.name)), detail: Some(plain_docs_sentence(param.docs).into()), }); } @@ -872,7 +872,7 @@ impl<'a> CompletionContext<'a> { fn enrich(&mut self, prefix: &str, suffix: &str) { for Completion { label, apply, .. } in &mut self.completions { let current = apply.as_ref().unwrap_or(label); - *apply = Some(format_eco!("{prefix}{current}{suffix}")); + *apply = Some(eco_format!("{prefix}{current}{suffix}")); } } @@ -934,7 +934,7 @@ impl<'a> CompletionContext<'a> { }); if parens && matches!(value, Value::Func(_)) { - apply = Some(format_eco!("{label}(${{}})")); + apply = Some(eco_format!("{label}(${{}})")); } self.completions.push(Completion { @@ -998,8 +998,8 @@ impl<'a> CompletionContext<'a> { self.completions.push(Completion { kind: CompletionKind::Syntax, label: (*ty).into(), - apply: Some(format_eco!("${{{ty}}}")), - detail: Some(format_eco!("A value of type {ty}.")), + apply: Some(eco_format!("${{{ty}}}")), + detail: Some(eco_format!("A value of type {ty}.")), }); self.scope_completions(false, |value| value.type_name() == *ty); } diff --git a/src/model/array.rs b/src/model/array.rs index 0a84072d1..746763ab2 100644 --- a/src/model/array.rs +++ b/src/model/array.rs @@ -2,7 +2,7 @@ use std::cmp::Ordering; use std::fmt::{self, Debug, Formatter, Write}; use std::ops::{Add, AddAssign}; -use ecow::{format_eco, EcoString, EcoVec}; +use ecow::{eco_format, EcoString, EcoVec}; use super::{ops, Args, Func, Value, Vm}; use crate::diag::{bail, At, SourceResult, StrResult}; @@ -293,7 +293,7 @@ impl Array { vec.make_mut().sort_by(|a, b| { a.partial_cmp(b).unwrap_or_else(|| { if result.is_ok() { - result = Err(format_eco!( + result = Err(eco_format!( "cannot order {} and {}", a.type_name(), b.type_name(), @@ -335,7 +335,7 @@ impl Array { /// The out of bounds access error message. #[cold] fn out_of_bounds(index: i64, len: i64) -> EcoString { - format_eco!("array index out of bounds (index: {}, len: {})", index, len) + eco_format!("array index out of bounds (index: {}, len: {})", index, len) } /// The error message when the array is empty. @@ -389,7 +389,7 @@ impl FromIterator for Array { impl IntoIterator for Array { type Item = Value; - type IntoIter = ecow::IntoIter; + type IntoIter = ecow::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { self.0.into_iter() diff --git a/src/model/dict.rs b/src/model/dict.rs index b6198b2c9..50a2275f5 100644 --- a/src/model/dict.rs +++ b/src/model/dict.rs @@ -3,7 +3,7 @@ use std::fmt::{self, Debug, Formatter, Write}; use std::ops::{Add, AddAssign}; use std::sync::Arc; -use ecow::{format_eco, EcoString}; +use ecow::{eco_format, EcoString}; use super::{array, Array, Str, Value}; use crate::diag::StrResult; @@ -66,7 +66,7 @@ impl Dict { pub fn take(&mut self, key: &str) -> StrResult { Arc::make_mut(&mut self.0) .remove(key) - .ok_or_else(|| format_eco!("missing key: {:?}", Str::from(key))) + .ok_or_else(|| eco_format!("missing key: {:?}", Str::from(key))) } /// Whether the dictionary contains a specific key. @@ -123,7 +123,7 @@ impl Dict { /// Return an "unexpected key" error if there is any remaining pair. pub fn finish(&self, expected: &[&str]) -> StrResult<()> { if let Some((key, _)) = self.iter().next() { - let parts: Vec<_> = expected.iter().map(|s| format_eco!("\"{s}\"")).collect(); + let parts: Vec<_> = expected.iter().map(|s| eco_format!("\"{s}\"")).collect(); let mut msg = format!("unexpected key {key:?}, valid keys are "); crate::diag::comma_list(&mut msg, &parts, "and"); return Err(msg.into()); @@ -135,7 +135,7 @@ impl Dict { /// The missing key access error message. #[cold] fn missing_key(key: &str) -> EcoString { - format_eco!("dictionary does not contain key {:?}", Str::from(key)) + eco_format!("dictionary does not contain key {:?}", Str::from(key)) } impl Debug for Dict { diff --git a/src/model/module.rs b/src/model/module.rs index 97c060e3d..e911d8592 100644 --- a/src/model/module.rs +++ b/src/model/module.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Debug, Formatter}; use std::sync::Arc; -use ecow::{format_eco, EcoString}; +use ecow::{eco_format, EcoString}; use super::{Content, Scope, Value}; use crate::diag::StrResult; @@ -61,7 +61,7 @@ impl Module { /// Try to access a definition in the module. pub fn get(&self, name: &str) -> StrResult<&Value> { self.scope().get(&name).ok_or_else(|| { - format_eco!("module `{}` does not contain `{name}`", self.name()) + eco_format!("module `{}` does not contain `{name}`", self.name()) }) } diff --git a/src/model/ops.rs b/src/model/ops.rs index be7892f97..52b9b06a3 100644 --- a/src/model/ops.rs +++ b/src/model/ops.rs @@ -2,7 +2,7 @@ use std::cmp::Ordering; -use ecow::format_eco; +use ecow::eco_format; use super::{format_str, Regex, Value}; use crate::diag::StrResult; @@ -12,7 +12,7 @@ use Value::*; /// Bail with a type mismatch error. macro_rules! mismatch { ($fmt:expr, $($value:expr),* $(,)?) => { - return Err(format_eco!($fmt, $($value.type_name()),*)) + return Err(eco_format!($fmt, $($value.type_name()),*)) }; } @@ -117,7 +117,7 @@ pub fn add(lhs: Value, rhs: Value) -> StrResult { (a.downcast::(), b.downcast::()) { if a.axis() == b.axis() { - return Err(format_eco!("cannot add two {:?} alignments", a.axis())); + return Err(eco_format!("cannot add two {:?} alignments", a.axis())); } return Ok(Value::dynamic(match a.axis() { diff --git a/src/model/str.rs b/src/model/str.rs index 3eee95065..5fcc1d059 100644 --- a/src/model/str.rs +++ b/src/model/str.rs @@ -15,14 +15,14 @@ use crate::geom::GenAlign; #[doc(hidden)] macro_rules! __format_str { ($($tts:tt)*) => {{ - $crate::model::Str::from($crate::model::format_eco!($($tts)*)) + $crate::model::Str::from($crate::model::eco_format!($($tts)*)) }}; } #[doc(inline)] pub use crate::__format_str as format_str; #[doc(hidden)] -pub use ecow::format_eco; +pub use ecow::eco_format; /// An immutable reference counted string. #[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] @@ -297,13 +297,13 @@ impl Str { /// The out of bounds access error message. #[cold] fn out_of_bounds(index: i64, len: i64) -> EcoString { - format_eco!("string index out of bounds (index: {}, len: {})", index, len) + eco_format!("string index out of bounds (index: {}, len: {})", index, len) } /// The char boundary access error message. #[cold] fn not_a_char_boundary(index: i64) -> EcoString { - format_eco!("string index {} is not a character boundary", index) + eco_format!("string index {} is not a character boundary", index) } /// The error message when the string is empty. @@ -449,7 +449,7 @@ pub struct Regex(regex::Regex); impl Regex { /// Create a new regular expression. pub fn new(re: &str) -> StrResult { - regex::Regex::new(re).map(Self).map_err(|err| format_eco!("{err}")) + regex::Regex::new(re).map(Self).map_err(|err| eco_format!("{err}")) } } diff --git a/src/model/value.rs b/src/model/value.rs index 5c0ab618b..f6ab95de2 100644 --- a/src/model/value.rs +++ b/src/model/value.rs @@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Formatter}; use std::hash::{Hash, Hasher}; use std::sync::Arc; -use ecow::{format_eco, EcoString}; +use ecow::{eco_format, EcoString}; use siphasher::sip128::{Hasher128, SipHasher}; use super::{ @@ -122,9 +122,9 @@ impl Value { Self::Dict(dict) => dict.at(&field).cloned(), Self::Content(content) => content .field(&field) - .ok_or_else(|| format_eco!("unknown field `{field}`")), + .ok_or_else(|| eco_format!("unknown field `{field}`")), Self::Module(module) => module.get(&field).cloned(), - v => Err(format_eco!("cannot access fields on type {}", v.type_name())), + v => Err(eco_format!("cannot access fields on type {}", v.type_name())), } } @@ -146,8 +146,8 @@ impl Value { pub fn display(self) -> Content { match self { Self::None => Content::empty(), - Self::Int(v) => item!(text)(format_eco!("{}", v)), - Self::Float(v) => item!(text)(format_eco!("{}", v)), + Self::Int(v) => item!(text)(eco_format!("{}", v)), + Self::Float(v) => item!(text)(eco_format!("{}", v)), Self::Str(v) => item!(text)(v.into()), Self::Symbol(v) => item!(text)(v.get().into()), Self::Content(v) => v, @@ -402,7 +402,7 @@ macro_rules! primitive { match value { Value::$variant(v) => Ok(v), $(Value::$other$(($binding))? => Ok($out),)* - v => Err(format_eco!( + v => Err(eco_format!( "expected {}, found {}", Self::TYPE_NAME, v.type_name(), diff --git a/src/syntax/lexer.rs b/src/syntax/lexer.rs index bd168f0a3..31608d40c 100644 --- a/src/syntax/lexer.rs +++ b/src/syntax/lexer.rs @@ -1,4 +1,4 @@ -use ecow::{format_eco, EcoString}; +use ecow::{eco_format, EcoString}; use unicode_segmentation::UnicodeSegmentation; use unicode_xid::UnicodeXID; use unscanny::Scanner; @@ -254,9 +254,9 @@ impl Lexer<'_> { let remaining = backticks - found; let noun = if remaining == 1 { "backtick" } else { "backticks" }; return self.error_at_end(if found == 0 { - format_eco!("expected {} {}", remaining, noun) + eco_format!("expected {} {}", remaining, noun) } else { - format_eco!("expected {} more {}", remaining, noun) + eco_format!("expected {} more {}", remaining, noun) }); } diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 483a076ea..b4321dbee 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use std::ops::Range; -use ecow::{format_eco, EcoString}; +use ecow::{eco_format, EcoString}; use unicode_math_class::MathClass; use super::{ast, is_newline, ErrorPos, LexMode, Lexer, SyntaxKind, SyntaxNode}; @@ -968,7 +968,7 @@ fn validate_array(p: &mut Parser, m: Marker) { for child in p.post_process(m) { let kind = child.kind(); if kind == SyntaxKind::Named || kind == SyntaxKind::Keyed { - child.convert_to_error(format_eco!( + child.convert_to_error(eco_format!( "expected expression, found {}", kind.name() )); @@ -998,7 +998,7 @@ fn validate_dict(p: &mut Parser, m: Marker) { | SyntaxKind::Comma | SyntaxKind::Colon => {} kind => { - child.convert_to_error(format_eco!( + child.convert_to_error(eco_format!( "expected named or keyed pair, found {}", kind.name() )); @@ -1026,7 +1026,7 @@ fn validate_params(p: &mut Parser, m: Marker) { SyntaxKind::Spread => { let Some(within) = child.children_mut().last_mut() else { continue }; if within.kind() != SyntaxKind::Ident { - within.convert_to_error(format_eco!( + within.convert_to_error(eco_format!( "expected identifier, found {}", within.kind().name(), )); @@ -1035,7 +1035,7 @@ fn validate_params(p: &mut Parser, m: Marker) { } SyntaxKind::LeftParen | SyntaxKind::RightParen | SyntaxKind::Comma => {} kind => { - child.convert_to_error(format_eco!( + child.convert_to_error(eco_format!( "expected identifier, named pair or argument sink, found {}", kind.name() )); @@ -1278,7 +1278,7 @@ impl<'s> Parser<'s> { .last() .map_or(true, |child| child.kind() != SyntaxKind::Error) { - let message = format_eco!("expected {}", thing); + let message = eco_format!("expected {}", thing); self.nodes.push(SyntaxNode::error(message, "", ErrorPos::Full)); } self.skip(); @@ -1302,7 +1302,7 @@ impl<'s> Parser<'s> { if !kind.is_error() { self.nodes[offset] - .convert_to_error(format_eco!("unexpected {}", kind.name())); + .convert_to_error(eco_format!("unexpected {}", kind.name())); } } }