hacky workaround
This commit is contained in:
@@ -166,7 +166,8 @@ pub fn default_op_dir() -> OpDir {
|
||||
|
||||
op_dir.insert((clause_name!(":-"), Fixity::In), (XFX, 1200, module_name.clone()));
|
||||
op_dir.insert((clause_name!(":-"), Fixity::Pre), (FX, 1200, module_name.clone()));
|
||||
op_dir.insert((clause_name!("?-"), Fixity::Pre), (FX, 1200, module_name.clone()));
|
||||
op_dir.insert((clause_name!("?-"), Fixity::Pre), (FX, 1200, module_name.clone()));
|
||||
op_dir.insert((clause_name!(","), Fixity::In), (XFY, 1000, module_name.clone()));
|
||||
|
||||
op_dir
|
||||
}
|
||||
@@ -548,29 +549,6 @@ impl Constant {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Constant {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Constant::Atom(ref atom) =>
|
||||
if atom.as_str().chars().any(|c| ".$'\" ".contains(c)) {
|
||||
write!(f, "'{}'", atom.as_str())
|
||||
} else {
|
||||
write!(f, "{}", atom.as_str())
|
||||
},
|
||||
&Constant::Char(c) =>
|
||||
write!(f, "'{}'", c as u8),
|
||||
&Constant::EmptyList =>
|
||||
write!(f, "[]"),
|
||||
&Constant::Number(ref n) =>
|
||||
write!(f, "{}", n),
|
||||
&Constant::String(ref s) =>
|
||||
write!(f, "\"{}\"", s),
|
||||
&Constant::Usize(integer) =>
|
||||
write!(f, "u{}", integer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub enum Term {
|
||||
AnonVar,
|
||||
|
||||
@@ -229,6 +229,27 @@ impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
|
||||
})
|
||||
}
|
||||
|
||||
fn print_constant(&mut self, c: Constant) {
|
||||
match c {
|
||||
Constant::Char(c) if c == '\n' =>
|
||||
self.outputter.append("'\\n'"),
|
||||
// Constant::Char(c) if c == '\f' =>
|
||||
// self.outputter.append("\\f"),
|
||||
Constant::Char(c) if c == '\r' =>
|
||||
self.outputter.append("'\\r'"),
|
||||
Constant::Char(c) if c == '\t' =>
|
||||
self.outputter.append("'\\t'"),
|
||||
// Constant::Char(c) if c == '\b' =>
|
||||
// self.outputter.append("\\b"),
|
||||
// Constant::Char(c) if c == '\\a' =>
|
||||
// self.outputter.append("\a"),
|
||||
// Constant::Char(c) if c == '\\v' =>
|
||||
// self.outputter.append("\\v"),
|
||||
_ =>
|
||||
self.outputter.append(format!("{}", c).as_str())
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_heap_term(&mut self, iter: &mut HCPreOrderIterator)
|
||||
{
|
||||
let heap_val = match self.check_for_seen(iter) {
|
||||
@@ -246,7 +267,7 @@ impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
|
||||
self.outputter.append("[]");
|
||||
},
|
||||
HeapCellValue::Addr(Addr::Con(c)) =>
|
||||
self.outputter.append(format!("{}", c).as_str()),
|
||||
self.print_constant(c),
|
||||
HeapCellValue::Addr(Addr::Lis(_)) => {
|
||||
let cell = Rc::new(Cell::new(true));
|
||||
|
||||
|
||||
@@ -18,6 +18,29 @@ impl fmt::Display for IndexPtr {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Constant {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Constant::Atom(ref atom) =>
|
||||
if atom.as_str().chars().any(|c| ".$'\" ".contains(c)) {
|
||||
write!(f, "'{}'", atom.as_str())
|
||||
} else {
|
||||
write!(f, "{}", atom.as_str())
|
||||
},
|
||||
&Constant::Char(c) =>
|
||||
write!(f, "'{}'", c as u8),
|
||||
&Constant::EmptyList =>
|
||||
write!(f, "[]"),
|
||||
&Constant::Number(ref n) =>
|
||||
write!(f, "{}", n),
|
||||
&Constant::String(ref s) =>
|
||||
write!(f, "\"{}\"", s),
|
||||
&Constant::Usize(integer) =>
|
||||
write!(f, "u{}", integer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ClauseName {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.as_str())
|
||||
|
||||
@@ -7,6 +7,15 @@
|
||||
(\==)/2, (@=<)/2, (@>=)/2, (@<)/2, (@>)/2, (=@=)/2, (\=@=)/2,
|
||||
catch/3, throw/1, true/0, false/0]).
|
||||
|
||||
','(G1, G2) :- '$get_cp'(B), ','(G1, G2, B).
|
||||
|
||||
','(!, ','(G1, G2), B) :- '$set_cp'(B), ','(G1, G2, B).
|
||||
','(!, !, B) :- '$set_cp'(B).
|
||||
','(!, G, B) :- '$set_cp'(B), G.
|
||||
','(G, ','(G2, G3), B) :- !, G, ','(G2, G3, B).
|
||||
','(G, !, B) :- !, G, '$set_cp'(B).
|
||||
','(G1, G2, _) :- G1, G2.
|
||||
|
||||
% arithmetic operators.
|
||||
:- op(700, xfx, is).
|
||||
:- op(500, yfx, +).
|
||||
@@ -63,15 +72,6 @@ false :- '$fail'.
|
||||
|
||||
% control operators.
|
||||
|
||||
','(G1, G2) :- '$get_cp'(B), ','(G1, G2, B).
|
||||
|
||||
','(!, ','(G1, G2), B) :- '$set_cp'(B), ','(G1, G2, B).
|
||||
','(!, !, B) :- '$set_cp'(B).
|
||||
','(!, G, B) :- '$set_cp'(B), G.
|
||||
','(G, ','(G2, G3), B) :- !, G, ','(G2, G3, B).
|
||||
','(G, !, B) :- !, G, '$set_cp'(B).
|
||||
','(G1, G2, _) :- G1, G2.
|
||||
|
||||
;(G1, G2) :- '$get_cp'(B), ;(G1, G2, B).
|
||||
|
||||
;(G1, G4, B) :- compound(G1), G1 = ->(G2, G3), (G2 -> G3 ; '$set_cp'(B), G4).
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
macro_rules! clause_name {
|
||||
($name: expr, $tbl: expr) => (
|
||||
ClauseName::User(TabledRc::new($name, $tbl.clone()))
|
||||
) ;
|
||||
($name: expr) => (
|
||||
ClauseName::BuiltIn($name)
|
||||
)
|
||||
|
||||
Submodule src/prolog/parser updated: d52da58a5d...52034e3a66
Reference in New Issue
Block a user