diff options
author | Aaron Seigo <aseigo@kde.org> | 2015-12-23 16:43:45 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2015-12-23 16:43:45 +0100 |
commit | 7e96145d27329ca3870f23d5b161785d10c9faf5 (patch) | |
tree | 46c5c673b9410341c817cc7fe6f93672718ec85d | |
parent | 8c78033ca7e59c44eb2886a3f8fe89c5b22ad114 (diff) | |
download | sink-7e96145d27329ca3870f23d5b161785d10c9faf5.tar.gz sink-7e96145d27329ca3870f23d5b161785d10c9faf5.zip |
Module -> SyntaxTree
-rw-r--r-- | akonadi2_cli/CMakeLists.txt | 4 | ||||
-rw-r--r-- | akonadi2_cli/main.cpp | 4 | ||||
-rw-r--r-- | akonadi2_cli/repl/replStates.cpp | 8 | ||||
-rw-r--r-- | akonadi2_cli/syntax_modules/core_syntax.cpp (renamed from akonadi2_cli/modules/core_syntax.cpp) | 14 | ||||
-rw-r--r-- | akonadi2_cli/syntax_modules/core_syntax.h (renamed from akonadi2_cli/modules/core_syntax.h) | 4 | ||||
-rw-r--r-- | akonadi2_cli/syntaxtree.cpp (renamed from akonadi2_cli/module.cpp) | 34 | ||||
-rw-r--r-- | akonadi2_cli/syntaxtree.h (renamed from akonadi2_cli/module.h) | 10 |
7 files changed, 39 insertions, 39 deletions
diff --git a/akonadi2_cli/CMakeLists.txt b/akonadi2_cli/CMakeLists.txt index a07140e..a061ebb 100644 --- a/akonadi2_cli/CMakeLists.txt +++ b/akonadi2_cli/CMakeLists.txt | |||
@@ -5,8 +5,8 @@ find_package(Readline REQUIRED) | |||
5 | 5 | ||
6 | set(akonadi2_cli_SRCS | 6 | set(akonadi2_cli_SRCS |
7 | main.cpp | 7 | main.cpp |
8 | module.cpp | 8 | syntaxtree.cpp |
9 | modules/core_syntax.cpp | 9 | syntax_modules/core_syntax.cpp |
10 | repl/repl.cpp | 10 | repl/repl.cpp |
11 | repl/replStates.cpp | 11 | repl/replStates.cpp |
12 | state.cpp) | 12 | state.cpp) |
diff --git a/akonadi2_cli/main.cpp b/akonadi2_cli/main.cpp index d23e070..f7b7b9f 100644 --- a/akonadi2_cli/main.cpp +++ b/akonadi2_cli/main.cpp | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <QCoreApplication> | 22 | #include <QCoreApplication> |
23 | #include <QDebug> | 23 | #include <QDebug> |
24 | 24 | ||
25 | #include "module.h" | 25 | #include "syntaxtree.h" |
26 | // #include "jsonlistener.h" | 26 | // #include "jsonlistener.h" |
27 | #include "repl/repl.h" | 27 | #include "repl/repl.h" |
28 | 28 | ||
@@ -64,5 +64,5 @@ int main(int argc, char *argv[]) | |||
64 | 64 | ||
65 | QStringList commands = app.arguments(); | 65 | QStringList commands = app.arguments(); |
66 | commands.removeFirst(); | 66 | commands.removeFirst(); |
67 | return Module::self()->run(commands); | 67 | return SyntaxTree::self()->run(commands); |
68 | } | 68 | } |
diff --git a/akonadi2_cli/repl/replStates.cpp b/akonadi2_cli/repl/replStates.cpp index 314cca8..0273aa2 100644 --- a/akonadi2_cli/repl/replStates.cpp +++ b/akonadi2_cli/repl/replStates.cpp | |||
@@ -29,7 +29,7 @@ | |||
29 | #include <QEvent> | 29 | #include <QEvent> |
30 | #include <QStateMachine> | 30 | #include <QStateMachine> |
31 | 31 | ||
32 | #include "module.h" | 32 | #include "syntaxtree.h" |
33 | 33 | ||
34 | static char *akonadi2_cli_next_tab_complete_match(const char *text, int state); | 34 | static char *akonadi2_cli_next_tab_complete_match(const char *text, int state); |
35 | static char ** akonadi2_cli_tab_completion(const char *text, int start, int end); | 35 | static char ** akonadi2_cli_tab_completion(const char *text, int start, int end); |
@@ -111,8 +111,8 @@ void EvalState::complete() | |||
111 | 111 | ||
112 | if (!m_partial.isEmpty()) { | 112 | if (!m_partial.isEmpty()) { |
113 | //emit output("Processing ... " + command); | 113 | //emit output("Processing ... " + command); |
114 | const QStringList commands = Module::tokenize(m_partial); | 114 | const QStringList commands = SyntaxTree::tokenize(m_partial); |
115 | Module::self()->run(commands); | 115 | SyntaxTree::self()->run(commands); |
116 | m_partial.clear(); | 116 | m_partial.clear(); |
117 | } | 117 | } |
118 | 118 | ||
@@ -149,7 +149,7 @@ static char **akonadi2_cli_tab_completion(const char *text, int start, int end) | |||
149 | 149 | ||
150 | static char *akonadi2_cli_next_tab_complete_match(const char *text, int state) | 150 | static char *akonadi2_cli_next_tab_complete_match(const char *text, int state) |
151 | { | 151 | { |
152 | QVector<Module::Syntax> nearest = Module::self()->nearestSyntax(tab_completion_full_state, QString(text)); | 152 | QVector<SyntaxTree::Syntax> nearest = SyntaxTree::self()->nearestSyntax(tab_completion_full_state, QString(text)); |
153 | 153 | ||
154 | if (nearest.size() > state) { | 154 | if (nearest.size() > state) { |
155 | return qstrdup(nearest[state].keyword.toUtf8()); | 155 | return qstrdup(nearest[state].keyword.toUtf8()); |
diff --git a/akonadi2_cli/modules/core_syntax.cpp b/akonadi2_cli/syntax_modules/core_syntax.cpp index 944abbe..f71c1d6 100644 --- a/akonadi2_cli/modules/core_syntax.cpp +++ b/akonadi2_cli/syntax_modules/core_syntax.cpp | |||
@@ -26,11 +26,11 @@ | |||
26 | namespace CoreSyntax | 26 | namespace CoreSyntax |
27 | { | 27 | { |
28 | 28 | ||
29 | Module::SyntaxList syntax() | 29 | SyntaxTree::SyntaxList syntax() |
30 | { | 30 | { |
31 | Module::SyntaxList syntax; | 31 | SyntaxTree::SyntaxList syntax; |
32 | syntax << Module::Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); | 32 | syntax << SyntaxTree::Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); |
33 | syntax << Module::Syntax(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); | 33 | syntax << SyntaxTree::Syntax(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); |
34 | return syntax; | 34 | return syntax; |
35 | } | 35 | } |
36 | 36 | ||
@@ -42,20 +42,20 @@ bool exit(const QStringList &, State &) | |||
42 | 42 | ||
43 | bool showHelp(const QStringList &commands, State &state) | 43 | bool showHelp(const QStringList &commands, State &state) |
44 | { | 44 | { |
45 | Module::Command command = Module::self()->match(commands); | 45 | SyntaxTree::Command command = SyntaxTree::self()->match(commands); |
46 | if (commands.isEmpty()) { | 46 | if (commands.isEmpty()) { |
47 | state.printLine(QObject::tr("Welcome to the Akonadi2 command line tool!")); | 47 | state.printLine(QObject::tr("Welcome to the Akonadi2 command line tool!")); |
48 | state.printLine(QObject::tr("Top-level commands:")); | 48 | state.printLine(QObject::tr("Top-level commands:")); |
49 | 49 | ||
50 | QSet<QString> sorted; | 50 | QSet<QString> sorted; |
51 | for (auto syntax: Module::self()->syntax()) { | 51 | for (auto syntax: SyntaxTree::self()->syntax()) { |
52 | sorted.insert(syntax.keyword); | 52 | sorted.insert(syntax.keyword); |
53 | } | 53 | } |
54 | 54 | ||
55 | for (auto keyword: sorted) { | 55 | for (auto keyword: sorted) { |
56 | state.printLine(keyword, 1); | 56 | state.printLine(keyword, 1); |
57 | } | 57 | } |
58 | } else if (const Module::Syntax *syntax = command.first) { | 58 | } else if (const SyntaxTree::Syntax *syntax = command.first) { |
59 | //TODO: get parent! | 59 | //TODO: get parent! |
60 | state.print(QObject::tr("Command `%1`").arg(syntax->keyword)); | 60 | state.print(QObject::tr("Command `%1`").arg(syntax->keyword)); |
61 | 61 | ||
diff --git a/akonadi2_cli/modules/core_syntax.h b/akonadi2_cli/syntax_modules/core_syntax.h index beb8528..0db6661 100644 --- a/akonadi2_cli/modules/core_syntax.h +++ b/akonadi2_cli/syntax_modules/core_syntax.h | |||
@@ -19,11 +19,11 @@ | |||
19 | 19 | ||
20 | #pragma once | 20 | #pragma once |
21 | 21 | ||
22 | #include "module.h" | 22 | #include "syntaxtree.h" |
23 | 23 | ||
24 | namespace CoreSyntax | 24 | namespace CoreSyntax |
25 | { | 25 | { |
26 | Module::SyntaxList syntax(); | 26 | SyntaxTree::SyntaxList syntax(); |
27 | bool exit(const QStringList &commands, State &state); | 27 | bool exit(const QStringList &commands, State &state); |
28 | bool showHelp(const QStringList &commands, State &); | 28 | bool showHelp(const QStringList &commands, State &); |
29 | } | 29 | } |
diff --git a/akonadi2_cli/module.cpp b/akonadi2_cli/syntaxtree.cpp index 5fd68b4..ea017db 100644 --- a/akonadi2_cli/module.cpp +++ b/akonadi2_cli/syntaxtree.cpp | |||
@@ -17,22 +17,22 @@ | |||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include "module.h" | 20 | #include "syntaxtree.h" |
21 | 21 | ||
22 | #include <QCoreApplication> | 22 | #include <QCoreApplication> |
23 | #include <QDebug> | 23 | #include <QDebug> |
24 | 24 | ||
25 | // TODO: needs a proper registry; making "core" modules plugins is | 25 | // TODO: needs a proper registry; making "core" modules plugins is |
26 | // almost certainly overkill, but this is not the way either | 26 | // almost certainly overkill, but this is not the way either |
27 | #include "modules/core_syntax.h" | 27 | #include "syntax_modules/core_syntax.h" |
28 | 28 | ||
29 | Module *Module::s_module = 0; | 29 | SyntaxTree *SyntaxTree::s_module = 0; |
30 | 30 | ||
31 | Module::Syntax::Syntax() | 31 | SyntaxTree::Syntax::Syntax() |
32 | { | 32 | { |
33 | } | 33 | } |
34 | 34 | ||
35 | Module::Syntax::Syntax(const QString &k, const QString &helpText, std::function<bool(const QStringList &, State &)> l, Interactivity inter) | 35 | SyntaxTree::Syntax::Syntax(const QString &k, const QString &helpText, std::function<bool(const QStringList &, State &)> l, Interactivity inter) |
36 | : keyword(k), | 36 | : keyword(k), |
37 | help(helpText), | 37 | help(helpText), |
38 | interactivity(inter), | 38 | interactivity(inter), |
@@ -40,30 +40,30 @@ Module::Syntax::Syntax(const QString &k, const QString &helpText, std::function< | |||
40 | { | 40 | { |
41 | } | 41 | } |
42 | 42 | ||
43 | Module::Module() | 43 | SyntaxTree::SyntaxTree() |
44 | { | 44 | { |
45 | QVector<std::function<SyntaxList()> > syntaxModules; | 45 | QVector<std::function<SyntaxList()> > syntaxSyntaxTrees; |
46 | syntaxModules << &CoreSyntax::syntax; | 46 | syntaxSyntaxTrees << &CoreSyntax::syntax; |
47 | for (auto syntaxModule: syntaxModules) { | 47 | for (auto syntaxSyntaxTree: syntaxSyntaxTrees) { |
48 | m_syntax += syntaxModule(); | 48 | m_syntax += syntaxSyntaxTree(); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | Module *Module::self() | 52 | SyntaxTree *SyntaxTree::self() |
53 | { | 53 | { |
54 | if (!s_module) { | 54 | if (!s_module) { |
55 | s_module = new Module; | 55 | s_module = new SyntaxTree; |
56 | } | 56 | } |
57 | 57 | ||
58 | return s_module; | 58 | return s_module; |
59 | } | 59 | } |
60 | 60 | ||
61 | Module::SyntaxList Module::syntax() const | 61 | SyntaxTree::SyntaxList SyntaxTree::syntax() const |
62 | { | 62 | { |
63 | return m_syntax; | 63 | return m_syntax; |
64 | } | 64 | } |
65 | 65 | ||
66 | bool Module::run(const QStringList &commands) | 66 | bool SyntaxTree::run(const QStringList &commands) |
67 | { | 67 | { |
68 | Command command = match(commands); | 68 | Command command = match(commands); |
69 | if (command.first && command.first->lambda) { | 69 | if (command.first && command.first->lambda) { |
@@ -78,7 +78,7 @@ bool Module::run(const QStringList &commands) | |||
78 | return false; | 78 | return false; |
79 | } | 79 | } |
80 | 80 | ||
81 | Module::Command Module::match(const QStringList &commandLine) const | 81 | SyntaxTree::Command SyntaxTree::match(const QStringList &commandLine) const |
82 | { | 82 | { |
83 | if (commandLine.isEmpty()) { | 83 | if (commandLine.isEmpty()) { |
84 | return Command(); | 84 | return Command(); |
@@ -115,7 +115,7 @@ Module::Command Module::match(const QStringList &commandLine) const | |||
115 | return Command(); | 115 | return Command(); |
116 | } | 116 | } |
117 | 117 | ||
118 | Module::SyntaxList Module::nearestSyntax(const QStringList &words, const QString &fragment) const | 118 | SyntaxTree::SyntaxList SyntaxTree::nearestSyntax(const QStringList &words, const QString &fragment) const |
119 | { | 119 | { |
120 | SyntaxList matches; | 120 | SyntaxList matches; |
121 | 121 | ||
@@ -157,7 +157,7 @@ Module::SyntaxList Module::nearestSyntax(const QStringList &words, const QString | |||
157 | return matches; | 157 | return matches; |
158 | } | 158 | } |
159 | 159 | ||
160 | QStringList Module::tokenize(const QString &text) | 160 | QStringList SyntaxTree::tokenize(const QString &text) |
161 | { | 161 | { |
162 | //TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"'] | 162 | //TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"'] |
163 | return text.split(" "); | 163 | return text.split(" "); |
diff --git a/akonadi2_cli/module.h b/akonadi2_cli/syntaxtree.h index 1149f4f..54b867f 100644 --- a/akonadi2_cli/module.h +++ b/akonadi2_cli/syntaxtree.h | |||
@@ -24,7 +24,7 @@ | |||
24 | #include <QStringList> | 24 | #include <QStringList> |
25 | #include <QVector> | 25 | #include <QVector> |
26 | 26 | ||
27 | class Module | 27 | class SyntaxTree |
28 | { | 28 | { |
29 | public: | 29 | public: |
30 | struct Syntax | 30 | struct Syntax |
@@ -49,9 +49,9 @@ public: | |||
49 | }; | 49 | }; |
50 | 50 | ||
51 | typedef std::pair<const Syntax *, QStringList> Command; | 51 | typedef std::pair<const Syntax *, QStringList> Command; |
52 | typedef QVector<Module::Syntax> SyntaxList; | 52 | typedef QVector<SyntaxTree::Syntax> SyntaxList; |
53 | 53 | ||
54 | static Module *self(); | 54 | static SyntaxTree *self(); |
55 | 55 | ||
56 | SyntaxList syntax() const; | 56 | SyntaxList syntax() const; |
57 | Command match(const QStringList &commands) const; | 57 | Command match(const QStringList &commands) const; |
@@ -62,11 +62,11 @@ public: | |||
62 | static QStringList tokenize(const QString &text); | 62 | static QStringList tokenize(const QString &text); |
63 | 63 | ||
64 | private: | 64 | private: |
65 | Module(); | 65 | SyntaxTree(); |
66 | Command matches(const QStringList &commands) const; | 66 | Command matches(const QStringList &commands) const; |
67 | 67 | ||
68 | SyntaxList m_syntax; | 68 | SyntaxList m_syntax; |
69 | State m_state; | 69 | State m_state; |
70 | static Module *s_module; | 70 | static SyntaxTree *s_module; |
71 | }; | 71 | }; |
72 | 72 | ||