[NEW_FEATURE] Add User Defined Languages support for the build-in function list.

[BUG_FIXED] Fix a minor problem of file extension support for the build-in function list.
[NEW] Add php, perl, xml, batch, ini and nsis for the build-in function list.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1113 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/trunk
Don Ho 11 years ago
parent 136dd24633
commit 3a593808a5

@ -195,8 +195,15 @@ void FunctionListPanel::reload()
const TCHAR *fn = ((*_ppEditView)->getCurrentBuffer())->getFileName();
LangType langID = ((*_ppEditView)->getCurrentBuffer())->getLangType();
const TCHAR *udln = NULL;
if (langID == L_USER)
{
udln = ((*_ppEditView)->getCurrentBuffer())->getUserDefineLangName();
}
TCHAR *ext = ::PathFindExtension(fn);
if (_funcParserMgr.parse(fi, langID) || _funcParserMgr.parse(fi, ext))
if (_funcParserMgr.parse(fi, AssociationInfo(-1, langID, ext, udln)))
{
_treeView.addItem(fn, NULL, INDEX_ROOT, TEXT("-1"));
}

@ -229,13 +229,14 @@ bool FunctionParsersManager::getFuncListFromXmlTree()
const TCHAR *langIDStr = (childNode->ToElement())->Attribute(TEXT("langID"), &langID);
const TCHAR *exts = (childNode->ToElement())->Attribute(TEXT("ext"));
const TCHAR *id = (childNode->ToElement())->Attribute(TEXT("id"));
if ((langIDStr || (exts && exts[0])) && (id && id[0]))
const TCHAR *userDefinedLangName = (childNode->ToElement())->Attribute(TEXT("userDefinedLangName"));
if (((langIDStr && langIDStr[0]) || (exts && exts[0]) || (userDefinedLangName && userDefinedLangName[0])) && (id && id[0]))
{
for (size_t i = 0, len = _parsers.size(); i < len; ++i)
{
if (_parsers[i]->_id == id)
{
_associationMap.push_back(AssociationInfo(i, langID, exts?exts:TEXT("")));
_associationMap.push_back(AssociationInfo(i, langIDStr?langID:-1, exts?exts:TEXT(""), userDefinedLangName?userDefinedLangName:TEXT("")));
break;
}
}
@ -246,29 +247,57 @@ bool FunctionParsersManager::getFuncListFromXmlTree()
return (_parsers.size() != 0);
}
FunctionParser * FunctionParsersManager::getParser(int langID)
FunctionParser * FunctionParsersManager::getParser(const AssociationInfo & assoInfo)
{
for (size_t i = 0, len = _associationMap.size(); i < len; ++i)
{
if (langID == _associationMap[i]._langID)
return _parsers[_associationMap[i]._id];
}
return NULL;
}
FunctionParser * FunctionParsersManager::getParser(generic_string ext)
{
if (ext == TEXT(""))
const unsigned char doNothing = 0;
const unsigned char checkLangID = 1;
const unsigned char checkUserDefined = 2;
const unsigned char checkExt = 3;
unsigned char choice = doNothing;
// langID != -1 && langID != L_USER
if (assoInfo._langID != -1 && assoInfo._langID != L_USER)
choice = checkLangID;
// langID == L_USER, we chack the userDefinedLangName
else if (assoInfo._langID == L_USER && assoInfo._userDefinedLangName != TEXT(""))
choice = checkUserDefined;
// langID == -1, we chack the ext
else if (assoInfo._langID == -1 && assoInfo._ext != TEXT(""))
choice = checkExt;
else
return NULL;
for (size_t i = 0, len = _associationMap.size(); i < len; ++i)
{
if (ext == _associationMap[i]._ext)
return _parsers[_associationMap[i]._id];
switch (choice)
{
case checkLangID:
{
if (assoInfo._langID == _associationMap[i]._langID)
return _parsers[_associationMap[i]._id];
}
break;
case checkUserDefined:
{
if (assoInfo._userDefinedLangName == _associationMap[i]._userDefinedLangName)
return _parsers[_associationMap[i]._id];
}
break;
case checkExt:
{
if (assoInfo._ext == _associationMap[i]._ext)
return _parsers[_associationMap[i]._id];
}
break;
}
}
return NULL;
}
void FunctionParser::funcParse(std::vector<foundInfo> & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName, const std::vector< std::pair<int, int> > * commentZones)
{
if (begin >= end)
@ -387,13 +416,13 @@ generic_string FunctionParser::parseSubLevel(size_t begin, size_t end, std::vect
}
}
bool FunctionParsersManager::parse(std::vector<foundInfo> & foundInfos, int langID)
bool FunctionParsersManager::parse(std::vector<foundInfo> & foundInfos, const AssociationInfo & assoInfo)
{
if (!_pXmlFuncListDoc)
return false;
// Serch the right parser from the given ext in the map
FunctionParser *fp = getParser(langID);
FunctionParser *fp = getParser(assoInfo);
if (!fp)
return false;
@ -404,24 +433,6 @@ bool FunctionParsersManager::parse(std::vector<foundInfo> & foundInfos, int lang
return true;
}
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
int docLen = (*_ppEditView)->getCurrentDocLen();
fp->parse(foundInfos, 0, docLen, _ppEditView);
return true;
}
size_t FunctionZoneParser::getBodyClosePos(size_t begin, const TCHAR *bodyOpenSymbol, const TCHAR *bodyCloseSymbol, ScintillaEditView **ppEditView)
{
size_t cntOpen = 1;

@ -114,8 +114,19 @@ struct AssociationInfo {
int _id;
int _langID;
generic_string _ext;
AssociationInfo(int id, int langID, const TCHAR *ext): _id(id), _langID(langID), _ext(ext){};
generic_string _userDefinedLangName;
AssociationInfo(int id, int langID, const TCHAR *ext, const TCHAR *userDefinedLangName): _id(id), _langID(langID) {
if (ext)
_ext = ext;
else
_ext = TEXT("");
if (userDefinedLangName)
_userDefinedLangName = userDefinedLangName;
else
_userDefinedLangName = TEXT("");
};
};
class FunctionParsersManager {
@ -123,8 +134,7 @@ public:
FunctionParsersManager() : _ppEditView(NULL), _pXmlFuncListDoc(NULL){};
~FunctionParsersManager();
bool init(generic_string xmlPath, ScintillaEditView ** ppEditView);
bool parse(std::vector<foundInfo> & foundInfos, int langID);
bool parse(std::vector<foundInfo> & foundInfos, generic_string ext);
bool parse(std::vector<foundInfo> & foundInfos, const AssociationInfo & assoInfo);
private:
ScintillaEditView **_ppEditView;
@ -135,8 +145,7 @@ private:
bool getFuncListFromXmlTree();
bool getZonePaserParameters(TiXmlNode *classRangeParser, generic_string &mainExprStr, generic_string &openSymboleStr, generic_string &closeSymboleStr, std::vector<generic_string> &classNameExprArray, generic_string &functionExprStr, std::vector<generic_string> &functionNameExprArray);
bool getUnitPaserParameters(TiXmlNode *functionParser, generic_string &mainExprStr, std::vector<generic_string> &functionNameExprArray, std::vector<generic_string> &classNameExprArray);
FunctionParser * getParser(generic_string ext);
FunctionParser * getParser(int langID);
FunctionParser * getParser(const AssociationInfo & assoInfo);
};
#endif //FUNCTIONPARSER_H

@ -14,17 +14,59 @@
L_CMAKE: 48 L_YAML: 49 L_COBOL 50 L_GUI4CLI: 51 L_D: 52 L_POWERSHELL: 53
L_R: 54 L_JSP: 55
-->
<association langID = "2" id="c_function"/>
<association langID = "3" id="c_cpp_function"/>
<association langID = "19" id="js_function"/>
<association langID="1" id="php_function"/>
<association langID="2" id="c_function"/>
<association langID="3" id="c_cpp_function"/>
<association langID="9" id="xml_node"/>
<association langID="12" id="batch_label"/>
<association langID="13" id="ini_section"/>
<association langID="19" id="js_function"/>
<association langID="21" id="perl_function"/>
<association langID="28" id="nsis_syntax"/>
<!--
if langID cannot be found above, you can still set the file extensions
<association ext="my_passer_ext1" id="my_passer_id"/>
<association ext="my_passer_ext2" id="my_passer_id"/>
<association ext=".my_passer_ext1" id="my_passer_id"/>
<association ext=".my_passer_ext2" id="my_passer_id"/>
for User Defined Languages:
<association userDefinedLangName="my user defined language" id="my_udl_passer_id"/>
<association userDefinedLangName="Autocad" id="my_autocad_passer_id"/>
-->
</associationMap>
<parsers>
<parser id="xml_node" displayName="XML Node" commentExpr="&lt;!--([^-]|-(?!-&gt;))*--&gt;">
<!-- Only match nodes with at least one attribute -->
<function
mainExpr="&lt;[\w\?]+[\t ]+\w+[\t ]*=[\t ]*&quot;[^&quot;]+&quot;"
displayMode="$functionName">
<functionName>
<nameExpr expr="[^&lt;]*"/>
</functionName>
</function>
</parser>
<parser id="batch_label" displayName="BAT Label" commentExpr="((::.*?$)|(REM.*?$))">
<function
mainExpr="^[\t ]*:\w+"
displayMode="$functionName">
<functionName>
<nameExpr expr="[^\t :]*"/>
</functionName>
</function>
</parser>
<parser id="ini_section" displayName="INI Section" commentExpr="((#.*?$)|(;.*?$))">
<function
mainExpr="^[\t ]*[\[&quot;][\w_.; \(\)-]+[\]&quot;]"
displayMode="$functionName">
<functionName>
<nameExpr expr="[^\[\]&quot;]*"/>
</functionName>
</function>
</parser>
<!-- Java parser : in progress, not working yet -->
<parser id="java" displayName="Java" commentExpr="((/\*.*?\*)/|(//.*?$))">
<classRange
@ -46,6 +88,7 @@
</function>
</classRange>
</parser>
<parser id="c_function" displayName="C source" commentExpr="((/\*.*?\*)/|(//.*?$))">
<function
mainExpr="^[\t ]*((static|const|virtual)[\s]+)?[\w:]+([\s]+[\w]+)?([\s]+|\*[\s]+|[\s]+\*|[\s]+\*[\s]+)([\w_]+[\s]*::)?(?!(if|while|for))[\w_]+[\s]*\([^\)\(]*\)([\s]*const[\s]*)?[\n\s]*\{"
@ -106,6 +149,54 @@
</function>
</parser>
<parser id="nsis_syntax" displayName="NSIS Syntax" commentExpr="((/\*.*?\*)/|(#.*?$)|(;.*?$))">
<function
mainExpr="^[\t ]*(!macro|Function|Section|SectionGroup)[\t ]+[^\r\n]*$"
displayMode="$functionName">
<functionName>
<nameExpr expr="(?(?=[\t ]*!macro)[\t ]*!macro[\t ]+[^\s]+|[^\r\n]*)"/>
</functionName>
</function>
</parser>
<parser id="perl_function" displayName="Perl">
<function mainExpr="sub[\s]+[\w]+[\s]*\([^\)\(]*\)[\n\s]*\{" displayMode="$className->$functionName">
<functionName>
<nameExpr expr="(sub[\s]+)?\K[\w]+"/>
</functionName>
<className>
<nameExpr expr="[\w]+(?=[\s]*::)"/>
</className>
</function>
</parser>
<parser id="php_function" displayName="PHP source" commentExpr="((/\*.*?\*)/|(//.*?$))">
<classRange mainExpr="^[\t ]*(((class|interface)[\t ]+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*[\t ]+((extends|implements)[\t ]+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)?)|(trait[\t ]+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))\s*\{"
openSymbole="\{"
closeSymbole="\}"
displayMode="node">
<className>
<nameExpr expr="(class[\t ]+|interface[\t ]+|trait[\t ]+)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
<nameExpr expr="[\t ]+[\w]+"/>
<nameExpr expr="[\w]+"/>
</className>
<function mainExpr="^[\t ]*(public[\t ]+|protected[\t ]+|private[\t ]+)?(static[\t ]+)?function[\s]+&?[\t ]*([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{">
<functionName>
<funcNameExpr expr="function[\s]+&?[\t ]*[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
<funcNameExpr expr="[\s]+&?[\w]+"/>
<funcNameExpr expr="[^&\s]+"/>
</functionName>
</function>
</classRange>
<function mainExpr="^[\t ]*function[\s]+&?[\t ]*([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{"
displayMode="$className->$functionName">
<functionName>
<nameExpr expr="(?!(if|while|for))[\w_]+[\s]*\("/>
<nameExpr expr="(?!(if|while|for))[\w_]+"/>
</functionName>
</function>
</parser>
</parsers>
</functionList>
</NotepadPlus>

@ -158,7 +158,7 @@
<Keywords name="type1">cliprestore clipsave composefont currentsmoothness findcolorrendering setsmoothness shfill</Keywords>
<Keywords name="type2">.begintransparencygroup .begintransparencymask .bytestring .charboxpath .currentaccuratecurves .currentblendmode .currentcurvejoin .currentdashadapt .currentdotlength .currentfilladjust2 .currentlimitclamp .currentopacityalpha .currentoverprintmode .currentrasterop .currentshapealpha .currentsourcetransparent .currenttextknockout .currenttexturetransparent .dashpath .dicttomark .discardtransparencygroup .discardtransparencymask .endtransparencygroup .endtransparencymask .execn .filename .filename .fileposition .forceput .forceundef .forgetsave .getbitsrect .getdevice .inittransparencymask .knownget .locksafe .makeoperator .namestring .oserrno .oserrorstring .peekstring .rectappend .runandhide .setaccuratecurves .setblendmode .setcurvejoin .setdashadapt .setdebug .setdefaultmatrix .setdotlength .setfilladjust2 .setlimitclamp .setmaxlength .setopacityalpha .setoverprintmode .setrasterop .setsafe .setshapealpha .setsourcetransparent .settextknockout .settexturetransparent .stringbreak .stringmatch .tempfile .type1decrypt .type1encrypt .type1execchar .unread arccos arcsin copydevice copyscanlines currentdevice finddevice findlibfile findprotodevice flushpage getdeviceprops getenv makeimagedevice makewordimagedevice max min putdeviceprops setdevice</Keywords>
</Language>
<Language name="powershell" ext="ps1" commentLine="#">
<Language name="powershell" ext="ps1 psm1" commentLine="#" commentStart="&lt;#" commentEnd="#&gt;">
<Keywords name="instre1">break continue do else elseif filter for foreach function if in return switch until where while</Keywords>
<Keywords name="instre2">add-content add-history add-member add-pssnapin clear-content clear-item clear-itemproperty clear-variable compare-object convertfrom-securestring convert-path convertto-html convertto-securestring copy-item copy-itemproperty export-alias export-clixml export-console export-csv foreach-object format-custom format-list format-table format-wide get-acl get-alias get-authenticodesignature get-childitem get-command get-content get-credential get-culture get-date get-eventlog get-executionpolicy get-help get-history get-host get-item get-itemproperty get-location get-member get-pfxcertificate get-process get-psdrive get-psprovider get-pssnapin get-service get-tracesource get-uiculture get-unique get-variable get-wmiobject group-object import-alias import-clixml import-csv invoke-expression invoke-history invoke-item join-path measure-command measure-object move-item move-itemproperty new-alias new-item new-itemproperty new-object new-psdrive new-service new-timespan new-variable out-default out-file out-host out-null out-printer out-string pop-location push-location read-host remove-item remove-itemproperty remove-psdrive remove-pssnapin remove-variable rename-item rename-itemproperty resolve-path restart-service resume-service select-object select-string set-acl set-alias set-authenticodesignature set-content set-date set-executionpolicy set-item set-itemproperty set-location set-psdebug set-service set-tracesource set-variable sort-object split-path start-service start-sleep start-transcript stop-process stop-service stop-transcript suspend-service tee-object test-path trace-command update-formatdata update-typedata where-object write-debug write-error write-host write-output write-progress write-verbose write-warning</Keywords>
<Keywords name="type1">ac asnp clc cli clp clv cpi cpp cvpa diff epal epcsv fc fl foreach ft fw gal gc gci gcm gdr ghy gi gl gm gp gps group gsv gsnp gu gv gwmi iex ihy ii ipal ipcsv mi mp nal ndr ni nv oh rdr ri rni rnp rp rsnp rv rvpa sal sasv sc select si sl sleep sort sp spps spsv sv tee where write cat cd clear cp h history kill lp ls mount mv popd ps pushd pwd r rm rmdir echo cls chdir copy del dir erase move rd ren set type</Keywords>

Loading…
Cancel
Save