Home
Phabricator
Search
Log In
Files
F5818108
lua_multiline_output_2.patch
asemke (Alexander Semke)
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Author
asemke
Created
Apr 22 2018, 7:31 PM
Size
1 KB
Mime Type
text/x-diff
Engine
blob
Format
Raw Data
Handle
3562085
Attached To
D12074: Solve problem of appearance input of interpreter in interpreter's output in Lua backend
lua_multiline_output_2.patch
View Options
diff --git a/src/backends/lua/luaexpression.cpp b/src/backends/lua/luaexpression.cpp
index 588c72bb..cad18b8b 100644
--- a/src/backends/lua/luaexpression.cpp
+++ b/src/backends/lua/luaexpression.cpp
@@ -67,15 +67,41 @@ void LuaExpression::parseError(QString &error)
void LuaExpression::parseOutput(QString &output)
{
- output.replace(command(), QLatin1String(""));
- output.replace(QLatin1String("return"), QLatin1String(""));
- output.replace(QLatin1String(">"), QLatin1String(""));
- output = output.trimmed();
-
- qDebug() << "final output of the command " << command() << ": " << output << endl;
+ qDebug()<<"parsing the output " << output;
+
+ const QStringList& inputs = command().split(QLatin1Char('\n'));
+ const QStringList& outputs = output.split(QLatin1Char('\n'));
+ QString parsedOutput;
+
+ for (auto out : outputs) {
+ //remove lua's promt characters if available
+ if (out.startsWith(QLatin1String("> ")))
+ out.remove(0, 2);
+ else if (out.startsWith(QLatin1String(">> ")))
+ out.remove(0, 3);
+
+ //for multi-line inputs lua returs the inputs as part of the output
+ //-> remove the input lines from the output.
+ //since lua doesn't always seem to preserve the spaces, compare trimmed strings
+ out = out.trimmed();
+ bool found = false;
+ for (auto in : inputs) {
+ if (out == in.trimmed()) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ if (!parsedOutput.isEmpty())
+ parsedOutput += QLatin1Char('\n');
+ parsedOutput += out;
+ }
+ }
- setResult(new Cantor::TextResult(output));
+ qDebug() << "final output of the command " << command() << ": " << parsedOutput << endl;
+ setResult(new Cantor::TextResult(parsedOutput));
setStatus(Cantor::Expression::Done);
}
Log In to Comment