Community
    • Login

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

    Scheduled Pinned Locked Moved General Discussion
    9 Posts 3 Posters 597 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.
    • ZsoltKántorZ
      ZsoltKántor
      last edited by

      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!

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @ZsoltKántor
        last edited by

        @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
        • ZsoltKántorZ
          ZsoltKántor
          last edited by ZsoltKántor

          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.

          PeterJonesP 2 Replies Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @ZsoltKántor
            last edited by

            @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
            • PeterJonesP
              PeterJones @ZsoltKántor
              last edited by

              @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
              • ZsoltKántorZ
                ZsoltKántor
                last edited by ZsoltKántor

                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
                • MAPJe71M
                  MAPJe71
                  last edited by

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

                  1 Reply Last reply Reply Quote 1
                  • ZsoltKántorZ
                    ZsoltKántor
                    last edited by

                    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
                    • ZsoltKántorZ
                      ZsoltKántor
                      last edited by ZsoltKántor

                      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
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors