[UPDATE] Build-in FunctionList in progress.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1001 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/trunk
Don Ho 2013-01-06 01:50:12 +00:00
parent 7516aa5437
commit ef6c612dc7
8 changed files with 344 additions and 13 deletions

View File

@ -451,7 +451,7 @@ BEGIN
MENUITEM "Document Map", IDM_VIEW_DOC_MAP
//MENUITEM "Function List", IDM_VIEW_FUNC_LIST
MENUITEM "Function List", IDM_VIEW_FUNC_LIST
MENUITEM SEPARATOR
MENUITEM "Synchronize Vertical Scrolling", IDM_VIEW_SYNSCROLLV
MENUITEM "Synchronize Horizontal Scrolling", IDM_VIEW_SYNSCROLLH

View File

@ -253,7 +253,7 @@ void FunctionListPanel::reload()
// clean up
removeAllEntries();
generic_string funcBegin = TEXT("^[\\s]*");
generic_string funcBegin = TEXT("^[\\t ]*");
generic_string qualifier_maybe = TEXT("((static|const)[\\s]+)?");
generic_string returnType = TEXT("[\\w]+");
generic_string space_starMaybe = TEXT("([\\s]+|\\*[\\s]+|[\\s]+\\*|[\\s]+\\*[\\s]+)");
@ -271,7 +271,7 @@ void FunctionListPanel::reload()
secondSearch += TEXT("\\(");
int docLen = (*_ppEditView)->getCurrentDocLen();
//int docLen = (*_ppEditView)->getCurrentDocLen();
vector<foundInfo> fi;
vector<generic_string> regExpr1;
vector<generic_string> regExpr2;
@ -289,11 +289,18 @@ void FunctionListPanel::reload()
generic_string str3 = TEXT("[\\w]+");
classRegExprArray.push_back(str1.c_str());
classRegExprArray.push_back(str2.c_str());
classRegExprArray.push_back(str3.c_str());
//classRegExprArray.push_back(str3.c_str());
//parse(fi, 0, docLen, function.c_str(), regExpr1, regExpr2);
/*
const TCHAR bodyOpenSymbol[] = TEXT("\\{");
const TCHAR bodyCloseSymbol[] = TEXT("\\}");
parse2(fi, 0, docLen, classRegExpr.c_str(), classRegExprArray, bodyOpenSymbol, bodyCloseSymbol, function.c_str(), regExpr1);
*/
generic_string fn = ((*_ppEditView)->getCurrentBuffer())->getFileName();
TCHAR *ext = ::PathFindExtension(fn.c_str());
_funcParserMgr.parse(fi, ext);
for (size_t i = 0; i < fi.size(); i++)
{

View File

@ -35,6 +35,7 @@
#endif //DOCKINGDLGINTERFACE_H
#include "functionListPanel_rc.h"
#include "functionParser.h"
class ScintillaEditView;
@ -64,13 +65,6 @@ root
*/
struct foundInfo {
generic_string _data;
generic_string _data2;
int _pos;
int _pos2;
//foundInfo(): /*_data(TEXT("")), _data2(TEXT("")), _pos(-1) _pos2(-1) */{};
};
class FunctionListPanel : public DockingDlgInterface {
public:
@ -79,6 +73,7 @@ public:
void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) {
DockingDlgInterface::init(hInst, hPere);
_ppEditView = ppEditView;
/*_isValidated = */_funcParserMgr.init(TEXT("funcList.xml"), ppEditView);
};
virtual void display(bool toShow = true) const {
@ -109,6 +104,7 @@ protected:
private:
ScintillaEditView **_ppEditView;
FunctionParsersManager _funcParserMgr;
std::vector<FuncInfo> _funcInfos;
std::vector< std::pair<int, int> > _skipZones;
generic_string parseSubLevel(size_t begin, size_t end, std::vector< generic_string > dataToSearch, int & foundPos);

View File

@ -0,0 +1,171 @@
// This file is part of Notepad++ project
// Copyright (C)2012 Don HO <don.h@free.fr>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// Note that the GPL places important restrictions on "derived works", yet
// it does not provide a detailed definition of that term. To avoid
// misunderstandings, we consider an application to constitute a
// "derivative work" for the purpose of this license if it does any of the
// following:
// 1. Integrates source code from Notepad++.
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
// installer, such as those produced by InstallShield.
// 3. Links to a library or executes a program that does any of the above.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "precompiledHeaders.h"
#include "ScintillaEditView.h"
#include "functionParser.h"
bool FunctionParsersManager::init(generic_string xmlPath, ScintillaEditView ** ppEditView)
{
_ppEditView = ppEditView;
bool loadOkay = false;
if (PathFileExists(xmlPath.c_str()))
{
_pXmlFuncListDoc = new TiXmlDocument(xmlPath);
loadOkay = _pXmlFuncListDoc->LoadFile();
if (loadOkay)
{
loadOkay = getFuncListFromXmlTree();
}
}
return loadOkay;
}
bool FunctionParsersManager::getFuncListFromXmlTree()
{
if (!_pXmlFuncListDoc)
return false;
TiXmlNode *root = _pXmlFuncListDoc->FirstChild(TEXT("NotepadPlus"));
if (!root)
return false;
root = root->FirstChild(TEXT("functionList"));
if (!root)
return false;
TiXmlNode *parserRoot = root->FirstChild(TEXT("parsers"));
if (!root)
return false;
for (TiXmlNode *childNode = parserRoot->FirstChildElement(TEXT("parser"));
childNode;
childNode = childNode->NextSibling(TEXT("parser")) )
{
const TCHAR *id = (childNode->ToElement())->Attribute(TEXT("id"));
if (!id || !id[0])
continue;
const TCHAR *displayName = (childNode->ToElement())->Attribute(TEXT("displayName"));
if (!displayName || !displayName[0])
displayName = id;
TiXmlNode *classRangeParser = childNode->FirstChild(TEXT("classRange"));
if (classRangeParser)
{
const TCHAR *mainExpr = NULL;
const TCHAR *openSymbole = NULL;
const TCHAR *closeSymbole = NULL;
std::vector<generic_string> classNameExprArray;
const TCHAR *functionExpr = NULL;
std::vector<generic_string> functionNameExprArray;
mainExpr = (classRangeParser->ToElement())->Attribute(TEXT("mainExpr"));
if (!mainExpr)
continue;
openSymbole = (classRangeParser->ToElement())->Attribute(TEXT("openSymbole"));
closeSymbole = (classRangeParser->ToElement())->Attribute(TEXT("closeSymbole"));
TiXmlNode *classNameParser = childNode->FirstChild(TEXT("className"));
if (classNameParser)
{
for (TiXmlNode *childNode2 = classNameParser->FirstChildElement(TEXT("nameExpr"));
childNode2;
childNode2 = childNode2->NextSibling(TEXT("nameExpr")) )
{
const TCHAR *expr = (childNode2->ToElement())->Attribute(TEXT("expr"));
if (expr && expr[0])
classNameExprArray.push_back(expr);
}
}
TiXmlNode *functionParser = childNode->FirstChild(TEXT("function"));
if (functionParser)
{
functionExpr = (classRangeParser->ToElement())->Attribute(TEXT("mainExpr"));
if (!functionExpr)
continue;
TiXmlNode *functionNameParser = childNode->FirstChild(TEXT("functionName"));
if (functionNameParser)
{
for (TiXmlNode *childNode3 = functionNameParser->FirstChildElement(TEXT("funcNameExpr"));
childNode3;
childNode3 = childNode3->NextSibling(TEXT("funcNameExpr")) )
{
const TCHAR *expr = (childNode3->ToElement())->Attribute(TEXT("expr"));
if (expr && expr[0])
functionNameExprArray.push_back(expr);
}
}
}
_parsers.push_back(new FunctionZoneParser(id, displayName, mainExpr, openSymbole, closeSymbole, classNameExprArray, functionExpr, functionNameExprArray));
}
else
{
TiXmlNode *functionParser = childNode->FirstChild(TEXT("fuction"));
if (!functionParser)
{
continue;
}
}
//_parsers.push_back();
}
return (_parsers.size() != 0);
}
FunctionParser * FunctionParsersManager::getParser(generic_string ext)
{
return NULL;
}
void FunctionZoneParser::parse(std::vector<foundInfo> & /*foundInfos*/)
{
}
bool FunctionParsersManager::parse(std::vector<foundInfo> & foundInfos, generic_string ext)
{
if (!_pXmlFuncListDoc)
return false;
// Serch the right parser from the given ext in the map
FunctionParser *fp = getParser(ext);
if (!fp)
return false;
// parse
fp->parse(foundInfos);
return true;
}

View File

@ -0,0 +1,100 @@
// This file is part of Notepad++ project
// Copyright (C)2003 Don HO <don.h@free.fr>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// Note that the GPL places important restrictions on "derived works", yet
// it does not provide a detailed definition of that term. To avoid
// misunderstandings, we consider an application to constitute a
// "derivative work" for the purpose of this license if it does any of the
// following:
// 1. Integrates source code from Notepad++.
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
// installer, such as those produced by InstallShield.
// 3. Links to a library or executes a program that does any of the above.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef FUNCTIONPARSER_H
#define FUNCTIONPARSER_H
class ScintillaEditView;
class TiXmlDocument;
struct foundInfo {
generic_string _data;
generic_string _data2;
int _pos;
int _pos2;
//foundInfo(): /*_data(TEXT("")), _data2(TEXT("")), _pos(-1) _pos2(-1) */{};
};
class FunctionParser {
public:
FunctionParser(const TCHAR *id, const TCHAR *displayName): _id(id), _displayName(displayName){};
virtual void parse(std::vector<foundInfo> & foundInfos) = 0;
protected:
generic_string _id;
generic_string _displayName;
};
class FunctionZoneParser : public FunctionParser {
public:
FunctionZoneParser(const TCHAR *id, const TCHAR *displayName, generic_string rangeExpr, generic_string openSymbole, generic_string closeSymbole,
std::vector<generic_string> classNameExprArray, generic_string functionExpr, std::vector<generic_string> functionNameExprArray):
FunctionParser(id, displayName), _rangeExpr(rangeExpr), _openSymbole(openSymbole), _closeSymbole(closeSymbole),
_classNameExprArray(classNameExprArray), _functionExpr(functionExpr), _functionNameExprArray(functionNameExprArray) {};
void parse(std::vector<foundInfo> & foundInfos);
private:
generic_string _rangeExpr;
generic_string _openSymbole;
generic_string _closeSymbole;
std::vector<generic_string> _classNameExprArray;
generic_string _functionExpr;
std::vector<generic_string> _functionNameExprArray;
};
class FunctionUnitParser : public FunctionParser {
public:
FunctionUnitParser(TCHAR *id, TCHAR *displayName,
generic_string mainExpr, std::vector<generic_string> functionNameExprArray,
std::vector<generic_string> classNameExprArray): FunctionParser(id, displayName), _functionExpr(mainExpr),
_functionNameExprArray(functionNameExprArray), _classNameExprArray(classNameExprArray){};
void parse(std::vector<foundInfo> & foundInfos);
private:
generic_string _functionExpr;
std::vector<generic_string> _functionNameExprArray;
std::vector<generic_string> _classNameExprArray;
};
class FunctionParsersManager {
public:
FunctionParsersManager() : _ppEditView(NULL), _pXmlFuncListDoc(NULL){};
bool init(generic_string xmlPath, ScintillaEditView ** ppEditView);
bool parse(std::vector<foundInfo> & foundInfos, generic_string ext);
private:
ScintillaEditView **_ppEditView;
std::vector<FunctionParser *> _parsers;
TiXmlDocument *_pXmlFuncListDoc;
bool getFuncListFromXmlTree();
FunctionParser * getParser(generic_string ext);
};
#endif //FUNCTIONPARSER_H

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" ?>
<NotepadPlus>
<functionList>
<associationMap>
<association ext="h" id="cpp_class"/>
<association ext="hpp" id="cpp_class"/>
<association ext="hxx" id="cpp_class"/>
<association ext="c" id="c_cpp_function"/>
<association ext="cpp" id="c_cpp_function"/>
<association ext="cxx" id="c_cpp_function"/>
</associationMap>
<parsers>
<parser id="cpp_class" displayName="C++ Class">
<classRange
mainExpr="^[\t ]*(class|struct)[\t ]+[\w]+[\s]*(:[\s]*(public|protected|private)[\s]+[\w]+[\s]*)?\{"
openSymbole = "\{"
closeSymbole = "\}"
displayMode="node">
<className>
<nameExpr expr="(class|struct)[\t ]+[\w]+"/>
<nameExpr expr="[\t ]+[\w]+"/>
<nameExpr expr="[\w]+"/>
</className>
<function
mainExpr="^[\t ]*((static|const)[\s]+)?[\w]+([\s]+|\*[\s]+|[\s]+\*|[\s]+\*[\s]+)([\w_]+[\s]*::)?(?!(if|whil|for))[\w_]+[\s]*\([\n\w_,*&amp;\s]*\)([\s]*const[\s]*)?[\n\s]*\{">
<functionName>
<funcNameExpr expr="(?!(if|whil|for))[\w_]+[\s]*\("/>
<funcNameExpr expr="(?!(if|whil|for))[\w_]+"/>
</functionName>
</function>
</classRange>
</parser>
<parser id="c_cpp_function" displayName="C++/C source">
<function
mainExpr="^[\t ]*((static|const)[\s]+)?[\w]+([\s]+|\*[\s]+|[\s]+\*|[\s]+\*[\s]+)([\w_]+[\s]*::)?(?!(if|whil|for))[\w_]+[\s]*\([\n\w_,*&amp;\s]*\)([\s]*const[\s]*)?[\n\s]*\{"
displayMode="$className->$functionName">
<functionName>
<nameExpr expr="(?!(if|whil|for))[\w_]+[\s]*\("/>
<nameExpr expr="(?!(if|whil|for))[\w_]+"/>
</functionName>
<className>
<nameExpr expr="[\\w_]+(?=[\\s]*::)"/>
</className>
</function>
</parser>
</parsers>
</functionList>
</NotepadPlus>

View File

@ -180,11 +180,11 @@ const TCHAR FLAG_ALWAYS_ON_TOP[] = TEXT("-alwaysOnTop");
const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\
\r\
notepad++ [--help] [-multiInst] [-noPlugins] [-lLanguage] [-nLineNumber] [-cColumnNumber] [-xPos] [-yPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [fullFilePathName]\r\
notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-nLineNumber] [-cColumnNumber] [-xPos] [-yPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [fullFilePathName]\r\
\r\
--help : This help message\r\
-multiInst : Launch another Notepad++ instance\r\
-noPlugins : Launch Notepad++ without loading any plugin\r\
-noPlugin : Launch Notepad++ without loading any plugin\r\
-l : Launch Notepad++ by applying indicated language to the file to open\r\
-n : Launch Notepad++ by scrolling indicated line on the file to open\r\
-c : Launch Notepad++ on scrolling indicated column on the file to open\r\

View File

@ -307,6 +307,10 @@
RelativePath="..\src\WinControls\FunctionList\functionListPanel.cpp"
>
</File>
<File
RelativePath="..\src\WinControls\FunctionList\functionParser.cpp"
>
</File>
<File
RelativePath="..\src\ScitillaComponent\GoToLineDlg.cpp"
>
@ -1258,6 +1262,10 @@
RelativePath="..\src\WinControls\FunctionList\functionListPanel_rc.h"
>
</File>
<File
RelativePath="..\src\WinControls\FunctionList\functionParser.h"
>
</File>
<File
RelativePath="..\src\ScitillaComponent\GoToLineDlg.h"
>