diff options
Diffstat (limited to 'sinksh/syntaxtree.cpp')
-rw-r--r-- | sinksh/syntaxtree.cpp | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/sinksh/syntaxtree.cpp b/sinksh/syntaxtree.cpp index 4860582..3380b04 100644 --- a/sinksh/syntaxtree.cpp +++ b/sinksh/syntaxtree.cpp | |||
@@ -29,10 +29,7 @@ Syntax::Syntax() | |||
29 | } | 29 | } |
30 | 30 | ||
31 | Syntax::Syntax(const QString &k, const QString &helpText, std::function<bool(const QStringList &, State &)> l, Interactivity inter) | 31 | Syntax::Syntax(const QString &k, const QString &helpText, std::function<bool(const QStringList &, State &)> l, Interactivity inter) |
32 | : keyword(k), | 32 | : keyword(k), help(helpText), interactivity(inter), lambda(l) |
33 | help(helpText), | ||
34 | interactivity(inter), | ||
35 | lambda(l) | ||
36 | { | 33 | { |
37 | } | 34 | } |
38 | 35 | ||
@@ -75,10 +72,10 @@ bool SyntaxTree::run(const QStringList &commands) | |||
75 | m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); | 72 | m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); |
76 | } else { | 73 | } else { |
77 | QStringList keywordList; | 74 | QStringList keywordList; |
78 | for (auto syntax: command.first->children) { | 75 | for (auto syntax : command.first->children) { |
79 | keywordList << syntax.keyword; | 76 | keywordList << syntax.keyword; |
80 | } | 77 | } |
81 | const QString keywords = keywordList.join(" " ); | 78 | const QString keywords = keywordList.join(" "); |
82 | m_state.printError(QObject::tr("Command requires additional arguments, one of: %1").arg(keywords)); | 79 | m_state.printError(QObject::tr("Command requires additional arguments, one of: %1").arg(keywords)); |
83 | } | 80 | } |
84 | } else { | 81 | } else { |
@@ -129,9 +126,9 @@ Syntax::List SyntaxTree::nearestSyntax(const QStringList &words, const QString & | |||
129 | { | 126 | { |
130 | Syntax::List matches; | 127 | Syntax::List matches; |
131 | 128 | ||
132 | //qDebug() << "words are" << words; | 129 | // qDebug() << "words are" << words; |
133 | if (words.isEmpty()) { | 130 | if (words.isEmpty()) { |
134 | for (const Syntax &syntax: m_syntax) { | 131 | for (const Syntax &syntax : m_syntax) { |
135 | if (syntax.keyword.startsWith(fragment)) { | 132 | if (syntax.keyword.startsWith(fragment)) { |
136 | matches.push_back(syntax); | 133 | matches.push_back(syntax); |
137 | } | 134 | } |
@@ -153,7 +150,7 @@ Syntax::List SyntaxTree::nearestSyntax(const QStringList &words, const QString & | |||
153 | } | 150 | } |
154 | } | 151 | } |
155 | 152 | ||
156 | //qDebug() << "exiting with" << lastFullSyntax.keyword << words.last(); | 153 | // qDebug() << "exiting with" << lastFullSyntax.keyword << words.last(); |
157 | if (lastFullSyntax.keyword == words.last()) { | 154 | if (lastFullSyntax.keyword == words.last()) { |
158 | syntaxIt = lastFullSyntax.children; | 155 | syntaxIt = lastFullSyntax.children; |
159 | while (syntaxIt.hasNext()) { | 156 | while (syntaxIt.hasNext()) { |
@@ -175,7 +172,7 @@ State &SyntaxTree::state() | |||
175 | 172 | ||
176 | QStringList SyntaxTree::tokenize(const QString &text) | 173 | QStringList SyntaxTree::tokenize(const QString &text) |
177 | { | 174 | { |
178 | //TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']a | 175 | // TODO: properly tokenize (e.g. "foo bar" should not become ['"foo', 'bar"']a |
179 | static const QVector<QChar> quoters = QVector<QChar>() << '"' << '\''; | 176 | static const QVector<QChar> quoters = QVector<QChar>() << '"' << '\''; |
180 | QStringList tokens; | 177 | QStringList tokens; |
181 | QString acc; | 178 | QString acc; |
@@ -218,4 +215,3 @@ QStringList SyntaxTree::tokenize(const QString &text) | |||
218 | 215 | ||
219 | return tokens; | 216 | return tokens; |
220 | } | 217 | } |
221 | |||