Commit 09fe570d authored by Jeff Smits's avatar Jeff Smits

Propagate fixed string escaping in aterm crate

parent 052ea781
......@@ -2,7 +2,7 @@
name = "strs"
version = "0.1.0"
dependencies = [
"aterm 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
"aterm 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"linked-hash-map 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -29,7 +29,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "aterm"
version = "0.17.1"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -307,7 +307,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699"
"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
"checksum aterm 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2861a3e1dd1e752eb5f0563f4576dfb79cd046b8e121304b02e48c67375d3039"
"checksum aterm 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a0f2df2694d64af77e71242cfb2e0d421f4b95c0d9c07d0d0d8a1a4c4adbfd3"
"checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159"
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
"checksum clap 2.23.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f57e9b63057a545ad2ecd773ea61e49422ed1b1d63d74d5da5ecaee55b3396cd"
......
......@@ -13,7 +13,7 @@ version = "0.1.0"
phf_codegen = "0.7.21"
[dependencies]
aterm = "0.17.1"
aterm = "0.18.1"
fnv = "1.0.5"
linked-hash-map = "0.4.2"
phf = "0.7.21"
......
......@@ -35,7 +35,7 @@ fn main() {
let opt = Opt::from_args();
match exec(&opt.program, &opt.output) {
Err(e) => {
eprintln!("{}", e.description());
eprintln!("{} ({})", e, e.description());
process::exit(1)
},
Ok(()) => {},
......
......@@ -182,8 +182,16 @@ impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for ImportModName<'s> {
impl<'s> ATermWrite for ImportModName<'s> {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
match *self {
ImportModName::Import(name) => write!(writer, "Import({:?})", name),
ImportModName::ImportWildcard(name) => write!(writer, "ImportWildcard({:?})", name),
ImportModName::Import(name) => {
write!(writer, "Import(")?;
name.to_ascii(writer)?;
write!(writer, ")")
},
ImportModName::ImportWildcard(name) => {
write!(writer, "ImportWildcard(")?;
name.to_ascii(writer)?;
write!(writer, ")")
},
}
}
}
......@@ -313,10 +321,20 @@ impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for Sort<'s> {
impl<'s> ATermWrite for Sort<'s> {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
match *self {
Sort::SortVar(id) => write!(writer, "SortVar({:?})", id),
Sort::SortNoArgs(id) => write!(writer, "SortNoArgs({:?})", id),
Sort::SortVar(id) => {
write!(writer, "SortVar(")?;
id.to_ascii(writer)?;
write!(writer, ")")
},
Sort::SortNoArgs(id) => {
write!(writer, "SortNoArgs(")?;
id.to_ascii(writer)?;
write!(writer, ")")
}
Sort::Sort(id, ref args) => {
write!(writer, "Sort({:?},[", id)?;
write!(writer, "Sort(")?;
id.to_ascii(writer)?;
write!(writer, ",[")?;
args.to_ascii(writer)?;
write!(writer, "])")
}
......@@ -399,12 +417,16 @@ impl<'s> ATermWrite for OpDecl<'s> {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
match *self {
OpDecl::OpDecl(s, ref ty) => {
write!(writer, "OpDecl({:?},", s)?;
write!(writer, "OpDecl(")?;
s.to_ascii(writer)?;
write!(writer, ",")?;
ty.to_ascii(writer)?;
write!(writer, ")")
}
OpDecl::OpDeclQ(s, ref ty) => {
write!(writer, "OpDeclQ({:?},", s)?;
write!(writer, "OpDeclQ(")?;
s.to_ascii(writer)?;
write!(writer, ",")?;
ty.to_ascii(writer)?;
write!(writer, ")")
}
......@@ -414,12 +436,16 @@ impl<'s> ATermWrite for OpDecl<'s> {
write!(writer, ")")
}
OpDecl::ExtOpDecl(s, ref ty) => {
write!(writer, "ExtOpDecl({:?},", s)?;
write!(writer, "ExtOpDecl(")?;
s.to_ascii(writer)?;
write!(writer, ",")?;
ty.to_ascii(writer)?;
write!(writer, ")")
}
OpDecl::ExtOpDeclQ(s, ref ty) => {
write!(writer, "ExtOpDeclQ({:?},", s)?;
write!(writer, "ExtOpDeclQ(")?;
s.to_ascii(writer)?;
write!(writer, ",")?;
ty.to_ascii(writer)?;
write!(writer, ")")
}
......@@ -862,7 +888,9 @@ impl<'s, 'a> TryFrom<&'a ATermRef<'s>> for VarDec<'s> {
impl<'s> ATermWrite for VarDec<'s> {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
write!(writer, "VarDec({:?},", self.0)?;
write!(writer, "VarDec(")?;
self.0.to_ascii(writer)?;
write!(writer, ",")?;
self.1.to_ascii(writer)?;
write!(writer, ")")
}
......
......@@ -143,7 +143,9 @@ impl<'a> TryFrom<ctree::Def<'a>> for Def<'a> {
impl<'a> ATermWrite for Def<'a> {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
write!(writer, "SDefT({:?},[", self.name)?;
write!(writer, "SDefT(")?;
self.name.to_ascii(writer)?;
write!(writer, ",[")?;
let term_ty = ctree::Type::ConstType(ctree::Sort::Sort("Term", Vec::new()));
self.sargs
.iter()
......@@ -357,14 +359,18 @@ impl<'a> ATermWrite for Strategy<'a> {
write!(writer, ")")
}
Strategy::CallT(name, ref sargs, ref targs) => {
write!(writer, "CallT(SVar({:?}),[", name)?;
write!(writer, "CallT(SVar(")?;
name.to_ascii(writer)?;
write!(writer, "),[")?;
sargs.to_ascii(writer)?;
write!(writer, "],[")?;
targs.to_ascii(writer)?;
write!(writer, "])")
}
Strategy::CallDynamic(name, ref sargs, ref targs) => {
write!(writer, "CallDynamic({:?},[", name)?;
write!(writer, "CallDynamic(")?;
name.to_ascii(writer)?;
write!(writer, ",[")?;
sargs.to_ascii(writer)?;
write!(writer, "],[")?;
targs.to_ascii(writer)?;
......@@ -401,8 +407,7 @@ impl<'a> ATermWrite for Strategy<'a> {
strat.to_ascii(writer)?;
}
}
let closing = str::repeat(")", strategies.len()-1);
write!(writer, "{}", closing)
write!(writer, "{}", str::repeat(")", strategies.len()-1))
}
Strategy::GuardedLChoice(ref pairs, ref final_else) => {
for &(ref cond, ref then) in pairs.iter() {
......@@ -413,8 +418,7 @@ impl<'a> ATermWrite for Strategy<'a> {
write!(writer, ",")?;
}
final_else.to_ascii(writer)?;
let closing = str::repeat(")", pairs.len());
write!(writer, "{}", closing)
write!(writer, "{}", str::repeat(")", pairs.len()))
}
Strategy::ConsMatch(ref map, ref final_else) => {
for strat in map.values() {
......@@ -423,11 +427,12 @@ impl<'a> ATermWrite for Strategy<'a> {
write!(writer, ",Id,")?;
}
final_else.to_ascii(writer)?;
let closing = str::repeat(")", map.len());
write!(writer, "{}", closing)
write!(writer, "{}", str::repeat(")", map.len()))
}
Strategy::PrimT(name, ref sargs, ref targs) => {
write!(writer, "PrimT({:?},[", name)?;
write!(writer, "PrimT(")?;
name.to_ascii(writer)?;
write!(writer, ",[")?;
sargs.to_ascii(writer)?;
write!(writer, "],[")?;
targs.to_ascii(writer)?;
......@@ -448,7 +453,11 @@ impl<'a> ATermWrite for Strategy<'a> {
sarg.to_ascii(writer)?;
write!(writer, ")")
}
Strategy::ImportTerm(ref name) => write!(writer, "ImportTerm({:?})", name),
Strategy::ImportTerm(ref name) => {
write!(writer, "ImportTerm(")?;
name.to_ascii(writer)?;
write!(writer, ")")
},
}
}
}
......@@ -588,7 +597,11 @@ impl<'a> ATermWrite for BuildTerm<'a> {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
fn not_anno_wrapped<'a, W: fmt::Write>(term: &BuildTerm<'a>, writer: &mut W) -> fmt::Result {
match *term {
BuildTerm::Var(name) => write!(writer, "Var({:?})", name),
BuildTerm::Var(name) => {
write!(writer, "Var(")?;
name.to_ascii(writer)?;
write!(writer, ")")
}
BuildTerm::Anno(ref term, ref annos) => {
write!(writer, "Anno(")?;
not_anno_wrapped(term, writer)?;
......@@ -598,9 +611,15 @@ impl<'a> ATermWrite for BuildTerm<'a> {
}
BuildTerm::Int(i) => write!(writer, "Int({:?})", i.to_string()),
BuildTerm::Real(BrokenF32(f)) => write!(writer, "Real({:?})", f.to_string()),
BuildTerm::Str(string) => write!(writer, "Str({:?})", string),
BuildTerm::Str(string) => {
write!(writer, "Str(")?;
string.to_ascii(writer)?;
write!(writer, ")")
}
BuildTerm::Op(cons, ref children) => {
write!(writer, "Op({:?},[", cons)?;
write!(writer, "Op(")?;
cons.to_ascii(writer)?;
write!(writer, ",[")?;
children.to_ascii(writer)?;
write!(writer, "])")
}
......@@ -615,7 +634,11 @@ impl<'a> ATermWrite for BuildTerm<'a> {
}
}
match *self {
BuildTerm::Var(name) => write!(writer, "Var({:?})", name),
BuildTerm::Var(name) => {
write!(writer, "Var(")?;
name.to_ascii(writer)?;
write!(writer, ")")
}
BuildTerm::Anno(ref term, ref annos) => {
write!(writer, "Anno(")?;
not_anno_wrapped(term, writer)?;
......@@ -625,9 +648,15 @@ impl<'a> ATermWrite for BuildTerm<'a> {
}
BuildTerm::Int(i) => write!(writer, "Anno(Int({:?}),Op(\"Nil\",[]))", i.to_string()),
BuildTerm::Real(BrokenF32(f)) => write!(writer, "Anno(Real({:?}),Op(\"Nil\",[]))", f.to_string()),
BuildTerm::Str(string) => write!(writer, "Anno(Str({:?}),Op(\"Nil\",[]))", string),
BuildTerm::Str(string) => {
write!(writer, "Anno(Str(")?;
string.to_ascii(writer)?;
write!(writer, "),Op(\"Nil\",[]))")
}
BuildTerm::Op(cons, ref children) => {
write!(writer, "Anno(Op({:?},[", cons)?;
write!(writer, "Anno(Op(")?;
cons.to_ascii(writer)?;
write!(writer, ",[")?;
children.to_ascii(writer)?;
write!(writer, "]),Op(\"Nil\",[]))")
}
......@@ -751,7 +780,11 @@ impl<'a> ATermWrite for MatchTerm<'a> {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
fn not_anno_wrapped<'a, W: fmt::Write>(term: &MatchTerm<'a>, writer: &mut W) -> fmt::Result {
match *term {
MatchTerm::Var(name) => write!(writer, "Var({:?})", name),
MatchTerm::Var(name) => {
write!(writer, "Var(")?;
name.to_ascii(writer)?;
write!(writer, ")")
}
MatchTerm::Wld => write!(writer, "Wld"),
MatchTerm::Anno(ref term, ref annos) => {
write!(writer, "Anno(")?;
......@@ -762,14 +795,22 @@ impl<'a> ATermWrite for MatchTerm<'a> {
}
MatchTerm::Int(i) => write!(writer, "Int({:?})", i.to_string()),
MatchTerm::Real(BrokenF32(f)) => write!(writer, "Real({:?})", f.to_string()),
MatchTerm::Str(string) => write!(writer, "Str({:?})", string),
MatchTerm::Str(string) => {
write!(writer, "Str(")?;
string.to_ascii(writer)?;
write!(writer, ")")
}
MatchTerm::Op(cons, ref children) => {
write!(writer, "Op({:?},[", cons)?;
write!(writer, "Op(")?;
cons.to_ascii(writer)?;
write!(writer, ",[")?;
children.to_ascii(writer)?;
write!(writer, "])")
}
MatchTerm::As(name, ref term) => {
write!(writer, "As(Var({:?}),", name)?;
write!(writer, "As(Var(")?;
name.to_ascii(writer)?;
write!(writer, "),")?;
term.to_ascii(writer)?;
write!(writer, ")")
}
......@@ -784,7 +825,11 @@ impl<'a> ATermWrite for MatchTerm<'a> {
}
}
match *self {
MatchTerm::Var(name) => write!(writer, "Var({:?})", name),
MatchTerm::Var(name) => {
write!(writer, "Var(")?;
name.to_ascii(writer)?;
write!(writer, ")")
}
MatchTerm::Wld => write!(writer, "Wld"),
MatchTerm::Anno(ref term, ref annos) => {
write!(writer, "Anno(")?;
......@@ -795,14 +840,22 @@ impl<'a> ATermWrite for MatchTerm<'a> {
}
MatchTerm::Int(i) => write!(writer, "Anno(Int({:?}),Wld)", i.to_string()),
MatchTerm::Real(BrokenF32(f)) => write!(writer, "Anno(Real({:?}),Wld)", f.to_string()),
MatchTerm::Str(string) => write!(writer, "Anno(Str({:?}),Wld)", string),
MatchTerm::Str(string) => {
write!(writer, "Anno(Str(")?;
string.to_ascii(writer)?;
write!(writer, "),Wld)")
},
MatchTerm::Op(cons, ref children) => {
write!(writer, "Anno(Op({:?},[", cons)?;
write!(writer, "Anno(Op(")?;
cons.to_ascii(writer)?;
write!(writer, ",[")?;
children.to_ascii(writer)?;
write!(writer, "]),Wld)")
}
MatchTerm::As(name, ref term) => {
write!(writer, "As(Var({:?}),", name)?;
write!(writer, "As(Var(")?;
name.to_ascii(writer)?;
write!(writer, "),")?;
term.to_ascii(writer)?;
write!(writer, ")")
}
......@@ -869,7 +922,9 @@ pub mod full_ctree {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
match *self {
Module::Module(name, ref decls) => {
write!(writer, "Module({:?},[", name)?;
write!(writer, "Module(")?;
name.to_ascii(writer)?;
write!(writer, ",[")?;
decls.to_ascii(writer)?;
write!(writer, "])")
}
......@@ -959,7 +1014,9 @@ pub mod full_ctree {
fn to_ascii<W: fmt::Write>(&self, writer: &mut W) -> fmt::Result {
match *self {
Def::SDefT(name, ref sargs, ref targs, ref body) => {
write!(writer, "SDefT({:?},[", name)?;
write!(writer, "SDefT(")?;
name.to_ascii(writer)?;
write!(writer, ",[")?;
sargs.to_ascii(writer)?;
write!(writer, "],[")?;
targs.to_ascii(writer)?;
......@@ -968,7 +1025,9 @@ pub mod full_ctree {
write!(writer, ")")
}
Def::ExtSDefInl(name, ref sargs, ref targs, ref body) => {
write!(writer, "ExtSDefInl({:?},[", name)?;
write!(writer, "ExtSDefInl(")?;
name.to_ascii(writer)?;
write!(writer, ",[")?;
sargs.to_ascii(writer)?;
write!(writer, "],[")?;
targs.to_ascii(writer)?;
......@@ -978,7 +1037,9 @@ pub mod full_ctree {
}
Def::ExtSDef(ref opt_name, ref sargs, ref targs) => {
if let Some(name) = *opt_name {
write!(writer, "ExtSDef({:?},[", name)?;
write!(writer, "ExtSDef(")?;
name.to_ascii(writer)?;
write!(writer, ",[")?;
} else {
write!(writer, "ExtSDef([")?;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment