Function List displays switch(WaitForSingleObject()) as a function definition
-
-
@ZsoltKántor said in Function List displays switch(WaitForSingleObject()) as a function definition:
Is this behavior normal
Normal, but not ideal.
Unfortunately, the regex for function-name parsing is never perfect, and there are edge cases it doesn’t catch. If you can come up with a better expression, good for you (and please share).
In this case, because
void
is optional on void function prototypes, the regex is probably matching theSomeFunctionName
followed by empty or non-empty parentheses, followed by{
… I would have thought that the dual parentheses would have stopped it from matching, but it apparently doesn’t. (I tried looking at the currentfunctionList/c.xml
, but it’s so complicated, I couldn’t understand it well enough to know where to begin exploring an alternative. Maybe one of the other regex or functionList gurus will take it on as a weekend project. ;-) )If it really annoys you,
switch(WaitForSingleObject()) /**/ {
would hide the{
from the regex, so it doesn’t treat it as a function definition, but should still compile. (Yes, I understand, changing source code to get around an oddity in the editor is a bad idea. I was just saying that the alternative exists, if it really annoys you. I didn’t say it was a good alternative.) -
Probably I can not fix this by myself (I should know how np++ uses those xml files, how parsing works, etc.), but a simple solution is to not include in the Functions List words which are statements, because you can’t have a function name that is a C/C++ statement. I’m wrong?
P.S.
Statements are a programming language reserved words. So if the regex parser sees a reserved word it will skip automatically. -
@ZsoltKántor said in Function List displays switch(WaitForSingleObject()) as a function definition:
but a simple solution is to not include in the Functions List words which are statements
That’s only “simple” if you bake it into the regex. All that the FunctionList parser knows is what you tell it with the regexes from the XML file. Notepad++ itself doesn’t know anything about C or what a “function” is, or how to tell which text is a C statement; Notepad++'s FunctionList feature just parses the active file, based on the selected file type to pick the correct
functionList\blah.xml
file, and applies those regular expressions from the XML to the text that it finds in the active file; anything that matches the regex rules for class or function are then listed in the FunctionList panel as a class or function, everything else is not listed.In other words, your “simple” solution is to do exactly what I said was too complicated for me to do in the amount of time that I devote to tasks for people asking questions in the forum: edit the regex to exclude more situations from the match, so that it wouldn’t be confused by that outlier situation.
-
@ZsoltKántor said in Function List displays switch(WaitForSingleObject()) as a function definition:
Statements are a programming language reserved words.
And the default
functionList\c.xml
already excludes theswitch
keyword as not being a function name, so it doesn’t think thatswitch
is part of the function name. It thinks that WaitForSingleObject() is the function, as is shown in your screenshot where it calls the functionWaitForSingleObject()
. -
What is strange is that a function define can not be wrapped in a statement, that’s invalid code. So to fix this the parser should look and check if function call is wrap in a statement or not. If it is - that can’t be a function define.
Just for your information, with conditional statements the problem is the same … -
-
I spent a lot of time yesterday editing
functionList\c.xml
, but nothing worked. Consider that I newer created an xml file from scratch.
@PeterJones if you renamecpp.xml
toc.xml
Function List output is correct. Looking atcpp.xml
to editc.xml
did not work either. -
P.S. but with the
cpp.xml
using in C source, function defines likeBOOL WINAPI CtrlHandler(DWORD CtrlType)
are not show :(