change declaration to directive
This commit is contained in:
@@ -38,7 +38,7 @@ pub(crate) enum ValidType {
|
||||
Callable,
|
||||
Character,
|
||||
Compound,
|
||||
Declaration,
|
||||
Directive,
|
||||
Evaluable,
|
||||
Float,
|
||||
InByte,
|
||||
@@ -74,7 +74,7 @@ impl ValidType {
|
||||
// ValidType::PredicateIndicator => atom!("predicate_indicator"),
|
||||
// ValidType::Variable => atom!("variable")
|
||||
ValidType::TcpListener => atom!("tcp_listener"),
|
||||
ValidType::Declaration => atom!("declaration"),
|
||||
ValidType::Directive => atom!("directive"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -608,8 +608,8 @@ impl MachineState {
|
||||
return self.arithmetic_error(err);
|
||||
}
|
||||
|
||||
if let CompilationError::InvalidDecl(err) = err {
|
||||
return self.declaration_error(err);
|
||||
if let CompilationError::InvalidDirective(err) = err {
|
||||
return self.directive_error(err);
|
||||
}
|
||||
|
||||
let location = err.line_and_col_num();
|
||||
@@ -732,7 +732,7 @@ pub enum CompilationError {
|
||||
ExpectedRel,
|
||||
InadmissibleFact,
|
||||
InadmissibleQueryTerm,
|
||||
InvalidDecl(DeclarationError),
|
||||
InvalidDirective(DirectiveError),
|
||||
InvalidMetaPredicateDecl,
|
||||
InvalidModuleDecl,
|
||||
InvalidModuleExport,
|
||||
@@ -743,9 +743,9 @@ pub enum CompilationError {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DeclarationError {
|
||||
ExpectedDecl(Term),
|
||||
InvalidDecl(Atom, usize /* arity */),
|
||||
pub enum DirectiveError {
|
||||
ExpectedDirective(Term),
|
||||
InvalidDirective(Atom, usize /* arity */),
|
||||
InvalidOpDeclNameType(Term),
|
||||
InvalidOpDeclSpecDomain(Term),
|
||||
InvalidOpDeclSpecValue(Atom),
|
||||
@@ -799,7 +799,7 @@ impl CompilationError {
|
||||
// TODO: type_error(callable, _).
|
||||
functor!(atom!("inadmissible_query_term"))
|
||||
}
|
||||
CompilationError::InvalidDecl(_) => {
|
||||
CompilationError::InvalidDirective(_) => {
|
||||
functor!(atom!("declaration_error"))
|
||||
}
|
||||
CompilationError::InvalidMetaPredicateDecl => {
|
||||
@@ -866,7 +866,7 @@ pub(crate) enum DomainErrorType {
|
||||
StreamOrAlias,
|
||||
OperatorSpecifier,
|
||||
OperatorPriority,
|
||||
Declaration,
|
||||
Directive,
|
||||
}
|
||||
|
||||
impl DomainErrorType {
|
||||
@@ -880,7 +880,7 @@ impl DomainErrorType {
|
||||
DomainErrorType::StreamOrAlias => atom!("stream_or_alias"),
|
||||
DomainErrorType::OperatorSpecifier => atom!("operator_specifier"),
|
||||
DomainErrorType::OperatorPriority => atom!("operator_priority"),
|
||||
DomainErrorType::Declaration => atom!("declaration"),
|
||||
DomainErrorType::Directive => atom!("directive"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -979,37 +979,37 @@ impl MachineState {
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn declaration_error(&mut self, err: DeclarationError) -> MachineError {
|
||||
pub(crate) fn directive_error(&mut self, err: DirectiveError) -> MachineError {
|
||||
match err {
|
||||
DeclarationError::ExpectedDecl(_term) => self.type_error(
|
||||
ValidType::Declaration,
|
||||
DirectiveError::ExpectedDirective(_term) => self.type_error(
|
||||
ValidType::Directive,
|
||||
atom_as_cell!(atom!("todo_insert_invalid_term_here")),
|
||||
),
|
||||
DeclarationError::InvalidDecl(name, arity) => {
|
||||
self.domain_error(DomainErrorType::Declaration, functor_stub(name, arity))
|
||||
DirectiveError::InvalidDirective(name, arity) => {
|
||||
self.domain_error(DomainErrorType::Directive, functor_stub(name, arity))
|
||||
}
|
||||
DeclarationError::InvalidOpDeclNameType(_term) => self.type_error(
|
||||
DirectiveError::InvalidOpDeclNameType(_term) => self.type_error(
|
||||
ValidType::List,
|
||||
atom_as_cell!(atom!("todo_insert_invalid_term_here")),
|
||||
),
|
||||
DeclarationError::InvalidOpDeclSpecDomain(_term) => self.domain_error(
|
||||
DirectiveError::InvalidOpDeclSpecDomain(_term) => self.domain_error(
|
||||
DomainErrorType::OperatorSpecifier,
|
||||
atom_as_cell!(atom!("todo_insert_invalid_term_here")),
|
||||
),
|
||||
DeclarationError::InvalidOpDeclSpecValue(atom) => {
|
||||
DirectiveError::InvalidOpDeclSpecValue(atom) => {
|
||||
self.domain_error(DomainErrorType::OperatorSpecifier, atom_as_cell!(atom))
|
||||
}
|
||||
DeclarationError::InvalidOpDeclPrecType(_term) => self.type_error(
|
||||
DirectiveError::InvalidOpDeclPrecType(_term) => self.type_error(
|
||||
ValidType::Integer,
|
||||
atom_as_cell!(atom!("todo_insert_invalid_term_here")),
|
||||
),
|
||||
DeclarationError::InvalidOpDeclPrecDomain(num) => {
|
||||
DirectiveError::InvalidOpDeclPrecDomain(num) => {
|
||||
self.domain_error(DomainErrorType::OperatorPriority, fixnum_as_cell!(num))
|
||||
}
|
||||
DeclarationError::ShallNotCreate(atom) => {
|
||||
DirectiveError::ShallNotCreate(atom) => {
|
||||
self.permission_error(Permission::Create, atom!("operator"), atom)
|
||||
}
|
||||
DeclarationError::ShallNotModify(atom) => {
|
||||
DirectiveError::ShallNotModify(atom) => {
|
||||
self.permission_error(Permission::Modify, atom!("operator"), atom)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ 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> {
|
||||
OpDeclSpec::try_from(spec).map_err(|_err| {
|
||||
CompilationError::InvalidDecl(DeclarationError::InvalidOpDeclSpecValue(spec))
|
||||
CompilationError::InvalidDirective(DirectiveError::InvalidOpDeclSpecValue(spec))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ fn setup_op_decl(mut terms: Vec<Term>, atom_tbl: &AtomTable) -> Result<OpDecl, C
|
||||
Term::Literal(_, Literal::Atom(name)) => name,
|
||||
Term::Literal(_, Literal::Char(c)) => AtomTable::build_with(atom_tbl, &c.to_string()),
|
||||
other => {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::InvalidOpDeclNameType(other),
|
||||
return Err(CompilationError::InvalidDirective(
|
||||
DirectiveError::InvalidOpDeclNameType(other),
|
||||
));
|
||||
}
|
||||
};
|
||||
@@ -36,8 +36,8 @@ fn setup_op_decl(mut terms: Vec<Term>, atom_tbl: &AtomTable) -> Result<OpDecl, C
|
||||
let spec = match terms.pop().unwrap() {
|
||||
Term::Literal(_, Literal::Atom(name)) => name,
|
||||
other => {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::InvalidOpDeclSpecDomain(other),
|
||||
return Err(CompilationError::InvalidDirective(
|
||||
DirectiveError::InvalidOpDeclSpecDomain(other),
|
||||
))
|
||||
}
|
||||
};
|
||||
@@ -48,33 +48,33 @@ fn setup_op_decl(mut terms: Vec<Term>, atom_tbl: &AtomTable) -> Result<OpDecl, C
|
||||
Term::Literal(_, Literal::Fixnum(bi)) => match u16::try_from(bi.get_num()) {
|
||||
Ok(n) if n <= 1200 => n,
|
||||
_ => {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::InvalidOpDeclPrecDomain(bi),
|
||||
return Err(CompilationError::InvalidDirective(
|
||||
DirectiveError::InvalidOpDeclPrecDomain(bi),
|
||||
));
|
||||
}
|
||||
},
|
||||
other => {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::InvalidOpDeclPrecType(other),
|
||||
return Err(CompilationError::InvalidDirective(
|
||||
DirectiveError::InvalidOpDeclPrecType(other),
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
if name == "[]" || name == "{}" {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::ShallNotCreate(name),
|
||||
return Err(CompilationError::InvalidDirective(
|
||||
DirectiveError::ShallNotCreate(name),
|
||||
));
|
||||
}
|
||||
|
||||
if name == "," {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::ShallNotModify(name),
|
||||
return Err(CompilationError::InvalidDirective(
|
||||
DirectiveError::ShallNotModify(name),
|
||||
));
|
||||
}
|
||||
|
||||
if name == "|" && (prec < 1001 || !spec.is_infix()) {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::ShallNotCreate(name),
|
||||
return Err(CompilationError::InvalidDirective(
|
||||
DirectiveError::ShallNotCreate(name),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -363,12 +363,12 @@ pub(super) fn setup_declaration<'a, LS: LoadState<'a>>(
|
||||
let (module_name, name, meta_specs) = setup_meta_predicate(terms, loader)?;
|
||||
Ok(Declaration::MetaPredicate(module_name, name, meta_specs))
|
||||
}
|
||||
_ => Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::InvalidDecl(name, terms.len()),
|
||||
_ => Err(CompilationError::InvalidDirective(
|
||||
DirectiveError::InvalidDirective(name, terms.len()),
|
||||
)),
|
||||
},
|
||||
other => Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::ExpectedDecl(other),
|
||||
other => Err(CompilationError::InvalidDirective(
|
||||
DirectiveError::ExpectedDirective(other),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,19 +18,19 @@ $ scryer-prolog -f --no-add-history tests-pl/invalid_decl3.pl -g halt
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl4.pl -g halt
|
||||
error(domain_error(declaration,op/4),load/1).
|
||||
error(domain_error(directive,op/4),load/1).
|
||||
|
||||
```
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl5.pl -g halt
|
||||
error(domain_error(declaration,(;)/2),load/1).
|
||||
error(domain_error(directive,(;)/2),load/1).
|
||||
|
||||
```
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl6.pl -g halt
|
||||
error(type_error(declaration,todo_insert_invalid_term_here),load/1).
|
||||
error(type_error(directive,todo_insert_invalid_term_here),load/1).
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user