File indexing completed on 2024-04-28 05:49:16

0001 /***************************************************************************
0002                           perl_parser.cpp  -  description
0003                              -------------------
0004     begin                : Apr 2 2003
0005     author               : 2003 Massimo Callegari
0006     email                : massimocallegari@yahoo.it
0007  ***************************************************************************/
0008 /***************************************************************************
0009  *                                                                         *
0010  *   SPDX-License-Identifier: GPL-2.0-or-later
0011  *                                                                         *
0012  ***************************************************************************/
0013 #include "plugin_katesymbolviewer.h"
0014 
0015 void KatePluginSymbolViewerView::parsePerlSymbols(void)
0016 {
0017     if (!m_mainWindow->activeView()) {
0018         return;
0019     }
0020 
0021     m_macro->setText(i18n("Show Uses"));
0022     m_struct->setText(i18n("Show Pragmas"));
0023     m_func->setText(i18n("Show Subroutines"));
0024     bool is_comment = false;
0025     QTreeWidgetItem *node = nullptr;
0026     QTreeWidgetItem *mcrNode = nullptr, *sctNode = nullptr, *clsNode = nullptr;
0027     QTreeWidgetItem *lastMcrNode = nullptr, *lastSctNode = nullptr, *lastClsNode = nullptr;
0028 
0029     KTextEditor::Document *kv = m_mainWindow->activeView()->document();
0030 
0031     // kdDebug(13000)<<"Lines counted :"<<kv->numLines()<<endl;
0032     if (m_treeOn->isChecked()) {
0033         mcrNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Uses")));
0034         sctNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Pragmas")));
0035         clsNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Subroutines")));
0036         mcrNode->setIcon(0, m_icon_block);
0037         sctNode->setIcon(0, m_icon_context);
0038         clsNode->setIcon(0, m_icon_class);
0039 
0040         if (m_expandOn->isChecked()) {
0041             m_symbols->expandItem(mcrNode);
0042             m_symbols->expandItem(sctNode);
0043             m_symbols->expandItem(clsNode);
0044         }
0045         lastMcrNode = mcrNode;
0046         lastSctNode = sctNode;
0047         lastClsNode = clsNode;
0048         m_symbols->setRootIsDecorated(1);
0049     } else {
0050         m_symbols->setRootIsDecorated(0);
0051     }
0052 
0053     for (int i = 0; i < kv->lines(); i++) {
0054         QString cl = kv->line(i);
0055         // qDebug()<< "Line " << i << " : "<< cl;
0056 
0057         if (cl.isEmpty() || cl.at(0) == QLatin1Char('#')) {
0058             continue;
0059         }
0060         if (cl.indexOf(QRegularExpression(QLatin1String("^=[a-zA-Z]"))) >= 0) {
0061             is_comment = true;
0062         }
0063         if (cl.indexOf(QRegularExpression(QLatin1String("^=cut$"))) >= 0) {
0064             is_comment = false;
0065             continue;
0066         }
0067         if (is_comment) {
0068             continue;
0069         }
0070 
0071         cl = cl.trimmed();
0072         // qDebug()<<"Trimmed line " << i << " : "<< cl;
0073 
0074         if (cl.indexOf(QRegularExpression(QLatin1String("^use +[A-Z]"))) == 0 && m_macro->isChecked()) {
0075             QString stripped = cl.remove(QRegularExpression(QLatin1String("^use +")));
0076             // stripped=stripped.replace( QRegularExpression(QLatin1String(";$")), "" ); // Doesn't work ??
0077             stripped = stripped.left(stripped.indexOf(QLatin1Char(';')));
0078             if (m_treeOn->isChecked()) {
0079                 node = new QTreeWidgetItem(mcrNode, lastMcrNode);
0080                 lastMcrNode = node;
0081             } else {
0082                 node = new QTreeWidgetItem(m_symbols);
0083             }
0084 
0085             node->setText(0, stripped);
0086             node->setIcon(0, m_icon_block);
0087             node->setText(1, QString::number(i, 10));
0088         }
0089 #if 1
0090         if (cl.indexOf(QRegularExpression(QLatin1String("^use +[a-z]"))) == 0 && m_struct->isChecked()) {
0091             QString stripped = cl.remove(QRegularExpression(QLatin1String("^use +")));
0092             stripped.remove(QRegularExpression(QLatin1String(";$")));
0093             if (m_treeOn->isChecked()) {
0094                 node = new QTreeWidgetItem(sctNode, lastSctNode);
0095                 lastMcrNode = node;
0096             } else {
0097                 node = new QTreeWidgetItem(m_symbols);
0098             }
0099 
0100             node->setText(0, stripped);
0101             node->setIcon(0, m_icon_context);
0102             node->setText(1, QString::number(i, 10));
0103         }
0104 #endif
0105 #if 1
0106         if (cl.indexOf(QRegularExpression(QLatin1String("^sub +"))) == 0 && m_func->isChecked()) {
0107             QString stripped = cl.remove(QRegularExpression(QLatin1String("^sub +")));
0108             stripped.remove(QRegularExpression(QLatin1String("[{;] *$")));
0109             if (m_treeOn->isChecked()) {
0110                 node = new QTreeWidgetItem(clsNode, lastClsNode);
0111                 lastClsNode = node;
0112             } else {
0113                 node = new QTreeWidgetItem(m_symbols);
0114             }
0115             node->setText(0, stripped);
0116 
0117             if (!stripped.isEmpty() && stripped.at(0) == QLatin1Char('_')) {
0118                 node->setIcon(0, m_icon_function);
0119             } else {
0120                 node->setIcon(0, m_icon_class);
0121             }
0122 
0123             node->setText(1, QString::number(i, 10));
0124         }
0125 #endif
0126     }
0127 }