use an enum for OpDesc spec
This commit is contained in:
@@ -6,8 +6,8 @@ use crate::parser::dashu::integer::Sign;
|
||||
use crate::parser::dashu::{ibig, Integer, Rational};
|
||||
use crate::{
|
||||
alpha_numeric_char, capital_letter_char, cut_char, decimal_digit_char, graphic_token_char,
|
||||
is_fx, is_infix, is_postfix, is_prefix, is_xf, is_xfx, is_xfy, is_yfx, semicolon_char,
|
||||
sign_char, single_quote_char, small_letter_char, solo_char, variable_indicator_char,
|
||||
semicolon_char, sign_char, single_quote_char, small_letter_char, solo_char,
|
||||
variable_indicator_char,
|
||||
};
|
||||
|
||||
use crate::forms::*;
|
||||
@@ -51,7 +51,7 @@ impl DirectedOp {
|
||||
fn is_prefix(&self) -> bool {
|
||||
match self {
|
||||
&DirectedOp::Left(_name, cell) | &DirectedOp::Right(_name, cell) => {
|
||||
is_prefix!(cell.get_spec() as u32)
|
||||
cell.get_spec().is_prefix()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ impl DirectedOp {
|
||||
fn is_negative_sign(&self) -> bool {
|
||||
match self {
|
||||
&DirectedOp::Left(name, cell) | &DirectedOp::Right(name, cell) => {
|
||||
name == atom!("-") && is_prefix!(cell.get_spec() as u32)
|
||||
name == atom!("-") && cell.get_spec().is_prefix()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,24 +78,24 @@ fn needs_bracketing(child_desc: OpDesc, op: &DirectedOp) -> bool {
|
||||
|
||||
if &*name.as_str() == "-" {
|
||||
let child_assoc = child_desc.get_spec();
|
||||
if is_prefix!(spec) && (is_postfix!(child_assoc) || is_infix!(child_assoc)) {
|
||||
if spec.is_prefix() && (child_assoc.is_postfix() || child_assoc.is_infix()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
let is_strict_right = is_yfx!(spec) || is_xfx!(spec) || is_fx!(spec);
|
||||
let is_strict_right = spec.is_strict_right();
|
||||
child_desc.get_prec() > priority
|
||||
|| (child_desc.get_prec() == priority && is_strict_right)
|
||||
}
|
||||
DirectedOp::Right(_, cell) => {
|
||||
let (priority, spec) = cell.get();
|
||||
let is_strict_left = is_xfx!(spec) || is_xfy!(spec) || is_xf!(spec);
|
||||
let is_strict_left = spec.is_strict_left();
|
||||
|
||||
if child_desc.get_prec() > priority
|
||||
|| (child_desc.get_prec() == priority && is_strict_left)
|
||||
{
|
||||
true
|
||||
} else if (is_postfix!(spec) || is_infix!(spec)) && !is_postfix!(child_desc.get_spec())
|
||||
} else if (spec.is_postfix() || spec.is_infix()) && !child_desc.get_spec().is_postfix()
|
||||
{
|
||||
*cell != child_desc && child_desc.get_prec() == priority
|
||||
} else {
|
||||
@@ -121,7 +121,7 @@ impl<'a, ElideLists> StackfulPreOrderHeapIter<'a, ElideLists> {
|
||||
None => return false,
|
||||
};
|
||||
|
||||
let mut parent_spec = DirectedOp::Left(atom!("-"), OpDesc::build_with(200, FY as u8));
|
||||
let mut parent_spec = DirectedOp::Left(atom!("-"), OpDesc::build_with(200, FY));
|
||||
|
||||
loop {
|
||||
let cell = self.read_cell(h);
|
||||
@@ -131,7 +131,7 @@ impl<'a, ElideLists> StackfulPreOrderHeapIter<'a, ElideLists> {
|
||||
read_heap_cell!(self.heap[s],
|
||||
(HeapCellValueTag::Atom, (name, _arity)) => {
|
||||
if let Some(spec) = fetch_atom_op_spec(name, None, op_dir) {
|
||||
if is_postfix!(spec.get_spec() as u32) || is_infix!(spec.get_spec() as u32) {
|
||||
if spec.get_spec().is_postfix() || spec.get_spec().is_infix() {
|
||||
if needs_bracketing(spec, &parent_spec) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -592,7 +592,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
}
|
||||
|
||||
fn enqueue_op(&mut self, mut max_depth: usize, name: Atom, spec: OpDesc) {
|
||||
if is_postfix!(spec.get_spec()) {
|
||||
if spec.get_spec().is_postfix() {
|
||||
if self.max_depth_exhausted(max_depth) {
|
||||
self.iter.pop_stack();
|
||||
self.state_stack.push(TokenOrRedirect::Atom(atom!("...")));
|
||||
@@ -610,7 +610,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
right_directed_op,
|
||||
));
|
||||
}
|
||||
} else if is_prefix!(spec.get_spec()) {
|
||||
} else if spec.get_spec().is_prefix() {
|
||||
if self.max_depth_exhausted(max_depth) {
|
||||
self.iter.pop_stack();
|
||||
self.state_stack.push(TokenOrRedirect::Atom(atom!("...")));
|
||||
@@ -639,7 +639,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
|
||||
self.state_stack.push(TokenOrRedirect::Atom(atom!("...")));
|
||||
} else if self.check_max_depth(&mut max_depth) {
|
||||
if is_xfy!(spec.get_spec()) {
|
||||
if matches!(spec.get_spec(), XFY) {
|
||||
let left_directed_op = DirectedOp::Left(name, spec);
|
||||
|
||||
self.state_stack
|
||||
@@ -791,7 +791,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
let dot_atom = atom!(".");
|
||||
|
||||
if let Some(spec) = op_desc {
|
||||
if dot_atom == name && is_infix!(spec.get_spec()) && !self.ignore_ops {
|
||||
if dot_atom == name && spec.get_spec().is_infix() && !self.ignore_ops {
|
||||
self.push_list(max_depth);
|
||||
return true;
|
||||
}
|
||||
@@ -1328,7 +1328,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
|
||||
fn close_list(&mut self, switch: Rc<Cell<(bool, usize)>>) -> Option<Rc<Cell<(bool, usize)>>> {
|
||||
if let Some(TokenOrRedirect::Op(_, op_desc)) = self.state_stack.last() {
|
||||
if is_postfix!(op_desc.get_spec()) || is_infix!(op_desc.get_spec()) {
|
||||
if op_desc.get_spec().is_postfix() || op_desc.get_spec().is_infix() {
|
||||
self.state_stack.push(TokenOrRedirect::ChildCloseList);
|
||||
return None;
|
||||
}
|
||||
@@ -1775,7 +1775,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
TokenOrRedirect::Op(atom, op) => {
|
||||
self.print_op(&atom.as_str());
|
||||
|
||||
if is_prefix!(op.get_spec()) {
|
||||
if op.get_spec().is_prefix() {
|
||||
self.set_parent_of_first_op(Some(DirectedOp::Left(atom, op)));
|
||||
}
|
||||
}
|
||||
@@ -2120,9 +2120,9 @@ mod tests {
|
||||
all_cells_unmarked(&wam.machine_st.heap);
|
||||
|
||||
wam.op_dir
|
||||
.insert((atom!("+"), Fixity::In), OpDesc::build_with(500, YFX as u8));
|
||||
.insert((atom!("+"), Fixity::In), OpDesc::build_with(500, YFX));
|
||||
wam.op_dir
|
||||
.insert((atom!("*"), Fixity::In), OpDesc::build_with(400, YFX as u8));
|
||||
.insert((atom!("*"), Fixity::In), OpDesc::build_with(400, YFX));
|
||||
|
||||
assert_eq!(
|
||||
&wam.parse_and_print_term("[a|[] + b].").unwrap(),
|
||||
@@ -2139,10 +2139,10 @@ mod tests {
|
||||
all_cells_unmarked(&wam.machine_st.heap);
|
||||
|
||||
wam.op_dir
|
||||
.insert((atom!("fy"), Fixity::Pre), OpDesc::build_with(9, FY as u8));
|
||||
.insert((atom!("fy"), Fixity::Pre), OpDesc::build_with(9, FY));
|
||||
|
||||
wam.op_dir
|
||||
.insert((atom!("yf"), Fixity::Post), OpDesc::build_with(9, YF as u8));
|
||||
.insert((atom!("yf"), Fixity::Post), OpDesc::build_with(9, YF));
|
||||
|
||||
assert_eq!(
|
||||
&wam.parse_and_print_term("(fy (fy 1)yf)yf.").unwrap(),
|
||||
|
||||
Reference in New Issue
Block a user