From 1231996ec2668e330ead79a16edf85ded1e07e48 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 25 Dec 2015 10:47:02 +0100 Subject: print the syntax tree --- akonadish/syntax_modules/core_syntax.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'akonadish/syntax_modules/core_syntax.cpp') 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) return true; } +void printSyntaxBranch(State &state, const Syntax::List &list, int depth) +{ + if (list.isEmpty()) { + return; + } + + if (depth > 0) { + state.printLine("\\", depth); + } + + for (auto syntax: list) { + state.print("|-", depth); + state.printLine(syntax.keyword); + printSyntaxBranch(state, syntax.children, depth + 1); + } +} + +bool printSyntaxTree(const QStringList &, State &state) +{ + printSyntaxBranch(state, SyntaxTree::self()->syntax(), 0); + return true; +} + Syntax::List syntax() { Syntax::List syntax; @@ -131,6 +154,8 @@ Syntax::List syntax() help.completer = &CoreSyntax::showHelpCompleter; syntax << help; + syntax << Syntax("syntaxtree", QString(), &printSyntaxTree); + Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); set.children << Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); Syntax setTiming = Syntax(QObject::tr("timing"), QObject::tr("Whether or not to print the time commands take to complete")); -- cgit v1.2.3