diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/eval/args.rs | 8 | ||||
| -rw-r--r-- | src/eval/scope.rs | 10 | ||||
| -rw-r--r-- | src/syntax/lexer.rs | 12 | ||||
| -rw-r--r-- | src/syntax/parser.rs | 24 |
4 files changed, 36 insertions, 18 deletions
diff --git a/src/eval/args.rs b/src/eval/args.rs index aadd7d54..8617bd93 100644 --- a/src/eval/args.rs +++ b/src/eval/args.rs @@ -158,7 +158,13 @@ impl Args { /// argument. pub fn finish(self) -> SourceResult<()> { if let Some(arg) = self.items.first() { - bail!(arg.span, "unexpected argument"); + bail!( + arg.span, + match &arg.name { + Some(name) => eco_format!("unexpected argument: {}", name), + _ => eco_format!("unexpected argument"), + } + ) } Ok(()) } diff --git a/src/eval/scope.rs b/src/eval/scope.rs index e241cac5..f2207188 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::fmt::{self, Debug, Formatter}; use std::hash::Hash; -use ecow::EcoString; +use ecow::{eco_format, EcoString}; use super::{Library, Value}; use crate::diag::StrResult; @@ -42,7 +42,7 @@ impl<'a> Scopes<'a> { .chain(self.scopes.iter().rev()) .chain(self.base.map(|base| base.global.scope())) .find_map(|scope| scope.get(var)) - .ok_or("unknown variable")?) + .ok_or(eco_format!("unknown variable: {}", var))?) } /// Try to access a variable immutably in math. @@ -51,7 +51,7 @@ impl<'a> Scopes<'a> { .chain(self.scopes.iter().rev()) .chain(self.base.map(|base| base.math.scope())) .find_map(|scope| scope.get(var)) - .ok_or("unknown variable")?) + .ok_or(eco_format!("unknown variable: {}", var))?) } /// Try to access a variable mutably. @@ -61,8 +61,8 @@ impl<'a> Scopes<'a> { .find_map(|scope| scope.get_mut(var)) .ok_or_else(|| { match self.base.and_then(|base| base.global.scope().get(var)) { - Some(_) => "cannot mutate a constant", - _ => "unknown variable", + Some(_) => eco_format!("cannot mutate a constant: {}", var), + _ => eco_format!("unknown variable: {}", var), } })? } diff --git a/src/syntax/lexer.rs b/src/syntax/lexer.rs index 7961d4ca..dcd2509a 100644 --- a/src/syntax/lexer.rs +++ b/src/syntax/lexer.rs @@ -217,7 +217,7 @@ impl Lexer<'_> { .and_then(std::char::from_u32) .is_none() { - return self.error("invalid unicode escape sequence"); + return self.error(eco_format!("invalid unicode codepoint: {}", hex)); } return SyntaxKind::Escape; @@ -585,10 +585,10 @@ impl Lexer<'_> { SyntaxKind::Float } else { return self.error(match base { - 2 => "invalid binary number", - 8 => "invalid octal number", - 16 => "invalid hexadecimal number", - _ => "invalid number", + 2 => eco_format!("invalid binary number: 0b{}", number), + 8 => eco_format!("invalid octal number: 0o{}", number), + 16 => eco_format!("invalid hexadecimal number: 0x{}", number), + _ => eco_format!("invalid number: {}", number), }); }; @@ -600,7 +600,7 @@ impl Lexer<'_> { suffix, "pt" | "mm" | "cm" | "in" | "deg" | "rad" | "em" | "fr" | "%" ) { - return self.error("invalid number suffix"); + return self.error(eco_format!("invalid number suffix: {}", suffix)); } SyntaxKind::Numeric diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index e6807404..4bc25a30 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -1046,8 +1046,8 @@ fn validate_dict(p: &mut Parser, m: Marker) { None => first.text().clone(), }; - if !used.insert(key) { - first.convert_to_error("duplicate key"); + if !used.insert(key.clone()) { + first.convert_to_error(eco_format!("duplicate key: {}", key)); child.make_erroneous(); } } @@ -1073,13 +1073,19 @@ fn validate_params(p: &mut Parser, m: Marker) { match child.kind() { SyntaxKind::Ident => { if !used.insert(child.text().clone()) { - child.convert_to_error("duplicate parameter"); + child.convert_to_error(eco_format!( + "duplicate parameter: {}", + child.text() + )); } } SyntaxKind::Named => { let Some(within) = child.children_mut().first_mut() else { return }; if !used.insert(within.text().clone()) { - within.convert_to_error("duplicate parameter"); + within.convert_to_error(eco_format!( + "duplicate parameter: {}", + within.text() + )); child.make_erroneous(); } } @@ -1101,7 +1107,10 @@ fn validate_params(p: &mut Parser, m: Marker) { continue; } if !used.insert(within.text().clone()) { - within.convert_to_error("duplicate parameter"); + within.convert_to_error(eco_format!( + "duplicate parameter: {}", + within.text() + )); child.make_erroneous(); } } @@ -1122,7 +1131,10 @@ fn validate_args(p: &mut Parser, m: Marker) { if child.kind() == SyntaxKind::Named { let Some(within) = child.children_mut().first_mut() else { return }; if !used.insert(within.text().clone()) { - within.convert_to_error("duplicate argument"); + within.convert_to_error(eco_format!( + "duplicate argument: {}", + within.text() + )); child.make_erroneous(); } } |
