• Login
Community
  • Login

Function List displays switch(WaitForSingleObject()) as a function definition

Scheduled Pinned Locked Moved General Discussion
9 Posts 3 Posters 605 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z
    ZsoltKántor
    last edited by Jul 16, 2021, 9:09 AM

    When you write a call to WinAPI function WaitForSingleObject() in a switch statement, the Function List recognises it as a function definition.

    aaeadcad.png

    Is this behavior normal??
    Thank you!

    P 1 Reply Last reply Jul 16, 2021, 2:45 PM Reply Quote 0
    • P
      PeterJones @ZsoltKántor
      last edited by Jul 16, 2021, 2:45 PM

      @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 the SomeFunctionName 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 current functionList/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.)

      1 Reply Last reply Reply Quote 1
      • Z
        ZsoltKántor
        last edited by ZsoltKántor Jul 16, 2021, 7:41 PM Jul 16, 2021, 7:38 PM

        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.

        P 2 Replies Last reply Jul 16, 2021, 7:46 PM Reply Quote 0
        • P
          PeterJones @ZsoltKántor
          last edited by Jul 16, 2021, 7:46 PM

          @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.

          1 Reply Last reply Reply Quote 0
          • P
            PeterJones @ZsoltKántor
            last edited by Jul 16, 2021, 7:48 PM

            @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 the switch keyword as not being a function name, so it doesn’t think that switch is part of the function name. It thinks that WaitForSingleObject() is the function, as is shown in your screenshot where it calls the function WaitForSingleObject().

            1 Reply Last reply Reply Quote 1
            • Z
              ZsoltKántor
              last edited by ZsoltKántor Jul 16, 2021, 11:01 PM Jul 16, 2021, 11:00 PM

              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 …

              e.g.:
              Clipboard01.png

              1 Reply Last reply Reply Quote 0
              • M
                MAPJe71
                last edited by Jul 17, 2021, 1:24 AM

                see https://notepad-plus-plus.org/community/topic/18087/wrong-parsing-for-c-function

                1 Reply Last reply Reply Quote 1
                • Z
                  ZsoltKántor
                  last edited by Jul 18, 2021, 8:18 AM

                  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 rename cpp.xml to c.xml Function List output is correct. Looking at cpp.xml to edit c.xml did not work either.

                  1 Reply Last reply Reply Quote 0
                  • Z
                    ZsoltKántor
                    last edited by ZsoltKántor Jul 18, 2021, 9:51 AM Jul 18, 2021, 9:50 AM

                    P.S. but with the cpp.xml using in C source, function defines like BOOL WINAPI CtrlHandler(DWORD CtrlType) are not show :(

                    1 Reply Last reply Reply Quote 0
                    5 out of 9
                    • First post
                      5/9
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors