diff options
author | Aaron Seigo <aseigo@kde.org> | 2015-12-25 10:47:02 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2015-12-25 10:47:02 +0100 |
commit | 1231996ec2668e330ead79a16edf85ded1e07e48 (patch) | |
tree | faa0fb06584a20553a0a64292f1cf091b13a80d1 /akonadish/syntax_modules/core_syntax.cpp | |
parent | 908dc9b172a08bfa219a834e15916e9fcfc3c4ec (diff) | |
download | sink-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.cpp | 25 |
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 | ||
125 | void 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 | |||
142 | bool printSyntaxTree(const QStringList &, State &state) | ||
143 | { | ||
144 | printSyntaxBranch(state, SyntaxTree::self()->syntax(), 0); | ||
145 | return true; | ||
146 | } | ||
147 | |||
125 | Syntax::List syntax() | 148 | Syntax::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")); |