summaryrefslogtreecommitdiffstats
path: root/akonadi2_cli/syntaxtree.h
diff options
context:
space:
mode:
Diffstat (limited to 'akonadi2_cli/syntaxtree.h')
-rw-r--r--akonadi2_cli/syntaxtree.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/akonadi2_cli/syntaxtree.h b/akonadi2_cli/syntaxtree.h
new file mode 100644
index 0000000..54b867f
--- /dev/null
+++ b/akonadi2_cli/syntaxtree.h
@@ -0,0 +1,72 @@
1/*
2 * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#pragma once
21
22#include "state.h"
23
24#include <QStringList>
25#include <QVector>
26
27class SyntaxTree
28{
29public:
30 struct Syntax
31 {
32 enum Interactivity {
33 NotInteractive = 0,
34 EventDriven
35 };
36
37 Syntax();
38 Syntax(const QString &keyword,
39 const QString &helpText = QString(),
40 std::function<bool(const QStringList &, State &)> lambda = std::function<bool(const QStringList &, State &)>(),
41 Interactivity interactivity = NotInteractive);
42
43 QString keyword;
44 QString help;
45 Interactivity interactivity;
46 std::function<bool(const QStringList &, State &)> lambda;
47
48 QVector<Syntax> children;
49 };
50
51 typedef std::pair<const Syntax *, QStringList> Command;
52 typedef QVector<SyntaxTree::Syntax> SyntaxList;
53
54 static SyntaxTree *self();
55
56 SyntaxList syntax() const;
57 Command match(const QStringList &commands) const;
58 SyntaxList nearestSyntax(const QStringList &words, const QString &fragment) const;
59
60 bool run(const QStringList &commands);
61
62 static QStringList tokenize(const QString &text);
63
64private:
65 SyntaxTree();
66 Command matches(const QStringList &commands) const;
67
68 SyntaxList m_syntax;
69 State m_state;
70 static SyntaxTree *s_module;
71};
72