diff options
author | Aaron Seigo <aseigo@kde.org> | 2015-12-23 20:31:25 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2015-12-23 20:31:25 +0100 |
commit | 5e9c1172ca196bdc8bcdc842e54efc5a74908fff (patch) | |
tree | 102ecf6f74bd94e0c8eaf09acc3006b241d49135 | |
parent | 26c510ace968af7d4c82c1f192bc8cdcb3505910 (diff) | |
download | sink-5e9c1172ca196bdc8bcdc842e54efc5a74908fff.tar.gz sink-5e9c1172ca196bdc8bcdc842e54efc5a74908fff.zip |
move Syntax out of SyntraxTree
-rw-r--r-- | akonadi2_cli/repl/replStates.cpp | 2 | ||||
-rw-r--r-- | akonadi2_cli/syntax_modules/akonadi_list.cpp | 2 | ||||
-rw-r--r-- | akonadi2_cli/syntax_modules/core_syntax.cpp | 14 | ||||
-rw-r--r-- | akonadi2_cli/syntaxtree.cpp | 4 | ||||
-rw-r--r-- | akonadi2_cli/syntaxtree.h | 44 |
5 files changed, 34 insertions, 32 deletions
diff --git a/akonadi2_cli/repl/replStates.cpp b/akonadi2_cli/repl/replStates.cpp index 0273aa2..0179779 100644 --- a/akonadi2_cli/repl/replStates.cpp +++ b/akonadi2_cli/repl/replStates.cpp | |||
@@ -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<SyntaxTree::Syntax> nearest = SyntaxTree::self()->nearestSyntax(tab_completion_full_state, QString(text)); | 152 | SyntaxTree::SyntaxList 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/syntax_modules/akonadi_list.cpp b/akonadi2_cli/syntax_modules/akonadi_list.cpp index 26b1f1e..62824ee 100644 --- a/akonadi2_cli/syntax_modules/akonadi_list.cpp +++ b/akonadi2_cli/syntax_modules/akonadi_list.cpp | |||
@@ -42,7 +42,7 @@ namespace AkonadiList | |||
42 | SyntaxTree::SyntaxList syntax() | 42 | SyntaxTree::SyntaxList syntax() |
43 | { | 43 | { |
44 | SyntaxTree::SyntaxList syntax; | 44 | SyntaxTree::SyntaxList syntax; |
45 | syntax << SyntaxTree::Syntax("list", QObject::tr("List all resources, or the contents of one or more resources"), &AkonadiList::list, SyntaxTree::Syntax::EventDriven); | 45 | syntax << Syntax("list", QObject::tr("List all resources, or the contents of one or more resources"), &AkonadiList::list, Syntax::EventDriven); |
46 | 46 | ||
47 | return syntax; | 47 | return syntax; |
48 | } | 48 | } |
diff --git a/akonadi2_cli/syntax_modules/core_syntax.cpp b/akonadi2_cli/syntax_modules/core_syntax.cpp index f9cd622..1231e29 100644 --- a/akonadi2_cli/syntax_modules/core_syntax.cpp +++ b/akonadi2_cli/syntax_modules/core_syntax.cpp | |||
@@ -30,15 +30,15 @@ namespace CoreSyntax | |||
30 | SyntaxTree::SyntaxList syntax() | 30 | SyntaxTree::SyntaxList syntax() |
31 | { | 31 | { |
32 | SyntaxTree::SyntaxList syntax; | 32 | SyntaxTree::SyntaxList syntax; |
33 | syntax << SyntaxTree::Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); | 33 | syntax << Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); |
34 | syntax << SyntaxTree::Syntax(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); | 34 | syntax << Syntax(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); |
35 | 35 | ||
36 | SyntaxTree::Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); | 36 | Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); |
37 | set.children << SyntaxTree::Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); | 37 | set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); |
38 | syntax << set; | 38 | syntax << set; |
39 | 39 | ||
40 | SyntaxTree::Syntax get(QObject::tr("get"), QObject::tr("Gets settings for the session")); | 40 | Syntax get(QObject::tr("get"), QObject::tr("Gets settings for the session")); |
41 | get.children << SyntaxTree::Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::printDebugLevel); | 41 | get.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::printDebugLevel); |
42 | syntax << get; | 42 | syntax << get; |
43 | 43 | ||
44 | return syntax; | 44 | return syntax; |
@@ -65,7 +65,7 @@ bool showHelp(const QStringList &commands, State &state) | |||
65 | for (auto keyword: sorted) { | 65 | for (auto keyword: sorted) { |
66 | state.printLine(keyword, 1); | 66 | state.printLine(keyword, 1); |
67 | } | 67 | } |
68 | } else if (const SyntaxTree::Syntax *syntax = command.first) { | 68 | } else if (const Syntax *syntax = command.first) { |
69 | //TODO: get parent! | 69 | //TODO: get parent! |
70 | state.print(QObject::tr("Command `%1`").arg(syntax->keyword)); | 70 | state.print(QObject::tr("Command `%1`").arg(syntax->keyword)); |
71 | 71 | ||
diff --git a/akonadi2_cli/syntaxtree.cpp b/akonadi2_cli/syntaxtree.cpp index 5dd4c54..a4f5d40 100644 --- a/akonadi2_cli/syntaxtree.cpp +++ b/akonadi2_cli/syntaxtree.cpp | |||
@@ -29,11 +29,11 @@ | |||
29 | 29 | ||
30 | SyntaxTree *SyntaxTree::s_module = 0; | 30 | SyntaxTree *SyntaxTree::s_module = 0; |
31 | 31 | ||
32 | SyntaxTree::Syntax::Syntax() | 32 | Syntax::Syntax() |
33 | { | 33 | { |
34 | } | 34 | } |
35 | 35 | ||
36 | SyntaxTree::Syntax::Syntax(const QString &k, const QString &helpText, std::function<bool(const QStringList &, State &)> l, Interactivity inter) | 36 | Syntax::Syntax(const QString &k, const QString &helpText, std::function<bool(const QStringList &, State &)> l, Interactivity inter) |
37 | : keyword(k), | 37 | : keyword(k), |
38 | help(helpText), | 38 | help(helpText), |
39 | interactivity(inter), | 39 | interactivity(inter), |
diff --git a/akonadi2_cli/syntaxtree.h b/akonadi2_cli/syntaxtree.h index 54b867f..7282955 100644 --- a/akonadi2_cli/syntaxtree.h +++ b/akonadi2_cli/syntaxtree.h | |||
@@ -24,32 +24,34 @@ | |||
24 | #include <QStringList> | 24 | #include <QStringList> |
25 | #include <QVector> | 25 | #include <QVector> |
26 | 26 | ||
27 | class SyntaxTree | 27 | class Syntax |
28 | { | 28 | { |
29 | public: | 29 | public: |
30 | struct Syntax | 30 | enum Interactivity { |
31 | { | 31 | NotInteractive = 0, |
32 | enum Interactivity { | 32 | EventDriven |
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 | }; | 33 | }; |
50 | 34 | ||
35 | Syntax(); | ||
36 | Syntax(const QString &keyword, | ||
37 | const QString &helpText = QString(), | ||
38 | std::function<bool(const QStringList &, State &)> lambda = std::function<bool(const QStringList &, State &)>(), | ||
39 | Interactivity interactivity = NotInteractive); | ||
40 | |||
41 | QString keyword; | ||
42 | QString help; | ||
43 | Interactivity interactivity; | ||
44 | std::function<bool(const QStringList &, State &)> lambda; | ||
45 | |||
46 | QVector<Syntax> children; | ||
47 | }; | ||
48 | |||
49 | class SyntaxTree | ||
50 | { | ||
51 | public: | ||
52 | |||
51 | typedef std::pair<const Syntax *, QStringList> Command; | 53 | typedef std::pair<const Syntax *, QStringList> Command; |
52 | typedef QVector<SyntaxTree::Syntax> SyntaxList; | 54 | typedef QVector<Syntax> SyntaxList; |
53 | 55 | ||
54 | static SyntaxTree *self(); | 56 | static SyntaxTree *self(); |
55 | 57 | ||