split up CompilationError::InconsistentEntry
This commit is contained in:
@@ -572,9 +572,10 @@ impl MachineState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let location = err.line_and_col_num();
|
let location = err.line_and_col_num();
|
||||||
let stub = err.as_functor();
|
let len = self.heap.len();
|
||||||
|
let stub = err.as_functor(&mut self.heap);
|
||||||
|
|
||||||
let stub = functor!(atom!("syntax_error"), [str(self.heap.len(), 0)], [stub]);
|
let stub = functor!(atom!("syntax_error"), [str(len, 0)], [stub]);
|
||||||
|
|
||||||
MachineError {
|
MachineError {
|
||||||
stub,
|
stub,
|
||||||
@@ -690,7 +691,12 @@ pub enum CompilationError {
|
|||||||
ExpectedRel,
|
ExpectedRel,
|
||||||
InadmissibleFact,
|
InadmissibleFact,
|
||||||
InadmissibleQueryTerm,
|
InadmissibleQueryTerm,
|
||||||
InconsistentEntry,
|
ExpectedDecl(Term),
|
||||||
|
InvalidDecl(Atom, usize /* arity */),
|
||||||
|
InvalidOpDeclName(Term),
|
||||||
|
InvalidOpDeclSpecTerm(Term),
|
||||||
|
InvalidOpDeclSpecValue(Atom),
|
||||||
|
InvalidOpDeclPrec(Term),
|
||||||
InvalidMetaPredicateDecl,
|
InvalidMetaPredicateDecl,
|
||||||
InvalidModuleDecl,
|
InvalidModuleDecl,
|
||||||
InvalidModuleExport,
|
InvalidModuleExport,
|
||||||
@@ -722,7 +728,7 @@ impl CompilationError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn as_functor(&self) -> MachineStub {
|
pub(crate) fn as_functor(&self, heap: &mut Heap) -> MachineStub {
|
||||||
match self {
|
match self {
|
||||||
CompilationError::Arithmetic(..) => {
|
CompilationError::Arithmetic(..) => {
|
||||||
functor!(atom!("arithmetic_error"))
|
functor!(atom!("arithmetic_error"))
|
||||||
@@ -744,8 +750,48 @@ impl CompilationError {
|
|||||||
// TODO: type_error(callable, _).
|
// TODO: type_error(callable, _).
|
||||||
functor!(atom!("inadmissible_query_term"))
|
functor!(atom!("inadmissible_query_term"))
|
||||||
}
|
}
|
||||||
CompilationError::InconsistentEntry => {
|
CompilationError::ExpectedDecl(_term) => {
|
||||||
functor!(atom!("inconsistent_entry"))
|
functor!(atom!("not_a_declaration"))
|
||||||
|
}
|
||||||
|
CompilationError::InvalidDecl(name, arity) => {
|
||||||
|
let culprit = functor_stub(*name, *arity);
|
||||||
|
functor!(
|
||||||
|
atom!("existence_error"),
|
||||||
|
[atom(atom!("declaration")), str(heap.len() + 2, 0)],
|
||||||
|
[culprit]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
CompilationError::InvalidOpDeclName(_term) => {
|
||||||
|
functor!(
|
||||||
|
atom!("invalid_op_decl"),
|
||||||
|
[atom(atom!("name")), atom(atom!("expected_string_or_atom"))]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
CompilationError::InvalidOpDeclSpecTerm(_term) => {
|
||||||
|
functor!(
|
||||||
|
atom!("invalid_op_decl"),
|
||||||
|
[
|
||||||
|
atom(atom!("specification")),
|
||||||
|
atom(atom!("expected_string_or_atom"))
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
CompilationError::InvalidOpDeclSpecValue(spec) => {
|
||||||
|
let functor = functor!(atom!("invalid_value"), [atom(spec)]);
|
||||||
|
functor!(
|
||||||
|
atom!("invalid_op_decl"),
|
||||||
|
[atom(atom!("specification")), str(heap.len() + 2, 0)],
|
||||||
|
[functor]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
CompilationError::InvalidOpDeclPrec(_term) => {
|
||||||
|
functor!(
|
||||||
|
atom!("invalid_op_decl"),
|
||||||
|
[
|
||||||
|
atom(atom!("precedence")),
|
||||||
|
atom(atom!("expected_integer_in_range_0_to_1200"))
|
||||||
|
]
|
||||||
|
)
|
||||||
}
|
}
|
||||||
CompilationError::InvalidMetaPredicateDecl => {
|
CompilationError::InvalidMetaPredicateDecl => {
|
||||||
functor!(atom!("invalid_meta_predicate_decl"))
|
functor!(atom!("invalid_meta_predicate_decl"))
|
||||||
|
|||||||
@@ -16,30 +16,37 @@ pub(crate) fn to_op_decl(prec: u16, spec: OpDeclSpec, name: Atom) -> OpDecl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn to_op_decl_spec(spec: Atom) -> Result<OpDeclSpec, CompilationError> {
|
pub(crate) fn to_op_decl_spec(spec: Atom) -> Result<OpDeclSpec, CompilationError> {
|
||||||
OpDeclSpec::try_from(spec).map_err(|_err| CompilationError::InconsistentEntry)
|
OpDeclSpec::try_from(spec).map_err(|_err| CompilationError::InvalidOpDeclSpecValue(spec))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_op_decl(mut terms: Vec<Term>, atom_tbl: &AtomTable) -> Result<OpDecl, CompilationError> {
|
fn setup_op_decl(mut terms: Vec<Term>, atom_tbl: &AtomTable) -> Result<OpDecl, CompilationError> {
|
||||||
let name = match terms.pop().unwrap() {
|
let name = match terms.pop().unwrap() {
|
||||||
Term::Literal(_, Literal::Atom(name)) => name,
|
Term::Literal(_, Literal::Atom(name)) => name,
|
||||||
Term::Literal(_, Literal::Char(c)) => AtomTable::build_with(atom_tbl, &c.to_string()),
|
Term::Literal(_, Literal::Char(c)) => AtomTable::build_with(atom_tbl, &c.to_string()),
|
||||||
_ => return Err(CompilationError::InconsistentEntry),
|
other => {
|
||||||
|
return Err(CompilationError::InvalidOpDeclName(other));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let spec = match terms.pop().unwrap() {
|
let spec = match terms.pop().unwrap() {
|
||||||
Term::Literal(_, Literal::Atom(name)) => name,
|
Term::Literal(_, Literal::Atom(name)) => name,
|
||||||
Term::Literal(_, Literal::Char(c)) => AtomTable::build_with(atom_tbl, &c.to_string()),
|
other => {
|
||||||
_ => return Err(CompilationError::InconsistentEntry),
|
return Err(CompilationError::InvalidOpDeclSpecTerm(other));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let spec = to_op_decl_spec(spec)?;
|
let spec = to_op_decl_spec(spec)?;
|
||||||
|
|
||||||
let prec = match terms.pop().unwrap() {
|
let prec = match terms.pop().unwrap() {
|
||||||
Term::Literal(_, Literal::Fixnum(bi)) => match u16::try_from(bi.get_num()) {
|
term @ Term::Literal(_, Literal::Fixnum(bi)) => match u16::try_from(bi.get_num()) {
|
||||||
Ok(n) if n <= 1200 => n,
|
Ok(n) if n <= 1200 => n,
|
||||||
_ => return Err(CompilationError::InconsistentEntry),
|
_ => {
|
||||||
|
return Err(CompilationError::InvalidOpDeclPrec(term));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => return Err(CompilationError::InconsistentEntry),
|
other => {
|
||||||
|
return Err(CompilationError::InvalidOpDeclPrec(other));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(to_op_decl(prec, spec, name))
|
Ok(to_op_decl(prec, spec, name))
|
||||||
@@ -327,9 +334,9 @@ pub(super) fn setup_declaration<'a, LS: LoadState<'a>>(
|
|||||||
let (module_name, name, meta_specs) = setup_meta_predicate(terms, loader)?;
|
let (module_name, name, meta_specs) = setup_meta_predicate(terms, loader)?;
|
||||||
Ok(Declaration::MetaPredicate(module_name, name, meta_specs))
|
Ok(Declaration::MetaPredicate(module_name, name, meta_specs))
|
||||||
}
|
}
|
||||||
_ => Err(CompilationError::InconsistentEntry),
|
_ => Err(CompilationError::InvalidDecl(name, terms.len())),
|
||||||
},
|
},
|
||||||
_ => Err(CompilationError::InconsistentEntry),
|
other => Err(CompilationError::ExpectedDecl(other)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
```trycmd
|
```trycmd
|
||||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl1.pl -g halt
|
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl1.pl -g halt
|
||||||
error(syntax_error(inconsistent_entry),load/1).
|
error(syntax_error(invalid_op_decl(specification,invalid_value(moin))),load/1).
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```trycmd
|
```trycmd
|
||||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl2.pl -g halt
|
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl2.pl -g halt
|
||||||
error(syntax_error(inconsistent_entry),load/1).
|
error(syntax_error(invalid_op_decl(precedence,expected_integer_in_range_0_to_1200)),load/1).
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```trycmd
|
```trycmd
|
||||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl3.pl -g halt
|
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl3.pl -g halt
|
||||||
error(syntax_error(inconsistent_entry),load/1).
|
error(syntax_error(invalid_op_decl(name,expected_string_or_atom)),load/1).
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```trycmd
|
```trycmd
|
||||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl4.pl -g halt
|
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl4.pl -g halt
|
||||||
error(syntax_error(inconsistent_entry),load/1).
|
error(syntax_error(existence_error(declaration,op/4)),load/1).
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```trycmd
|
```trycmd
|
||||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl5.pl -g halt
|
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl5.pl -g halt
|
||||||
error(syntax_error(inconsistent_entry),load/1).
|
error(syntax_error(existence_error(declaration,(;)/2)),load/1).
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```trycmd
|
```trycmd
|
||||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl6.pl -g halt
|
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl6.pl -g halt
|
||||||
error(syntax_error(inconsistent_entry),load/1).
|
error(syntax_error(not_a_declaration),load/1).
|
||||||
|
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user