File indexing completed on 2024-04-28 05:49:17
0001 /*************************************************************************** 0002 tcl_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 0014 #include "plugin_katesymbolviewer.h" 0015 0016 void KatePluginSymbolViewerView::parseTclSymbols(void) 0017 { 0018 if (!m_mainWindow->activeView()) { 0019 return; 0020 } 0021 0022 QString prevline; 0023 bool prevComment = false; 0024 QString varStr(QStringLiteral("set ")); 0025 QString procStr(QStringLiteral("proc")); 0026 QString stripped; 0027 int args_par = 0, graph = 0; 0028 char block = 0, parse_func = 0; 0029 0030 QTreeWidgetItem *node = nullptr; 0031 QTreeWidgetItem *mcrNode = nullptr, *clsNode = nullptr; 0032 QTreeWidgetItem *lastMcrNode = nullptr, *lastClsNode = nullptr; 0033 0034 if (m_treeOn->isChecked()) { 0035 clsNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Functions"))); 0036 mcrNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Globals"))); 0037 clsNode->setIcon(0, m_icon_function); 0038 mcrNode->setIcon(0, m_icon_variable); 0039 0040 lastMcrNode = mcrNode; 0041 lastClsNode = clsNode; 0042 0043 if (m_expandOn->isChecked()) { 0044 m_symbols->expandItem(clsNode); 0045 m_symbols->expandItem(mcrNode); 0046 } 0047 m_symbols->setRootIsDecorated(1); 0048 } else { 0049 m_symbols->setRootIsDecorated(0); 0050 } 0051 0052 KTextEditor::Document *kDoc = m_mainWindow->activeView()->document(); 0053 0054 // positions.resize(kDoc->numLines() + 3); // Maximum m_symbols number o.O 0055 // positions.fill(0); 0056 0057 for (int i = 0; i < kDoc->lines(); i++) { 0058 QString currline = kDoc->line(i); 0059 currline = currline.trimmed(); 0060 bool comment = false; 0061 // qDebug(13000)<<currline; 0062 if (currline.isEmpty()) { 0063 continue; 0064 } 0065 if (currline.at(0) == QLatin1Char('#')) { 0066 comment = true; 0067 } 0068 0069 if (i > 0) { 0070 prevline = kDoc->line(i - 1); 0071 if (prevline.endsWith(QLatin1String("\\")) && prevComment) { 0072 comment = true; 0073 } 0074 } 0075 prevComment = comment; 0076 0077 if (!comment) { 0078 if (currline.startsWith(varStr) && block == 0) { 0079 if (m_macro->isChecked()) // not really a macro, but a variable 0080 { 0081 stripped = currline.right(currline.length() - 3); 0082 stripped = stripped.simplified(); 0083 int fnd = stripped.indexOf(QLatin1Char(' ')); 0084 // fnd = stripped.indexOf(QLatin1Char(';')); 0085 if (fnd > 0) { 0086 stripped = stripped.left(fnd); 0087 } 0088 0089 if (m_treeOn->isChecked()) { 0090 node = new QTreeWidgetItem(mcrNode, lastMcrNode); 0091 lastMcrNode = node; 0092 } else { 0093 node = new QTreeWidgetItem(m_symbols); 0094 } 0095 node->setText(0, stripped); 0096 node->setIcon(0, m_icon_function); 0097 node->setText(1, QString::number(i, 10)); 0098 stripped.clear(); 0099 } // macro 0100 } // starts with "set" 0101 0102 else if (currline.startsWith(procStr)) { 0103 parse_func = 1; 0104 } 0105 0106 if (parse_func == 1) { 0107 for (int j = 0; j < currline.length(); j++) { 0108 if (block == 1) { 0109 if (currline.at(j) == QLatin1Char('{')) { 0110 graph++; 0111 } 0112 if (currline.at(j) == QLatin1Char('}')) { 0113 graph--; 0114 if (graph == 0) { 0115 block = 0; 0116 parse_func = 0; 0117 continue; 0118 } 0119 } 0120 } 0121 if (block == 0) { 0122 stripped += currline.at(j); 0123 if (currline.at(j) == QLatin1Char('{')) { 0124 args_par++; 0125 } 0126 if (currline.at(j) == QLatin1Char('}')) { 0127 args_par--; 0128 if (args_par == 0) { 0129 // stripped = stripped.simplified(); 0130 if (m_func->isChecked()) { 0131 if (m_treeOn->isChecked()) { 0132 node = new QTreeWidgetItem(clsNode, lastClsNode); 0133 lastClsNode = node; 0134 } else { 0135 node = new QTreeWidgetItem(m_symbols); 0136 } 0137 node->setText(0, stripped); 0138 node->setIcon(0, m_icon_variable); 0139 node->setText(1, QString::number(i, 10)); 0140 } 0141 stripped.clear(); 0142 block = 1; 0143 } 0144 } 0145 } // block = 0 0146 } // for j loop 0147 } // m_func->isChecked() 0148 } // not a comment 0149 } // for i loop 0150 0151 // positions.resize(m_symbols->itemIndex(node) + 1); 0152 }