add slightly more descriptive syntax errors
This commit is contained in:
@@ -40,9 +40,9 @@ impl MachineError {
|
||||
{
|
||||
let mod_name = HeapCellValue::Addr(Addr::Con(Constant::Atom(mod_name)));
|
||||
let name = HeapCellValue::Addr(Addr::Con(Constant::Atom(name)));
|
||||
|
||||
|
||||
let mut stub = functor!("evaluation_error", 1, [HeapCellValue::Addr(Addr::HeapCell(h + 2))]);
|
||||
|
||||
|
||||
stub.append(&mut functor!("/", 2, [HeapCellValue::Addr(Addr::HeapCell(h + 2 + 3)),
|
||||
heap_integer!(arity)],
|
||||
Fixity::In));
|
||||
@@ -50,7 +50,7 @@ impl MachineError {
|
||||
|
||||
MachineError { stub, from: ErrorProvenance::Constructed }
|
||||
}
|
||||
|
||||
|
||||
pub(super) fn existence_error(h: usize, name: ClauseName, arity: usize) -> Self {
|
||||
let mut stub = functor!("existence_error", 2, [heap_atom!("procedure"), heap_str!(3 + h)]);
|
||||
stub.append(&mut Self::functor_stub(name, arity));
|
||||
@@ -58,11 +58,60 @@ impl MachineError {
|
||||
MachineError { stub, from: ErrorProvenance::Constructed }
|
||||
}
|
||||
|
||||
pub(super) fn syntax_error(error: SyntaxError) -> Self {
|
||||
let stub = functor!("syntax_error", 1, [heap_atom!(error.as_str())]);
|
||||
MachineError { stub, from: ErrorProvenance::Received }
|
||||
pub(super) fn syntax_error(h: usize, err: ParserError) -> Self {
|
||||
let err = match err {
|
||||
ParserError::Arithmetic(_) =>
|
||||
vec![heap_atom!("arithmetic_error")],
|
||||
ParserError::BackQuotedString =>
|
||||
vec![heap_atom!("back_quoted_string")],
|
||||
ParserError::UnexpectedChar(c) =>
|
||||
functor!("unexpected_char", 1, [heap_char!(c)]),
|
||||
ParserError::UnexpectedEOF =>
|
||||
vec![heap_atom!("unexpected_end_of_file")],
|
||||
ParserError::ExpectedRel =>
|
||||
vec![heap_atom!("expected_relation")],
|
||||
ParserError::InadmissibleFact =>
|
||||
vec![heap_atom!("inadmissible_fact")],
|
||||
ParserError::InadmissibleQueryTerm =>
|
||||
vec![heap_atom!("inadmissible_query_term")],
|
||||
ParserError::IncompleteReduction =>
|
||||
vec![heap_atom!("incomplete_reduction")],
|
||||
ParserError::InconsistentEntry =>
|
||||
vec![heap_atom!("inconsistent_entry")],
|
||||
ParserError::InvalidModuleDecl =>
|
||||
vec![heap_atom!("invalid_module_declaration")],
|
||||
ParserError::InvalidModuleExport =>
|
||||
vec![heap_atom!("invalid_module_export")],
|
||||
ParserError::InvalidModuleResolution =>
|
||||
vec![heap_atom!("invalid_module_resolution")],
|
||||
ParserError::InvalidRuleHead =>
|
||||
vec![heap_atom!("invalid_head_of_rule")],
|
||||
ParserError::InvalidUseModuleDecl =>
|
||||
vec![heap_atom!("invalid_use_module_declaration")],
|
||||
ParserError::IO(_) =>
|
||||
vec![heap_atom!("input_output_error")],
|
||||
ParserError::MissingQuote =>
|
||||
vec![heap_atom!("missing_quote")],
|
||||
ParserError::NonPrologChar =>
|
||||
vec![heap_atom!("non_prolog_character")],
|
||||
ParserError::ParseBigInt =>
|
||||
vec![heap_atom!("cannot_parse_big_int")],
|
||||
ParserError::ParseFloat =>
|
||||
vec![heap_atom!("cannot_parse_float")],
|
||||
ParserError::Utf8Conversion(_) =>
|
||||
vec![heap_atom!("utf8_conversion_error")]
|
||||
};
|
||||
|
||||
let mut stub = if err.len() == 1 {
|
||||
functor!("syntax_error", 1)
|
||||
} else {
|
||||
functor!("syntax_error", 1, [heap_str!(h + 2)])
|
||||
};
|
||||
|
||||
stub.extend(err.into_iter());
|
||||
MachineError { stub, from: ErrorProvenance::Constructed }
|
||||
}
|
||||
|
||||
|
||||
pub(super) fn domain_error(error: DomainError, culprit: Addr) -> Self {
|
||||
let stub = functor!("domain_error", 2, [heap_atom!(error.as_str()),
|
||||
HeapCellValue::Addr(culprit)]);
|
||||
@@ -140,19 +189,6 @@ impl ValidType {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum SyntaxError {
|
||||
ImpDepAtom
|
||||
}
|
||||
|
||||
impl SyntaxError {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
&SyntaxError::ImpDepAtom => "imp_dep_atom"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum DomainError {
|
||||
NotLessThanZero
|
||||
|
||||
Reference in New Issue
Block a user