use std::collections::BTreeMap;
-use crate::{atom_table, StreamConfig};
use crate::machine::machine_indices::VarKey;
use crate::machine::mock_wam::CompositeOpDir;
use crate::machine::{BREAK_FROM_DISPATCH_LOOP_LOC, LIB_QUERY_SUCCESS};
use crate::parser::ast::{Var, VarPtr};
use crate::parser::parser::{Parser, Tokens};
use crate::read::{write_term_to_heap, TermWriteResult};
+use crate::{atom_table, StreamConfig};
use indexmap::IndexMap;
use super::{
- streams::Stream, Atom, AtomCell, HeapCellValue, HeapCellValueTag, Machine, MachineConfig,
- LeafAnswer, PrologTerm,
+ streams::Stream, Atom, AtomCell, HeapCellValue, HeapCellValueTag, LeafAnswer, Machine,
+ MachineConfig, PrologTerm,
};
pub struct QueryState<'a> {
// choice point, so we should break.
self.machine.machine_st.backtrack();
- Some(Ok(LeafAnswer::LeafAnswer { bindings: bindings, residual_goals: vec![] }))
+ Some(Ok(LeafAnswer::LeafAnswer {
+ bindings: bindings,
+ residual_goals: vec![],
+ }))
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PrologTerm {
+ /// An arbitrary precision integer.
Integer(Integer),
+ /// An arbitrary precision rational.
Rational(Rational),
+ /// A float.
Float(OrderedFloat<f64>),
+ /// A Prolog atom.
Atom(String),
+ /// A Prolog string.
+ ///
+ /// In particular, this represents Prolog lists of characters.
String(String),
+ /// A Prolog list.
List(Vec<PrologTerm>),
+ /// A Prolog compound term.
Compound(String, Vec<PrologTerm>),
+ /// A Prolog variable.
Var(String),
}
/// Creates a conjunction, giving `None` if empty.
pub fn try_conjunction(value: impl IntoIterator<Item = PrologTerm>) -> Option<Self> {
let mut iter = value.into_iter();
- iter.next()
- .map(|first| {
- PrologTerm::try_conjunction(iter)
- .map(|rest| PrologTerm::compound(",", [first.clone(), rest]))
- .unwrap_or(first)
- })
+ iter.next().map(|first| {
+ PrologTerm::try_conjunction(iter)
+ .map(|rest| PrologTerm::compound(",", [first.clone(), rest]))
+ .unwrap_or(first)
+ })
}
/// Creates a disjunction, giving the atom `false` if empty.
/// Creates a disjunction, giving `None` if empty.
pub fn try_disjunction(value: impl IntoIterator<Item = PrologTerm>) -> Option<Self> {
let mut iter = value.into_iter();
- iter.next()
- .map(|first| {
- PrologTerm::try_disjunction(iter)
- .map(|rest| PrologTerm::compound(";", [first.clone(), rest]))
- .unwrap_or(first)
- })
+ iter.next().map(|first| {
+ PrologTerm::try_disjunction(iter)
+ .map(|rest| PrologTerm::compound(";", [first.clone(), rest]))
+ .unwrap_or(first)
+ })
}
}
LeafAnswer::True => PrologTerm::atom("true"),
LeafAnswer::False => PrologTerm::atom("false"),
LeafAnswer::Exception(inner) => match inner.clone() {
- PrologTerm::Compound(functor, args) if functor == "error" && args.len() == 2 => inner,
+ PrologTerm::Compound(functor, args) if functor == "error" && args.len() == 2 => {
+ inner
+ }
_ => PrologTerm::compound("throw", [inner]),
},
- LeafAnswer::LeafAnswer { bindings: _, residual_goals: _ } => {
+ LeafAnswer::LeafAnswer {
+ bindings: _,
+ residual_goals: _,
+ } => {
todo!()
- },
+ }
}
}
}