File indexing completed on 2024-04-28 05:49:16
0001 /*************************************************************************** 0002 bash_parser.cpp - description 0003 ------------------- 0004 begin : dec 12 2008 0005 author : Daniel Dumitrache 0006 email : daniel.dumitrache@gmail.com 0007 ***************************************************************************/ 0008 /*************************************************************************** 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 ***************************************************************************/ 0011 0012 #include "plugin_katesymbolviewer.h" 0013 0014 void KatePluginSymbolViewerView::parseBashSymbols(void) 0015 { 0016 if (!m_mainWindow->activeView()) { 0017 return; 0018 } 0019 0020 QTreeWidgetItem *node = nullptr; 0021 QTreeWidgetItem *funcNode = nullptr; 0022 QTreeWidgetItem *lastFuncNode = nullptr; 0023 0024 // It is necessary to change names 0025 m_func->setText(i18n("Show Functions")); 0026 0027 if (m_treeOn->isChecked()) { 0028 funcNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Functions"))); 0029 funcNode->setIcon(0, m_icon_function); 0030 0031 if (m_expandOn->isChecked()) { 0032 m_symbols->expandItem(funcNode); 0033 } 0034 0035 lastFuncNode = funcNode; 0036 0037 m_symbols->setRootIsDecorated(1); 0038 } else { 0039 m_symbols->setRootIsDecorated(0); 0040 } 0041 0042 KTextEditor::Document *kDoc = m_mainWindow->activeView()->document(); 0043 0044 static const QRegularExpression function_regexp(QLatin1String("^(function )?([a-zA-Z0-9-_]+) *\\( *\\)")); 0045 QRegularExpressionMatch match; 0046 0047 for (int i = 0; i < kDoc->lines(); i++) { 0048 QString currline = kDoc->line(i).trimmed().simplified(); 0049 0050 if (currline.isEmpty() || currline.at(0) == QLatin1Char('#')) { 0051 continue; 0052 } 0053 0054 if (m_func->isChecked()) { 0055 match = function_regexp.match(currline); 0056 if (match.hasMatch()) { 0057 QString funcName = match.captured(2); 0058 funcName.append(QLatin1String("()")); 0059 0060 if (m_treeOn->isChecked()) { 0061 node = new QTreeWidgetItem(funcNode, lastFuncNode); 0062 lastFuncNode = node; 0063 } else { 0064 node = new QTreeWidgetItem(m_symbols); 0065 } 0066 0067 node->setText(0, funcName); 0068 node->setIcon(0, m_icon_function); 0069 node->setText(1, QString::number(i, 10)); 0070 } 0071 } 0072 } 0073 }