Better error messages.
This commit is contained in:
parent
3f44e2893c
commit
92c7fd9e5b
@ -269,7 +269,7 @@ impl Engine {
|
|||||||
if let Some(prop) = extract_prop_from_getter(fn_name) {
|
if let Some(prop) = extract_prop_from_getter(fn_name) {
|
||||||
return EvalAltResult::ErrorDotExpr(
|
return EvalAltResult::ErrorDotExpr(
|
||||||
format!(
|
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,
|
prop,
|
||||||
self.map_type_name(args[0].type_name())
|
self.map_type_name(args[0].type_name())
|
||||||
),
|
),
|
||||||
@ -283,7 +283,7 @@ impl Engine {
|
|||||||
if let Some(prop) = extract_prop_from_setter(fn_name) {
|
if let Some(prop) = extract_prop_from_setter(fn_name) {
|
||||||
return EvalAltResult::ErrorDotExpr(
|
return EvalAltResult::ErrorDotExpr(
|
||||||
format!(
|
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,
|
prop,
|
||||||
self.map_type_name(args[0].type_name()),
|
self.map_type_name(args[0].type_name()),
|
||||||
self.map_type_name(args[1].type_name()),
|
self.map_type_name(args[1].type_name()),
|
||||||
|
@ -178,8 +178,9 @@ impl fmt::Display for EvalAltResult {
|
|||||||
|
|
||||||
Self::ErrorDotExpr(s, _) if !s.is_empty() => write!(f, "{}", s)?,
|
Self::ErrorDotExpr(s, _) if !s.is_empty() => write!(f, "{}", s)?,
|
||||||
|
|
||||||
Self::ErrorIndexingType(_, _)
|
Self::ErrorIndexingType(s, _) => write!(f, "Indexer not registered for type '{}'", s)?,
|
||||||
| Self::ErrorUnboundThis(_)
|
|
||||||
|
Self::ErrorUnboundThis(_)
|
||||||
| Self::ErrorFor(_)
|
| Self::ErrorFor(_)
|
||||||
| Self::ErrorInExpr(_)
|
| Self::ErrorInExpr(_)
|
||||||
| Self::ErrorDotExpr(_, _)
|
| Self::ErrorDotExpr(_, _)
|
||||||
|
20
src/token.rs
20
src/token.rs
@ -768,10 +768,13 @@ pub struct TokenizeState {
|
|||||||
///
|
///
|
||||||
/// This trait is volatile and may change.
|
/// This trait is volatile and may change.
|
||||||
pub trait InputStream {
|
pub trait InputStream {
|
||||||
fn unread(&mut self, ch: char);
|
/// Un-get a character back into the `InputStream`.
|
||||||
/// Get the next character
|
/// 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>;
|
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>;
|
fn peek_next(&mut self) -> Option<char>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1088,12 +1091,12 @@ fn get_next_token_inner(
|
|||||||
}
|
}
|
||||||
// _ - cannot follow a decimal point
|
// _ - cannot follow a decimal point
|
||||||
'_' => {
|
'_' => {
|
||||||
stream.unread(next_char);
|
stream.unget(next_char);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// .. - reserved symbol, not a floating-point number
|
// .. - reserved symbol, not a floating-point number
|
||||||
'.' => {
|
'.' => {
|
||||||
stream.unread(next_char);
|
stream.unget(next_char);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// symbol after period - probably a float
|
// symbol after period - probably a float
|
||||||
@ -1104,7 +1107,7 @@ fn get_next_token_inner(
|
|||||||
}
|
}
|
||||||
// Not a floating-point number
|
// Not a floating-point number
|
||||||
_ => {
|
_ => {
|
||||||
stream.unread(next_char);
|
stream.unget(next_char);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1634,12 +1637,10 @@ pub struct MultiInputsStream<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InputStream for MultiInputsStream<'_> {
|
impl InputStream for MultiInputsStream<'_> {
|
||||||
/// Buffer a character.
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn unread(&mut self, ch: char) {
|
fn unget(&mut self, ch: char) {
|
||||||
self.buf = Some(ch);
|
self.buf = Some(ch);
|
||||||
}
|
}
|
||||||
/// Get the next character
|
|
||||||
fn get_next(&mut self) -> Option<char> {
|
fn get_next(&mut self) -> Option<char> {
|
||||||
if let Some(ch) = self.buf.take() {
|
if let Some(ch) = self.buf.take() {
|
||||||
return Some(ch);
|
return Some(ch);
|
||||||
@ -1658,7 +1659,6 @@ impl InputStream for MultiInputsStream<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Peek the next character
|
|
||||||
fn peek_next(&mut self) -> Option<char> {
|
fn peek_next(&mut self) -> Option<char> {
|
||||||
if let Some(ch) = self.buf {
|
if let Some(ch) = self.buf {
|
||||||
return Some(ch);
|
return Some(ch);
|
||||||
|
Loading…
Reference in New Issue
Block a user