summaryrefslogtreecommitdiffstats
path: root/akonadish/syntax_modules/core_syntax.cpp
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2015-12-25 10:47:02 +0100
committerAaron Seigo <aseigo@kde.org>2015-12-25 10:47:02 +0100
commit1231996ec2668e330ead79a16edf85ded1e07e48 (patch)
treefaa0fb06584a20553a0a64292f1cf091b13a80d1 /akonadish/syntax_modules/core_syntax.cpp
parent908dc9b172a08bfa219a834e15916e9fcfc3c4ec (diff)
downloadsink-1231996ec2668e330ead79a16edf85ded1e07e48.tar.gz
sink-1231996ec2668e330ead79a16edf85ded1e07e48.zip
print the syntax tree
Diffstat (limited to 'akonadish/syntax_modules/core_syntax.cpp')
-rw-r--r--akonadish/syntax_modules/core_syntax.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/akonadish/syntax_modules/core_syntax.cpp b/akonadish/syntax_modules/core_syntax.cpp
index 9cd6a6a..8f3219f 100644
--- a/akonadish/syntax_modules/core_syntax.cpp
+++ b/akonadish/syntax_modules/core_syntax.cpp
@@ -122,6 +122,29 @@ bool printCommandTiming(const QStringList &, State &state)
122 return true; 122 return true;
123} 123}
124 124
125void printSyntaxBranch(State &state, const Syntax::List &list, int depth)
126{
127 if (list.isEmpty()) {
128 return;
129 }
130
131 if (depth > 0) {
132 state.printLine("\\", depth);
133 }
134
135 for (auto syntax: list) {
136 state.print("|-", depth);
137 state.printLine(syntax.keyword);
138 printSyntaxBranch(state, syntax.children, depth + 1);
139 }
140}
141
142bool printSyntaxTree(const QStringList &, State &state)
143{
144 printSyntaxBranch(state, SyntaxTree::self()->syntax(), 0);
145 return true;
146}
147
125Syntax::List syntax() 148Syntax::List syntax()
126{ 149{
127 Syntax::List syntax; 150 Syntax::List syntax;
@@ -131,6 +154,8 @@ Syntax::List syntax()
131 help.completer = &CoreSyntax::showHelpCompleter; 154 help.completer = &CoreSyntax::showHelpCompleter;
132 syntax << help; 155 syntax << help;
133 156
157 syntax << Syntax("syntaxtree", QString(), &printSyntaxTree);
158
134 Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); 159 Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session"));
135 set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); 160 set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel);
136 Syntax setTiming = Syntax(QObject::tr("timing"), QObject::tr("Whether or not to print the time commands take to complete")); 161 Syntax setTiming = Syntax(QObject::tr("timing"), QObject::tr("Whether or not to print the time commands take to complete"));