properly handle character controls from ASCII to UTF-8, re: #48
This commit is contained in:
@@ -143,7 +143,7 @@ impl HCValueFormatter for WriteqFormatter {
|
|||||||
|
|
||||||
// 7.10.4
|
// 7.10.4
|
||||||
match iter.machine_st.store(iter.machine_st.deref(addr)) {
|
match iter.machine_st.store(iter.machine_st.deref(addr)) {
|
||||||
Addr::Con(Constant::Number(Number::Integer(n))) => {
|
Addr::Con(Constant::Number(Number::Integer(ref n))) if !n.is_negative() => {
|
||||||
iter.stack().pop();
|
iter.stack().pop();
|
||||||
|
|
||||||
let i = n.mod_floor(&BigInt::from(26)).to_usize().unwrap();
|
let i = n.mod_floor(&BigInt::from(26)).to_usize().unwrap();
|
||||||
@@ -285,42 +285,47 @@ impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
|
|||||||
self.outputter.append(atom.as_str());
|
self.outputter.append(atom.as_str());
|
||||||
} else {
|
} else {
|
||||||
self.outputter.push_char('\'');
|
self.outputter.push_char('\'');
|
||||||
self.outputter.append(atom.as_str());
|
|
||||||
|
for c in atom.as_str().chars() {
|
||||||
|
self.print_char(c);
|
||||||
|
}
|
||||||
|
|
||||||
self.outputter.push_char('\'');
|
self.outputter.push_char('\'');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_char(&mut self, c: char) {
|
fn print_char(&mut self, c: char) {
|
||||||
if non_quoted_token(c) {
|
if c == '\n' {
|
||||||
self.outputter.push_char(c);
|
self.outputter.append("\\n");
|
||||||
|
} else if c == '\r' {
|
||||||
|
self.outputter.append("\\r");
|
||||||
|
} else if c == '\t' {
|
||||||
|
self.outputter.append("\\t");
|
||||||
|
} else if c == '\u{0b}' { // UTF-8 vertical tab
|
||||||
|
self.outputter.append("\\v");
|
||||||
|
} else if c == '\u{0c}' { // UTF-8 form feed
|
||||||
|
self.outputter.append("\\f");
|
||||||
|
} else if c == '\u{08}' { // UTF-8 backspace
|
||||||
|
self.outputter.append("\\b");
|
||||||
|
} else if c == '\u{07}' { // UTF-8 alert
|
||||||
|
self.outputter.append("\\a");
|
||||||
} else {
|
} else {
|
||||||
self.outputter.push_char('\'');
|
|
||||||
self.outputter.push_char(c);
|
self.outputter.push_char(c);
|
||||||
self.outputter.push_char('\'');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_constant(&mut self, c: Constant) {
|
fn print_constant(&mut self, c: Constant) {
|
||||||
match c {
|
match c {
|
||||||
Constant::Atom(ref atom) =>
|
Constant::Atom(ref atom) =>
|
||||||
self.print_atom(atom),
|
self.print_atom(atom),
|
||||||
Constant::Char(c) if c == '\n' =>
|
Constant::Char(c) if non_quoted_token(c) =>
|
||||||
self.outputter.append("'\\n'"),
|
|
||||||
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 == '\f' =>
|
|
||||||
// self.outputter.append("\\f"),
|
|
||||||
// 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"),
|
|
||||||
Constant::Char(c) =>
|
|
||||||
self.print_char(c),
|
self.print_char(c),
|
||||||
|
Constant::Char(c) => {
|
||||||
|
self.outputter.push_char('\'');
|
||||||
|
self.print_char(c);
|
||||||
|
self.outputter.push_char('\'');
|
||||||
|
},
|
||||||
Constant::EmptyList =>
|
Constant::EmptyList =>
|
||||||
self.outputter.append("[]"),
|
self.outputter.append("[]"),
|
||||||
Constant::Number(Number::Float(fl)) =>
|
Constant::Number(Number::Float(fl)) =>
|
||||||
|
|||||||
Submodule src/prolog/parser updated: b663bce82d...b23670b232
15
src/tests.rs
15
src/tests.rs
@@ -1622,7 +1622,20 @@ fn test_queries_on_builtins()
|
|||||||
assert_prolog_success!(&mut wam, "?- call_with_inference_limit((setup_call_cleanup(S=1,(G=2;fail),writeq(S+G>B)), B=3, !), 100, R).",
|
assert_prolog_success!(&mut wam, "?- call_with_inference_limit((setup_call_cleanup(S=1,(G=2;fail),writeq(S+G>B)), B=3, !), 100, R).",
|
||||||
[["G = 2", "B = 3", "R = !", "S = 1"]]);
|
[["G = 2", "B = 3", "R = !", "S = 1"]]);
|
||||||
assert_prolog_success!(&mut wam, "?- call_with_inference_limit((setup_call_cleanup(S=1,(G=2;fail),writeq(S+G>B)), B=3, !), 10, R).",
|
assert_prolog_success!(&mut wam, "?- call_with_inference_limit((setup_call_cleanup(S=1,(G=2;fail),writeq(S+G>B)), B=3, !), 10, R).",
|
||||||
[["S = _1", "G = _4", "B = _14", "R = inference_limit_exceeded"]]);
|
[["S = _1", "G = _4", "B = _14", "R = inference_limit_exceeded"]]);
|
||||||
|
|
||||||
|
assert_prolog_success!(&mut wam, "?- X = '\\n'.",
|
||||||
|
[["X = '\\n'"]]);
|
||||||
|
assert_prolog_success!(&mut wam, "?- X = '\\b'.",
|
||||||
|
[["X = '\\b'"]]);
|
||||||
|
assert_prolog_success!(&mut wam, "?- X = '\\v'.",
|
||||||
|
[["X = '\\v'"]]);
|
||||||
|
assert_prolog_success!(&mut wam, "?- X = '\\a'.",
|
||||||
|
[["X = '\\a'"]]);
|
||||||
|
assert_prolog_success!(&mut wam, "?- X = '\\f'.",
|
||||||
|
[["X = '\\f'"]]);
|
||||||
|
assert_prolog_success!(&mut wam, "?- X = '\\b\\r\\f\\t\\n'.",
|
||||||
|
[["X = '\\b\\r\\f\\t\\n'"]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user