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)
};
}
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;
}
}
// 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;
// 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));
}
_ => {
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 {
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)".