diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-20 19:07:07 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-20 19:07:07 +0100 |
commit | bdb01c2c068df326f5a8328ed1492ab1bea388c5 (patch) | |
tree | 25c2ee1b29bc481b6914c244ed9ca194b1415d16 /sinksh/syntaxtree.h | |
parent | 17e7ee40c9185c0505883853345fd6024c675b1a (diff) | |
download | sink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.tar.gz sink-bdb01c2c068df326f5a8328ed1492ab1bea388c5.zip |
Renamed Akonadi2 to Sink
(except for documentation).
Diffstat (limited to 'sinksh/syntaxtree.h')
-rw-r--r-- | sinksh/syntaxtree.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/sinksh/syntaxtree.h b/sinksh/syntaxtree.h new file mode 100644 index 0000000..468aad3 --- /dev/null +++ b/sinksh/syntaxtree.h | |||
@@ -0,0 +1,80 @@ | |||
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 <QTime> | ||
26 | #include <QVector> | ||
27 | |||
28 | #include <functional> | ||
29 | |||
30 | class Syntax | ||
31 | { | ||
32 | public: | ||
33 | typedef QVector<Syntax> List; | ||
34 | |||
35 | enum Interactivity { | ||
36 | NotInteractive = 0, | ||
37 | EventDriven | ||
38 | }; | ||
39 | |||
40 | Syntax(); | ||
41 | Syntax(const QString &keyword, | ||
42 | const QString &helpText = QString(), | ||
43 | std::function<bool(const QStringList &, State &)> lambda = std::function<bool(const QStringList &, State &)>(), | ||
44 | Interactivity interactivity = NotInteractive); | ||
45 | |||
46 | QString keyword; | ||
47 | QString help; | ||
48 | Interactivity interactivity; | ||
49 | std::function<bool(const QStringList &, State &)> lambda; | ||
50 | std::function<QStringList(const QStringList &, const QString &, State &state)> completer; | ||
51 | |||
52 | QVector<Syntax> children; | ||
53 | }; | ||
54 | |||
55 | class SyntaxTree | ||
56 | { | ||
57 | public: | ||
58 | typedef std::pair<const Syntax *, QStringList> Command; | ||
59 | |||
60 | static SyntaxTree *self(); | ||
61 | |||
62 | int registerSyntax(std::function<Syntax::List()> f); | ||
63 | Syntax::List syntax() const; | ||
64 | Command match(const QStringList &commands) const; | ||
65 | Syntax::List nearestSyntax(const QStringList &words, const QString &fragment) const; | ||
66 | State &state(); | ||
67 | bool run(const QStringList &commands); | ||
68 | |||
69 | static QStringList tokenize(const QString &text); | ||
70 | |||
71 | private: | ||
72 | SyntaxTree(); | ||
73 | |||
74 | Syntax::List m_syntax; | ||
75 | State m_state; | ||
76 | QTime m_timeElapsed; | ||
77 | static SyntaxTree *s_module; | ||
78 | }; | ||
79 | |||
80 | #define REGISTER_SYNTAX(name) static const int theTrickFor##name = SyntaxTree::self()->registerSyntax(&name::syntax); | ||