Better error messages.

This commit is contained in:
Stephen Chung 2021-01-15 17:13:04 +08:00
parent 3f44e2893c
commit 92c7fd9e5b
3 changed files with 15 additions and 14 deletions

View File

@ -269,7 +269,7 @@ impl Engine {
if let Some(prop) = extract_prop_from_getter(fn_name) {
return EvalAltResult::ErrorDotExpr(
format!(
"Failed to get property '{}' of '{}' - the property may not exist, or it may be write-only",
"Unknown property '{}' - a getter is not registered for type '{}'",
prop,
self.map_type_name(args[0].type_name())
),
@ -283,7 +283,7 @@ impl Engine {
if let Some(prop) = extract_prop_from_setter(fn_name) {
return EvalAltResult::ErrorDotExpr(
format!(
"Failed to set property '{}' of '{}' - the property may not exist, may be read-only, or '{}' is the wrong type",
"No writable property '{}' - a setter is not registered for type '{}' to handle '{}'",
prop,
self.map_type_name(args[0].type_name()),
self.map_type_name(args[1].type_name()),

View File

@ -178,8 +178,9 @@ impl fmt::Display for EvalAltResult {
Self::ErrorDotExpr(s, _) if !s.is_empty() => write!(f, "{}", s)?,
Self::ErrorIndexingType(_, _)
| Self::ErrorUnboundThis(_)
Self::ErrorIndexingType(s, _) => write!(f, "Indexer not registered for type '{}'", s)?,
Self::ErrorUnboundThis(_)
| Self::ErrorFor(_)
| Self::ErrorInExpr(_)
| Self::ErrorDotExpr(_, _)

View File

@ -768,10 +768,13 @@ pub struct TokenizeState {
///
/// This trait is volatile and may change.
pub trait InputStream {
fn unread(&mut self, ch: char);
/// Get the next character
/// Un-get a character back into the `InputStream`.
/// The next [`get_next`][InputStream::get_next] or [`peek_next`][InputStream::peek_next]
/// will return this character instead.
fn unget(&mut self, ch: char);
/// Get the next character from the `InputStream`.
fn get_next(&mut self) -> Option<char>;
/// Peek the next character
/// Peek the next character in the `InputStream`.
fn peek_next(&mut self) -> Option<char>;
}
@ -1088,12 +1091,12 @@ fn get_next_token_inner(
}
// _ - cannot follow a decimal point
'_' => {
stream.unread(next_char);
stream.unget(next_char);
break;
}
// .. - reserved symbol, not a floating-point number
'.' => {
stream.unread(next_char);
stream.unget(next_char);
break;
}
// symbol after period - probably a float
@ -1104,7 +1107,7 @@ fn get_next_token_inner(
}
// Not a floating-point number
_ => {
stream.unread(next_char);
stream.unget(next_char);
break;
}
}
@ -1634,12 +1637,10 @@ pub struct MultiInputsStream<'a> {
}
impl InputStream for MultiInputsStream<'_> {
/// Buffer a character.
#[inline(always)]
fn unread(&mut self, ch: char) {
fn unget(&mut self, ch: char) {
self.buf = Some(ch);
}
/// Get the next character
fn get_next(&mut self) -> Option<char> {
if let Some(ch) = self.buf.take() {
return Some(ch);
@ -1658,7 +1659,6 @@ impl InputStream for MultiInputsStream<'_> {
}
}
}
/// Peek the next character
fn peek_next(&mut self) -> Option<char> {
if let Some(ch) = self.buf {
return Some(ch);