Add stub for incomplete line editing
diff --git a/Parser.cpp b/Parser.cpp
index 9b8f264..95bda1d 100644
--- a/Parser.cpp
+++ b/Parser.cpp
@@ -197,7 +197,6 @@
while ((ret = parseOne(&next)))
{
- // qDebug() << "parseMany one" << next;
nodes.append(next);
}
@@ -308,8 +307,6 @@
{
ParsePos pos = save();
- qDebug() << "Parsing sentence" << peek();
-
if (peek() == '}')
{
return false;
@@ -320,15 +317,12 @@
if (!ret)
{
- qDebug() << "Many failed" << ret.message();
reset(pos);
return ret;
}
skip();
- qDebug() << "will we get an =?" << peek();
-
if (get() != '=')
{
ret = ParseResult(ParseResult::INCOMPLETE, "Expected = in sentence", save());
@@ -341,15 +335,12 @@
if (!ret)
{
- qDebug() << "sentence parseMany returned" << ret.message();
reset(pos);
return ret;
}
skip();
- qDebug() << "end of sentence" << peek();
-
if (peek() != '}' && get() != ';')
{
ret = ParseResult(ParseResult::INCOMPLETE, "Expected ; or } after sentence", save());
@@ -394,7 +385,6 @@
if (ret.status() == ParseResult::INCOMPLETE)
{
- qDebug() << "Function incomplete";
reset(pos);
return ret;
}
@@ -406,8 +396,6 @@
return ret;
}
- qDebug() << "Function parsing succeeded";
-
*function = func;
return true;
}
diff --git a/Repl.cpp b/Repl.cpp
index 0bddf3d..fd09dfc 100644
--- a/Repl.cpp
+++ b/Repl.cpp
@@ -35,8 +35,6 @@
return "";
}
- ReadLine::add_history(line);
-
QString string = QString::fromUtf8(line);
free(line);
@@ -57,11 +55,14 @@
QList<AstNode> expr;
- addHistory(line);
+ if (!line.isEmpty())
+ addHistory(line);
+
+ ParseResult ret;
if (trySpecialCase(line))
{}
- else if (tryEvaluate(line, &expr))
+ else if ((ret = tryEvaluate(line, &expr)))
{
bool okay = true;
QList<Token> out;
@@ -88,6 +89,15 @@
qDebug().noquote() << pprint(out);
}
}
+ 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");
+ }
else
{
qDebug() << "What?";
@@ -95,7 +105,7 @@
}
}
-bool Repl::trySpecialCase(QString line)
+ParseResult Repl::trySpecialCase(QString line)
{
if (line.startsWith("."))
{
@@ -114,23 +124,26 @@
return false;
}
-bool Repl::tryEvaluate(QString line, QList<AstNode> *expr)
+ParseResult Repl::tryEvaluate(QString line, QList<AstNode> *expr)
{
Parser parser(line);
Function func;
- if (parser.parseFunctionDefinition(&func))
+ ParseResult ret;
+
+ if ((ret = parser.parseFunctionDefinition(&func)))
{
_eval.addFunction(func);
*expr = {};
return true;
}
-
- if (!parser.parseMany(expr))
- return false;
-
- parser.skip();
-
- return parser.atEnd();
+ else if (ret.status() == ParseResult::INCOMPLETE)
+ {
+ return ret;
+ }
+ else
+ {
+ return parser.parseMany(expr);
+ }
}
diff --git a/Repl.h b/Repl.h
index b3470f2..10a922b 100644
--- a/Repl.h
+++ b/Repl.h
@@ -5,6 +5,7 @@
#include "Evaluator.h"
#include "AstNode.h"
+#include "Parser.h"
class Repl
{
@@ -17,8 +18,8 @@
protected:
QString readLine();
void addHistory(QString line);
- bool trySpecialCase(QString line);
- bool tryEvaluate(QString line, QList<AstNode> *expr);
+ ParseResult trySpecialCase(QString line);
+ ParseResult tryEvaluate(QString line, QList<AstNode> *expr);
Evaluator _eval;