Skip to content

Commit

Permalink
more generally consider NEGATIVE_SIGN a non-op term (#2401)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed May 13, 2024
1 parent 42a0d68 commit 070f1e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
}

Expand Down
14 changes: 6 additions & 8 deletions src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
_ => {
Expand All @@ -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 {
Expand Down
17 changes: 10 additions & 7 deletions tests-pl/iso-conformity-tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,16 @@

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)".
Expand Down

0 comments on commit 070f1e8

Please sign in to comment.