]> Repositorios git - scryer-prolog.git/commitdiff
throw exception when attempting to post query as goal (#329)
authorMark Thom <[email protected]>
Sun, 12 Apr 2020 18:07:41 +0000 (12:07 -0600)
committerMark Thom <[email protected]>
Sun, 12 Apr 2020 18:07:41 +0000 (12:07 -0600)
src/prolog/machine/machine_errors.rs
src/prolog/machine/toplevel.rs
src/prolog/write.rs

index 1f3dc1803a42abeaedc19d58d76a03682655b588..1e09b2bb246326761e09721a9205eafc52739e43 100644 (file)
@@ -301,9 +301,6 @@ impl MachineError {
     pub(super)
     fn session_error(h: usize, err: SessionError) -> Self {
         match err {
-            SessionError::ParserError(err) => {
-                Self::syntax_error(h, err)
-            }
             SessionError::CannotOverwriteBuiltIn(pred_str)
           | SessionError::CannotOverwriteImport(pred_str) => {
                 Self::permission_error(
@@ -329,7 +326,15 @@ impl MachineError {
                     h,
                     Permission::Access,
                     "private_procedure",
-                    functor!("modules_does_not_exist"),
+                    functor!("module_does_not_exist"),
+                )
+            }
+            SessionError::NamelessEntry => {
+                Self::permission_error(
+                    h,
+                    Permission::Create,
+                    "static_procedure",
+                    functor!("nameless_procedure")
                 )
             }
             SessionError::OpIsInfixAndPostFix(op) => {
@@ -340,7 +345,17 @@ impl MachineError {
                     functor!(clause_name(op)),
                 )
             }
-            _ => unreachable!(),
+            SessionError::ParserError(err) => {
+                Self::syntax_error(h, err)
+            }
+            SessionError::QueryCannotBePostedAsGoal => {
+                Self::permission_error(
+                    h,
+                    Permission::Create,
+                    "static_procedure",
+                    functor!("query_cannot_be_posted_as_goal")
+                )
+            }
         }
     }
 
@@ -681,6 +696,7 @@ pub enum SessionError {
     ModuleNotFound,
     NamelessEntry,
     OpIsInfixAndPostFix(ClauseName),
+    QueryCannotBePostedAsGoal,
     ParserError(ParserError),
 }
 
index 40ccac3f8a3c9d46fa0b585df4ba9f8a8639e6cb..717f173ec3d7e7f9f59aac100628b76e45bfd4c4 100644 (file)
@@ -1290,7 +1290,7 @@ impl<'a> TopLevelBatchWorker<'a> {
                 TopLevel::Declaration(decl) =>
                     return Ok(Some(decl)),
                 TopLevel::Query(_) =>
-                    return Err(SessionError::NamelessEntry),
+                    return Err(SessionError::QueryCannotBePostedAsGoal),
             }
         }
 
index fdb5b90998c879f94c1b1db93492b19067f0da18..d83b848d6bb0b463f4dad69a72ccf34b14f946d0 100644 (file)
@@ -289,7 +289,9 @@ impl fmt::Display for IndexingInstruction {
 impl fmt::Display for SessionError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
-            &SessionError::CannotOverwriteBuiltIn(ref msg) => write!(f, "cannot overwrite {}", msg),
+            &SessionError::CannotOverwriteBuiltIn(ref msg) => {
+                write!(f, "cannot overwrite {}", msg)
+            }
             &SessionError::CannotOverwriteImport(ref msg) => {
                 write!(f, "cannot overwrite import {}", msg)
             }
@@ -312,7 +314,12 @@ impl fmt::Display for SessionError {
             &SessionError::NamelessEntry => {
                 write!(f, "the predicate head is not an atom or clause.")
             }
-            &SessionError::ParserError(ref e) => write!(f, "syntax_error({})", e.as_str()),
+            &SessionError::ParserError(ref e) => {
+                write!(f, "syntax_error({})", e.as_str())
+            }
+            &SessionError::QueryCannotBePostedAsGoal => {
+                write!(f, "query forms cannot be posted as goals.")
+            }
         }
     }
 }