aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/python-console/test_cli.cpp
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2018-06-28 13:16:53 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2018-06-28 17:57:26 +0200
commitc63274342f1aaa3d1087c0df5ffdaccfd0afcd56 (patch)
treeb04628f6c8c6768e2d5771737f3f13687cd0ed29 /3rdparty/python-console/test_cli.cpp
parent66670831b89d934ef00c47c0527137f6ec38a0b0 (diff)
downloadnextpnr-c63274342f1aaa3d1087c0df5ffdaccfd0afcd56.tar.gz
nextpnr-c63274342f1aaa3d1087c0df5ffdaccfd0afcd56.tar.bz2
nextpnr-c63274342f1aaa3d1087c0df5ffdaccfd0afcd56.zip
initial import of python-console
Diffstat (limited to '3rdparty/python-console/test_cli.cpp')
-rw-r--r--3rdparty/python-console/test_cli.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/3rdparty/python-console/test_cli.cpp b/3rdparty/python-console/test_cli.cpp
new file mode 100644
index 00000000..76d0f251
--- /dev/null
+++ b/3rdparty/python-console/test_cli.cpp
@@ -0,0 +1,63 @@
+#include <iostream>
+#include <string>
+#include "ParseHelper.h"
+#include "ParseListener.h"
+#include "Interpreter.h"
+
+const std::string STD_PROMPT = ">>> ";
+const std::string MULTILINE_PROMPT = "... ";
+
+struct InterpreterRelay : public ParseListener
+{
+ Interpreter* m_interpreter;
+
+ InterpreterRelay( ):
+ m_interpreter( new Interpreter )
+ { }
+
+ virtual void parseEvent( const ParseMessage& msg )
+ {
+ if ( msg.errorCode )
+ {
+ std::cout << "(" << msg.errorCode << ") " << msg.message << "\n";
+ return;
+ }
+ else
+ {
+ int err;
+ std::string res = m_interpreter->interpret( msg.message, &err );
+ std::cout << "(" << msg.errorCode << ") " << res << "\n";
+ }
+ }
+};
+
+int main( int argc, char *argv[] )
+{
+ Interpreter::Initialize( );
+ const std::string* prompt = &STD_PROMPT;
+ ParseHelper helper;
+ ParseListener* listener = new InterpreterRelay;
+ helper.subscribe( listener );
+
+ std::string str;
+ std::cout << *prompt;
+ std::getline( std::cin, str );
+ while ( str != "quit" )
+ {
+ std::cout << str << "\n";
+ helper.process( str );
+ if ( helper.buffered( ) )
+ {
+ prompt = &MULTILINE_PROMPT;
+ }
+ else
+ {
+ prompt = &STD_PROMPT;
+ }
+ std::cout << *prompt;
+ std::getline( std::cin, str );
+ }
+
+ Interpreter::Finalize( );
+ return 0;
+}