From 8b07718cb47dca6240a70e9aea57b88121cc956b Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 23 Dec 2015 23:25:09 +0100 Subject: akonadi2_cli -> akonadish --- akonadish/syntaxtree.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 akonadish/syntaxtree.h (limited to 'akonadish/syntaxtree.h') diff --git a/akonadish/syntaxtree.h b/akonadish/syntaxtree.h new file mode 100644 index 0000000..77f52af --- /dev/null +++ b/akonadish/syntaxtree.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include "state.h" + +#include +#include + +class Syntax +{ +public: + typedef QVector List; + + enum Interactivity { + NotInteractive = 0, + EventDriven + }; + + Syntax(); + Syntax(const QString &keyword, + const QString &helpText = QString(), + std::function lambda = std::function(), + Interactivity interactivity = NotInteractive); + + QString keyword; + QString help; + Interactivity interactivity; + std::function lambda; + std::function completer; + + QVector children; +}; + +class SyntaxTree +{ +public: + + typedef std::pair Command; + + static SyntaxTree *self(); + + Syntax::List syntax() const; + Command match(const QStringList &commands) const; + Syntax::List nearestSyntax(const QStringList &words, const QString &fragment) const; + + bool run(const QStringList &commands); + + static QStringList tokenize(const QString &text); + +private: + SyntaxTree(); + + Syntax::List m_syntax; + State m_state; + static SyntaxTree *s_module; +}; + -- cgit v1.2.3 From 35f0ddf67c629ce9efaa1ba893afcb2921a251a2 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 24 Dec 2015 10:22:07 +0100 Subject: REGISTER_SYNTAX for automagic adding of syntax a fun abuse of static initialization and std::function --- akonadish/syntaxtree.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'akonadish/syntaxtree.h') diff --git a/akonadish/syntaxtree.h b/akonadish/syntaxtree.h index 77f52af..6fdf2b9 100644 --- a/akonadish/syntaxtree.h +++ b/akonadish/syntaxtree.h @@ -57,6 +57,7 @@ public: static SyntaxTree *self(); + int registerSyntax(std::function f); Syntax::List syntax() const; Command match(const QStringList &commands) const; Syntax::List nearestSyntax(const QStringList &words, const QString &fragment) const; @@ -73,3 +74,4 @@ private: static SyntaxTree *s_module; }; +#define REGISTER_SYNTAX(name) static const int theTrickFor##name = SyntaxTree::self()->registerSyntax(&name::syntax); -- cgit v1.2.3 From f5d4b7dc12dbb3b38b70bcbe94298972208d64f5 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 24 Dec 2015 10:36:52 +0100 Subject: minor ws fix --- akonadish/syntaxtree.h | 1 - 1 file changed, 1 deletion(-) (limited to 'akonadish/syntaxtree.h') diff --git a/akonadish/syntaxtree.h b/akonadish/syntaxtree.h index 6fdf2b9..3421fc3 100644 --- a/akonadish/syntaxtree.h +++ b/akonadish/syntaxtree.h @@ -52,7 +52,6 @@ public: class SyntaxTree { public: - typedef std::pair Command; static SyntaxTree *self(); -- cgit v1.2.3 From ad442fb49e5d4271a5f2276eb73d9d15b1e8755f Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 10:31:24 +0100 Subject: support command timing output --- akonadish/syntaxtree.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'akonadish/syntaxtree.h') diff --git a/akonadish/syntaxtree.h b/akonadish/syntaxtree.h index 3421fc3..5ee915a 100644 --- a/akonadish/syntaxtree.h +++ b/akonadish/syntaxtree.h @@ -22,6 +22,7 @@ #include "state.h" #include +#include #include class Syntax @@ -70,6 +71,7 @@ private: Syntax::List m_syntax; State m_state; + QTime m_timeElapsed; static SyntaxTree *s_module; }; -- cgit v1.2.3 From 67a19008d078a067ceb3424c00553c33b918970e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 26 Dec 2015 19:18:49 +0100 Subject: Fixed build --- akonadish/syntaxtree.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'akonadish/syntaxtree.h') diff --git a/akonadish/syntaxtree.h b/akonadish/syntaxtree.h index 5ee915a..884a10d 100644 --- a/akonadish/syntaxtree.h +++ b/akonadish/syntaxtree.h @@ -25,6 +25,8 @@ #include #include +#include + class Syntax { public: -- cgit v1.2.3