/* echo */
| ECHO_TOK
- ( simpleSymbolicExpr[s]
+ ( str[s, true]
{ cmd->reset(new EchoCommand(s)); }
| { cmd->reset(new EchoCommand()); }
)
void Smt2Printer::toStreamCmdEcho(std::ostream& out,
const std::string& output) const
{
- std::string s = output;
- // escape all double-quotes
- size_t pos = 0;
- while ((pos = s.find('"', pos)) != string::npos)
- {
- s.replace(pos, 1, "\"\"");
- pos += 2;
- }
- out << "(echo \"" << s << "\")" << std::endl;
+ out << "(echo " << cvc5::quoteString(output) << ')' << std::endl;
}
/*
#endif /* CVC5_COMPETITION_MODE */
}
-static void errorToStream(std::ostream& out, std::string message, Variant v) {
- // escape all double-quotes
- size_t pos = 0;
- while((pos = message.find('"', pos)) != string::npos) {
- message.replace(pos, 1, "\"\"");
- pos += 2;
- }
- out << "(error \"" << message << "\")" << endl;
+static void errorToStream(std::ostream& out, std::string message, Variant v)
+{
+ out << "(error " << cvc5::quoteString(message) << ')' << endl;
}
static void toStream(std::ostream& out, const CommandFailure* s, Variant v) {
#include "proof/unsat_core.h"
#include "smt/dump.h"
#include "smt/model.h"
+#include "util/smt2_quote_string.h"
#include "util/unsafe_interrupt_exception.h"
#include "util/utility.h"
/* class EchoCommand */
/* -------------------------------------------------------------------------- */
-EchoCommand::EchoCommand(std::string output)
-{
- // escape all double-quotes
- size_t pos = 0;
- while ((pos = output.find('"', pos)) != string::npos)
- {
- output.replace(pos, 1, "\"\"");
- pos += 2;
- }
- d_output = '"' + output + '"';
-}
+EchoCommand::EchoCommand(std::string output) : d_output(output) {}
std::string EchoCommand::getOutput() const { return d_output; }
+
void EchoCommand::invoke(api::Solver* solver, SymbolManager* sm)
{
/* we don't have an output stream here, nothing to do */
SymbolManager* sm,
std::ostream& out)
{
- out << d_output << std::endl;
+ out << cvc5::quoteString(d_output) << std::endl;
Trace("dtview::command") << "* ~COMMAND: echo |" << d_output << "|~"
<< std::endl;
d_commandStatus = CommandSuccess::instance();
}
Command* EchoCommand::clone() const { return new EchoCommand(d_output); }
+
std::string EchoCommand::getCommandName() const { return "echo"; }
void EchoCommand::toStream(std::ostream& out,
return s;
}
+std::string quoteString(const std::string& s) {
+ // escape all double-quotes
+ std::string output = s;
+ size_t pos = 0;
+ while ((pos = output.find('"', pos)) != std::string::npos)
+ {
+ output.replace(pos, 1, "\"\"");
+ pos += 2;
+ }
+ return '"' + output + '"';
+}
+
} // namespace cvc5
*/
std::string quoteSymbol(const std::string& s);
+/**
+ * SMT-LIB 2 quoting for strings
+ */
+std::string quoteString(const std::string& s);
+
} // namespace cvc5
#endif /* CVC5__UTIL__SMT2_QUOTE_STRING_H */