summaryrefslogtreecommitdiffstats
path: root/akonadish/syntaxtree.h
diff options
context:
space:
mode:
Diffstat (limited to 'akonadish/syntaxtree.h')
-rw-r--r--akonadish/syntaxtree.h75
1 files changed, 75 insertions, 0 deletions
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 @@
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 Syntax
28{
29public:
30 typedef QVector<Syntax> List;
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 std::function<QStringList(const QStringList &, const QString &)> completer;
48
49 QVector<Syntax> children;
50};
51
52class SyntaxTree
53{
54public:
55
56 typedef std::pair<const Syntax *, QStringList> Command;
57
58 static SyntaxTree *self();
59
60 Syntax::List syntax() const;
61 Command match(const QStringList &commands) const;
62 Syntax::List nearestSyntax(const QStringList &words, const QString &fragment) const;
63
64 bool run(const QStringList &commands);
65
66 static QStringList tokenize(const QString &text);
67
68private:
69 SyntaxTree();
70
71 Syntax::List m_syntax;
72 State m_state;
73 static SyntaxTree *s_module;
74};
75