]> Repositorios git - scryer-prolog.git/commitdiff
more generally consider NEGATIVE_SIGN a non-op term (#2401)
authorMark Thom <[email protected]>
Mon, 13 May 2024 20:37:32 +0000 (14:37 -0600)
committerMark Thom <[email protected]>
Mon, 13 May 2024 20:37:44 +0000 (14:37 -0600)
src/parser/ast.rs
src/parser/parser.rs
tests-pl/iso-conformity-tests.pl

index 82526ab458bb94faf2b63612429439fa49e1560c..7b3022eab0f5477c1a433bf48d20977ea28112fc 100644 (file)
@@ -49,13 +49,13 @@ macro_rules! fixnum {
 
 macro_rules! is_term {
     ($x:expr) => {
-        ($x as u32 & $crate::parser::ast::TERM) != 0
+        ($x as u32 & $crate::parser::ast::TERM) != 0 || is_negate!($x)
     };
 }
 
 macro_rules! is_lterm {
     ($x:expr) => {
-        ($x as u32 & $crate::parser::ast::LTERM) != 0
+        ($x as u32 & $crate::parser::ast::LTERM) != 0 || is_negate!($x)
     };
 }
 
index 3637df24fe6faa5d79ff7428478f88b9c38c3a31..47e829219dcb3c92aa555dfcc8de13d5c22025bc 100644 (file)
@@ -150,6 +150,7 @@ pub fn get_op_desc(name: Atom, op_dir: &CompositeOpDir) -> Option<CompositeOpDes
             op_desc.pre = pri as usize;
             op_desc.spec |= spec as u32;
         } else if name == atom!("-") {
+            // used to denote a negative sign that should be treated as an atom and not an operator
             op_desc.spec |= NEGATIVE_SIGN;
         }
     }
@@ -693,7 +694,7 @@ impl<'a, R: CharRead> Parser<'a, R> {
                 // expect a term or non-comma operator.
                 if let TokenType::Comma = desc.tt {
                     return None;
-                } else if is_term!(desc.spec) || is_op!(desc.spec) {
+                } else if is_term!(desc.spec) || is_op!(desc.spec) || is_negate!(desc.spec) {
                     arity += 1;
                 } else {
                     return None;
@@ -911,9 +912,6 @@ impl<'a, R: CharRead> Parser<'a, R> {
                         // can't be prefix, so either inf == 0
                         // or post == 0.
                         self.reduce_op(inf + post);
-
-                        // let fixity = if inf > 0 { Fixity::In } else { Fixity::Post };
-
                         self.promote_atom_op(name, inf + post, spec & (XFX | XFY | YFX | YF | XF));
                     }
                     _ => {
@@ -927,12 +925,12 @@ impl<'a, R: CharRead> Parser<'a, R> {
                                     inf + post,
                                     spec & (XFX | XFY | YFX | XF | YF),
                                 );
-                            } else {
-                                self.promote_atom_op(name, pre, spec & (FX | FY | NEGATIVE_SIGN));
+
+                                return Ok(true);
                             }
-                        } else {
-                            self.promote_atom_op(name, pre, spec & (FX | FY | NEGATIVE_SIGN));
                         }
+
+                        self.promote_atom_op(name, pre, spec & (FX | FY | NEGATIVE_SIGN));
                     }
                 }
             } else {
index dc08ce2d57c66f3c4b9cfd3d086af939255bd5d7..10b85c10dae2acd6314d1b430f3ae4dad81a37cd 100644 (file)
@@ -230,13 +230,16 @@ test_61 :- integer('-'/*.*/1).
 
 test_62 :- atom(-/*.*/-).
 
-test_63_180_64 :- setup_call_cleanup((  current_op(P,fy,-),
-                                        op(0,fy,-)
-                                     ),
-                                     (  integer(-1),
-                                        integer(- 1)
-                                     ),
-                                     op(P,fy,-)).
+test_63_180_64_328 :- setup_call_cleanup((  current_op(P,fy,-),
+                                            op(0,fy,-)
+                                         ),
+                                         (  integer(-1),
+                                            integer(- 1),
+                                            read_from_chars("writeq_term_to_chars([-]).", Writer),
+                                            call(Writer, Cs),
+                                            Cs == "[-]"
+                                         ),
+                                         op(P,fy,-)).
 
 test_135 :- writeq_term_to_chars(-(1), Chars),
             Chars == "- (1)".