correct comma printing
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "scryer-prolog"
|
name = "scryer-prolog"
|
||||||
version = "0.8.29"
|
version = "0.8.30"
|
||||||
authors = ["Mark Thom <markjordanthom@gmail.com>"]
|
authors = ["Mark Thom <markjordanthom@gmail.com>"]
|
||||||
repository = "https://github.com/mthom/scryer-prolog"
|
repository = "https://github.com/mthom/scryer-prolog"
|
||||||
description = "A modern Prolog implementation written mostly in Rust."
|
description = "A modern Prolog implementation written mostly in Rust."
|
||||||
@@ -14,7 +14,7 @@ cfg-if = "0.1.7"
|
|||||||
downcast = "0.10.0"
|
downcast = "0.10.0"
|
||||||
num = "0.2"
|
num = "0.2"
|
||||||
ordered-float = "0.5.0"
|
ordered-float = "0.5.0"
|
||||||
prolog_parser = "0.8.7"
|
prolog_parser = "0.8.8"
|
||||||
readline_rs_compat = { version = "0.1.7", optional = true }
|
readline_rs_compat = { version = "0.1.7", optional = true }
|
||||||
ref_thread_local = "0.0.0"
|
ref_thread_local = "0.0.0"
|
||||||
|
|
||||||
|
|||||||
@@ -537,31 +537,42 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_atom(&mut self, atom: &ClauseName, spec: Option<(usize, Specifier)>) {
|
fn print_atom(&mut self, atom: &ClauseName) {
|
||||||
push_space_if_amb!(self, atom.as_str(), {
|
push_space_if_amb!(self, atom.as_str(), {
|
||||||
match atom.as_str() {
|
match atom.as_str() {
|
||||||
"" => self.append_str("''"),
|
"" => self.append_str("''"),
|
||||||
"," if spec.is_some() => self.append_str(atom.as_str()),
|
//"," => self.append_str("(,)"),
|
||||||
";" | "!" => self.append_str(atom.as_str()),
|
s => self.print_op_addendum(s)
|
||||||
s => if !self.quoted || non_quoted_token(s.chars()) {
|
|
||||||
self.append_str(atom.as_str());
|
|
||||||
} else {
|
|
||||||
if self.quoted {
|
|
||||||
self.push_char('\'');
|
|
||||||
}
|
|
||||||
|
|
||||||
for c in atom.as_str().chars() {
|
|
||||||
self.print_char(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.quoted {
|
|
||||||
self.push_char('\'');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_op_addendum(&mut self, atom: &str) {
|
||||||
|
if !self.quoted || non_quoted_token(atom.chars()) {
|
||||||
|
self.append_str(atom);
|
||||||
|
} else {
|
||||||
|
if self.quoted {
|
||||||
|
self.push_char('\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
for c in atom.chars() {
|
||||||
|
self.print_char(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.quoted {
|
||||||
|
self.push_char('\'');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_op(&mut self, atom: &str) {
|
||||||
|
if atom == "," {
|
||||||
|
self.push_char(',');
|
||||||
|
} else {
|
||||||
|
self.print_op_addendum(atom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn print_char(&mut self, c: char) {
|
fn print_char(&mut self, c: char) {
|
||||||
match c {
|
match c {
|
||||||
'\n' => self.append_str("\\n"),
|
'\n' => self.append_str("\\n"),
|
||||||
@@ -617,7 +628,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
|||||||
|
|
||||||
fn print_constant(&mut self, c: Constant, op: &Option<DirectedOp>) {
|
fn print_constant(&mut self, c: Constant, op: &Option<DirectedOp>) {
|
||||||
match c {
|
match c {
|
||||||
Constant::Atom(ref atom, Some(spec)) => {
|
Constant::Atom(ref atom, Some(_)) => {
|
||||||
if let Some(ref op) = op {
|
if let Some(ref op) = op {
|
||||||
if self.outputter.ends_with(&format!(" {}", op.as_str())) {
|
if self.outputter.ends_with(&format!(" {}", op.as_str())) {
|
||||||
self.push_char(' ');
|
self.push_char(' ');
|
||||||
@@ -626,7 +637,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
|||||||
self.push_char('(');
|
self.push_char('(');
|
||||||
}
|
}
|
||||||
|
|
||||||
self.print_atom(atom, Some(spec));
|
self.print_atom(atom);
|
||||||
|
|
||||||
if op.is_some() {
|
if op.is_some() {
|
||||||
self.push_char(')');
|
self.push_char(')');
|
||||||
@@ -634,7 +645,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
|||||||
},
|
},
|
||||||
Constant::Atom(ref atom, None) =>
|
Constant::Atom(ref atom, None) =>
|
||||||
push_space_if_amb!(self, atom.as_str(), {
|
push_space_if_amb!(self, atom.as_str(), {
|
||||||
self.print_atom(atom, None);
|
self.print_atom(atom);
|
||||||
}),
|
}),
|
||||||
Constant::Char(c) if non_quoted_token(once(c)) =>
|
Constant::Char(c) if non_quoted_token(once(c)) =>
|
||||||
self.print_char(c),
|
self.print_char(c),
|
||||||
@@ -772,9 +783,9 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
|||||||
if let Some(loc_data) = self.state_stack.pop() {
|
if let Some(loc_data) = self.state_stack.pop() {
|
||||||
match loc_data {
|
match loc_data {
|
||||||
TokenOrRedirect::Atom(atom) =>
|
TokenOrRedirect::Atom(atom) =>
|
||||||
self.print_atom(&atom, None),
|
self.print_atom(&atom),
|
||||||
TokenOrRedirect::Op(atom, spec) =>
|
TokenOrRedirect::Op(atom, _) =>
|
||||||
self.print_atom(&atom, Some(spec)),
|
self.print_op(atom.as_str()),
|
||||||
TokenOrRedirect::NumberedVar(num_var) =>
|
TokenOrRedirect::NumberedVar(num_var) =>
|
||||||
self.append_str(num_var.as_str()),
|
self.append_str(num_var.as_str()),
|
||||||
TokenOrRedirect::CompositeRedirect(op) =>
|
TokenOrRedirect::CompositeRedirect(op) =>
|
||||||
|
|||||||
@@ -559,17 +559,8 @@ impl ListingCompiler {
|
|||||||
|
|
||||||
get_desc(op_decl.name(), comp_ops)
|
get_desc(op_decl.name(), comp_ops)
|
||||||
};
|
};
|
||||||
|
|
||||||
if op_decl.0 == 0 {
|
op_decl.submit(self.get_module_name(), existing_desc, &mut indices.op_dir)
|
||||||
// remove all instances of the operator.
|
|
||||||
if self.module.is_none() {
|
|
||||||
op_decl.remove(&mut wam_indices.op_dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
op_decl.submit(self.get_module_name(), existing_desc, &mut indices.op_dir)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Declaration::UseModule(name) =>
|
Declaration::UseModule(name) =>
|
||||||
self.use_module(name, code_repo, flags, wam_indices, indices),
|
self.use_module(name, code_repo, flags, wam_indices, indices),
|
||||||
|
|||||||
@@ -188,7 +188,10 @@ impl MachineState {
|
|||||||
where Outputter: HCValueOutputter
|
where Outputter: HCValueOutputter
|
||||||
{
|
{
|
||||||
let mut printer = HCPrinter::from_heap_locs(&self, output, var_dict);
|
let mut printer = HCPrinter::from_heap_locs(&self, output, var_dict);
|
||||||
|
|
||||||
printer.see_all_locs();
|
printer.see_all_locs();
|
||||||
|
printer.quoted = true;
|
||||||
|
|
||||||
printer.print(addr)
|
printer.print(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -272,7 +272,13 @@ impl Machine {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn add_batched_ops(&mut self, op_dir: OpDir) {
|
pub fn add_batched_ops(&mut self, op_dir: OpDir) {
|
||||||
self.indices.op_dir.extend(op_dir.into_iter());
|
for ((name, fixity), info) in op_dir {
|
||||||
|
if info.1 == 0 {
|
||||||
|
self.indices.op_dir.remove(&(name, fixity));
|
||||||
|
} else {
|
||||||
|
self.indices.op_dir.insert((name, fixity), info);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
Reference in New Issue
Block a user