[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [akonadi-next/feature/new_cli] akonadi2_cli: Module -> SyntaxTree
From: Aaron Seigo <aseigo () kde ! org>
Date: 2015-12-23 16:08:04
Message-ID: E1aBlxM-0007dS-3a () scm ! kde ! org
[Download RAW message or body]
Git commit 7e96145d27329ca3870f23d5b161785d10c9faf5 by Aaron Seigo.
Committed on 23/12/2015 at 15:43.
Pushed by aseigo into branch 'feature/new_cli'.
Module -> SyntaxTree
M +2 -2 akonadi2_cli/CMakeLists.txt
M +2 -2 akonadi2_cli/main.cpp
M +4 -4 akonadi2_cli/repl/replStates.cpp
R +7 -7 akonadi2_cli/syntax_modules/core_syntax.cpp [from: \
akonadi2_cli/modules/core_syntax.cpp - 080% similarity] R +2 -2 \
akonadi2_cli/syntax_modules/core_syntax.h [from: akonadi2_cli/modules/core_syntax.h - \
094% similarity] R +17 -17 akonadi2_cli/syntaxtree.cpp [from: \
akonadi2_cli/module.cpp - 080% similarity] R +5 -5 akonadi2_cli/syntaxtree.h \
[from: akonadi2_cli/module.h - 092% similarity]
http://commits.kde.org/akonadi-next/7e96145d27329ca3870f23d5b161785d10c9faf5
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)
set(akonadi2_cli_SRCS
main.cpp
- module.cpp
- modules/core_syntax.cpp
+ syntaxtree.cpp
+ syntax_modules/core_syntax.cpp
repl/repl.cpp
repl/replStates.cpp
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 @@
#include <QCoreApplication>
#include <QDebug>
-#include "module.h"
+#include "syntaxtree.h"
// #include "jsonlistener.h"
#include "repl/repl.h"
@@ -64,5 +64,5 @@ int main(int argc, char *argv[])
QStringList commands = app.arguments();
commands.removeFirst();
- return Module::self()->run(commands);
+ return SyntaxTree::self()->run(commands);
}
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 @@
#include <QEvent>
#include <QStateMachine>
-#include "module.h"
+#include "syntaxtree.h"
static char *akonadi2_cli_next_tab_complete_match(const char *text, int state);
static char ** akonadi2_cli_tab_completion(const char *text, int start, int end);
@@ -111,8 +111,8 @@ void EvalState::complete()
if (!m_partial.isEmpty()) {
//emit output("Processing ... " + command);
- const QStringList commands = Module::tokenize(m_partial);
- Module::self()->run(commands);
+ const QStringList commands = SyntaxTree::tokenize(m_partial);
+ SyntaxTree::self()->run(commands);
m_partial.clear();
}
@@ -149,7 +149,7 @@ static char **akonadi2_cli_tab_completion(const char *text, int \
start, int end)
static char *akonadi2_cli_next_tab_complete_match(const char *text, int state)
{
- QVector<Module::Syntax> nearest = \
Module::self()->nearestSyntax(tab_completion_full_state, QString(text)); + \
QVector<SyntaxTree::Syntax> nearest = \
SyntaxTree::self()->nearestSyntax(tab_completion_full_state, QString(text));
if (nearest.size() > state) {
return qstrdup(nearest[state].keyword.toUtf8());
diff --git a/akonadi2_cli/modules/core_syntax.cpp \
b/akonadi2_cli/syntax_modules/core_syntax.cpp similarity index 80%
rename from akonadi2_cli/modules/core_syntax.cpp
rename to 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 @@
namespace CoreSyntax
{
-Module::SyntaxList syntax()
+SyntaxTree::SyntaxList syntax()
{
- Module::SyntaxList syntax;
- syntax << Module::Syntax("exit", QObject::tr("Exits the application. Ctrl-d also \
works!"), &CoreSyntax::exit);
- syntax << Module::Syntax(QObject::tr("help"), QObject::tr("Print command \
information: help [command]"), &CoreSyntax::showHelp); + SyntaxTree::SyntaxList \
syntax; + syntax << SyntaxTree::Syntax("exit", QObject::tr("Exits the application. \
Ctrl-d also works!"), &CoreSyntax::exit); + syntax << \
SyntaxTree::Syntax(QObject::tr("help"), QObject::tr("Print command information: help \
[command]"), &CoreSyntax::showHelp); return syntax;
}
@@ -42,20 +42,20 @@ bool exit(const QStringList &, State &)
bool showHelp(const QStringList &commands, State &state)
{
- Module::Command command = Module::self()->match(commands);
+ SyntaxTree::Command command = SyntaxTree::self()->match(commands);
if (commands.isEmpty()) {
state.printLine(QObject::tr("Welcome to the Akonadi2 command line tool!"));
state.printLine(QObject::tr("Top-level commands:"));
QSet<QString> sorted;
- for (auto syntax: Module::self()->syntax()) {
+ for (auto syntax: SyntaxTree::self()->syntax()) {
sorted.insert(syntax.keyword);
}
for (auto keyword: sorted) {
state.printLine(keyword, 1);
}
- } else if (const Module::Syntax *syntax = command.first) {
+ } else if (const SyntaxTree::Syntax *syntax = command.first) {
//TODO: get parent!
state.print(QObject::tr("Command `%1`").arg(syntax->keyword));
diff --git a/akonadi2_cli/modules/core_syntax.h \
b/akonadi2_cli/syntax_modules/core_syntax.h similarity index 94%
rename from akonadi2_cli/modules/core_syntax.h
rename to 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 @@
#pragma once
-#include "module.h"
+#include "syntaxtree.h"
namespace CoreSyntax
{
- Module::SyntaxList syntax();
+ SyntaxTree::SyntaxList syntax();
bool exit(const QStringList &commands, State &state);
bool showHelp(const QStringList &commands, State &);
}
diff --git a/akonadi2_cli/module.cpp b/akonadi2_cli/syntaxtree.cpp
similarity index 80%
rename from akonadi2_cli/module.cpp
rename to akonadi2_cli/syntaxtree.cpp
index 5fd68b4..ea017db 100644
--- a/akonadi2_cli/module.cpp
+++ b/akonadi2_cli/syntaxtree.cpp
@@ -17,22 +17,22 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "module.h"
+#include "syntaxtree.h"
#include <QCoreApplication>
#include <QDebug>
// TODO: needs a proper registry; making "core" modules plugins is
// almost certainly overkill, but this is not the way either
-#include "modules/core_syntax.h"
+#include "syntax_modules/core_syntax.h"
-Module *Module::s_module = 0;
+SyntaxTree *SyntaxTree::s_module = 0;
-Module::Syntax::Syntax()
+SyntaxTree::Syntax::Syntax()
{
}
-Module::Syntax::Syntax(const QString &k, const QString &helpText, \
std::function<bool(const QStringList &, State &)> l, Interactivity inter) \
+SyntaxTree::Syntax::Syntax(const QString &k, const QString &helpText, \
std::function<bool(const QStringList &, State &)> l, Interactivity inter) : \
keyword(k), help(helpText),
interactivity(inter),
@@ -40,30 +40,30 @@ Module::Syntax::Syntax(const QString &k, const QString &helpText, \
std::function< {
}
-Module::Module()
+SyntaxTree::SyntaxTree()
{
- QVector<std::function<SyntaxList()> > syntaxModules;
- syntaxModules << &CoreSyntax::syntax;
- for (auto syntaxModule: syntaxModules) {
- m_syntax += syntaxModule();
+ QVector<std::function<SyntaxList()> > syntaxSyntaxTrees;
+ syntaxSyntaxTrees << &CoreSyntax::syntax;
+ for (auto syntaxSyntaxTree: syntaxSyntaxTrees) {
+ m_syntax += syntaxSyntaxTree();
}
}
-Module *Module::self()
+SyntaxTree *SyntaxTree::self()
{
if (!s_module) {
- s_module = new Module;
+ s_module = new SyntaxTree;
}
return s_module;
}
-Module::SyntaxList Module::syntax() const
+SyntaxTree::SyntaxList SyntaxTree::syntax() const
{
return m_syntax;
}
-bool Module::run(const QStringList &commands)
+bool SyntaxTree::run(const QStringList &commands)
{
Command command = match(commands);
if (command.first && command.first->lambda) {
@@ -78,7 +78,7 @@ bool Module::run(const QStringList &commands)
return false;
}
-Module::Command Module::match(const QStringList &commandLine) const
+SyntaxTree::Command SyntaxTree::match(const QStringList &commandLine) const
{
if (commandLine.isEmpty()) {
return Command();
@@ -115,7 +115,7 @@ Module::Command Module::match(const QStringList &commandLine) \
const return Command();
}
-Module::SyntaxList Module::nearestSyntax(const QStringList &words, const QString \
&fragment) const +SyntaxTree::SyntaxList SyntaxTree::nearestSyntax(const QStringList \
&words, const QString &fragment) const {
SyntaxList matches;
@@ -157,7 +157,7 @@ Module::SyntaxList Module::nearestSyntax(const QStringList \
&words, const QString return matches;
}
-QStringList Module::tokenize(const QString &text)
+QStringList SyntaxTree::tokenize(const QString &text)
{
//TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']
return text.split(" ");
diff --git a/akonadi2_cli/module.h b/akonadi2_cli/syntaxtree.h
similarity index 92%
rename from akonadi2_cli/module.h
rename to akonadi2_cli/syntaxtree.h
index 1149f4f..54b867f 100644
--- a/akonadi2_cli/module.h
+++ b/akonadi2_cli/syntaxtree.h
@@ -24,7 +24,7 @@
#include <QStringList>
#include <QVector>
-class Module
+class SyntaxTree
{
public:
struct Syntax
@@ -49,9 +49,9 @@ public:
};
typedef std::pair<const Syntax *, QStringList> Command;
- typedef QVector<Module::Syntax> SyntaxList;
+ typedef QVector<SyntaxTree::Syntax> SyntaxList;
- static Module *self();
+ static SyntaxTree *self();
SyntaxList syntax() const;
Command match(const QStringList &commands) const;
@@ -62,11 +62,11 @@ public:
static QStringList tokenize(const QString &text);
private:
- Module();
+ SyntaxTree();
Command matches(const QStringList &commands) const;
SyntaxList m_syntax;
State m_state;
- static Module *s_module;
+ static SyntaxTree *s_module;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic