Fix bug with incomplete parses not failing
diff --git a/Parser.cpp b/Parser.cpp
index 95bda1d..2c62f27 100644
--- a/Parser.cpp
+++ b/Parser.cpp
@@ -37,6 +37,14 @@
return _status;
}
+ParseResult ParseResult::operator ||(const ParseResult &other) const
+{
+ if (_status == COMPLETE || _status == INCOMPLETE)
+ return *this;
+ else
+ return other;
+}
+
Parser::Parser(QString input)
{
_input = input;
diff --git a/Parser.h b/Parser.h
index f65e787..ee604f9 100644
--- a/Parser.h
+++ b/Parser.h
@@ -34,6 +34,8 @@
QString message() const;
int status() const;
+ ParseResult operator ||(const ParseResult &other) const;
+
private:
int _status = COMPLETE;
QString _message = "";
diff --git a/Repl.cpp b/Repl.cpp
index fd09dfc..037a758 100644
--- a/Repl.cpp
+++ b/Repl.cpp
@@ -67,7 +67,7 @@
bool okay = true;
QList<Token> out;
- for (const AstNode &node : expr)
+ for (const AstNode &node : qAsConst(expr))
{
RuntimeResult res = _eval.evaluate(node, VarContext());
@@ -91,16 +91,13 @@
}
else if (ret.status() == ParseResult::INCOMPLETE)
{
- qDebug() << "INCOMPLETE";
- ReadLine::rl_line_buffer = line.toUtf8().data();
- // ReadLine::rl_insert_text("\n");
- // ReadLine::rl_on_new_line();
- ReadLine::rl_redisplay();
- // ReadLine::rl_message("Incomplete");
+ qDebug() << "Parse error: incomplete input:" << ret.message();
+ ReadLine::rl_insert_text("Hello there!");
+ ReadLine::rl_redisplay();
}
else
{
- qDebug() << "What?";
+ qDebug() << "Parse error:" << ret.message();
}
}
}
@@ -131,7 +128,7 @@
ParseResult ret;
- if ((ret = parser.parseFunctionDefinition(&func)))
+ if ((ret = parser.parseFunctionDefinition(&func)))
{
_eval.addFunction(func);
*expr = {};