Menu

#1624 Brace-matching problems with batch-files

Bug
closed-fixed
3
2020-04-27
2014-07-14
hurda77
No

In the following code-example, the second brace of ") else (" isn't being matched to any other brace when the text is being set as "Batch". This throws off the matching of all following braces.

When the text is set to "Normal Text", the brace-matching is working properly.

if "%VC12DIR%"=="" (
    rem Prepend SDK paths - Don't use the SDK SetEnv.cmd because it pulls in
    rem random VC paths which we don't want.
    rem Add the atlthunk compat library to the end of our LIB
    set "PATH=%SDKDIR%\bin;%PATH%"
    set "LIB=%SDKDIR%\lib;%LIB%;%MOZBUILDDIR%atlthunk_compat"

    if "%USEPSDKATL%"=="1" (
        if "%USEPSDKIDL%"=="1" (
            set "INCLUDE=%SDKDIR%\include;%PSDKDIR%\include\atl;%PSDKDIR%\include;%INCLUDE%"
        ) else (
            set "INCLUDE=%SDKDIR%\include;%PSDKDIR%\include\atl;%INCLUDE%"
        )
    ) else (
        if "%USEPSDKIDL%"=="1" (
            set "INCLUDE=%SDKDIR%\include;%SDKDIR%\include\atl;%PSDKDIR%\include;%INCLUDE%"
        ) else (
            set "INCLUDE=%SDKDIR%\include;%SDKDIR%\include\atl;%INCLUDE%"
        )
    )
)

Reproduced in SciTE 3.4.4, Notepad++ 6.6.7 and Notepad2-Mod r906.
Code-example taken from start-shell-msvc2013.bat of MozillaBuild 1.9 for Windows.

Related

Bugs: #1624
Bugs: #1906
Bugs: #1997

Discussion

  • Neil Hodgson

    Neil Hodgson - 2014-07-14

    The batch lexer colours most of the '(' as "External Commands" (style 5) but the '(' following "else" are default (style 0). Since they are in different styles they don't match.

    I'll leave fixing this to someone that is interested in the batch language.

     
  • Neil Hodgson

    Neil Hodgson - 2014-07-14
    • labels: --> scintilla, batch, lexer
    • status: open --> open-accepted
    • assigned_to: Neil Hodgson
    • Priority: 5 --> 3
     
  • Rob Mahn

    Rob Mahn - 2018-06-15

    I have attached a very simple test.bat and test.txt.

    I am using Notepad++ v7.5.6 (32-bit).

    In test.bat, the first and last pair of braces will not match. The center pair does match.

    In test.txt, the same lines of code will match.

    In larger batch files, I can't match most of the pairs.

     
  • Neil Hodgson

    Neil Hodgson - 2018-06-16

    If you make the styles of the braces more contrasting with different background colours then it will be more obvious that the braces are different styles and thus not candidates for matching with the common SCI_BRACEMATCH API. In SciTE settings like these will highlight the different styles:

    style.batch.0=fore:#000000,back:#FF0000
    style.batch.5=fore:#007090,back:#00FF00
    

    Notepad++ can use whatever rules it wants for matching braces so could decide to ignore styles.

     
    • Rob Mahn

      Rob Mahn - 2018-06-16

      Hi Neil,
      While the matching braces contrast is not great in Notepad++, the problem is further exposed with navigation to the matching brace. It would not recognize the first or last pair of parenthesis as having a match at all. Thus, they do not get highlighted either.

      From the search menu, Go to Matching Brace (Ctrl-B) and Select All Between Matching Braces (Ctrl-Alt+b) are not enabled when the cursor is on the first or last pair.

      The Notepad++ blames the problem on Scintilla.
      https://github.com/notepad-plus-plus/notepad-plus-plus/issues/4191
      https://github.com/notepad-plus-plus/notepad-plus-plus/issues/2865

      Once deep in a batch file, there are many braces that will not match, but I skinned it down to a simple example.

      Thank you,
      Rob Mahn

      From: Neil Hodgson [mailto:nyamatongwe@users.sourceforge.net]
      Sent: Saturday, June 16, 2018 4:30 AM
      To: [scintilla:bugs] 1624@bugs.scintilla.p.re.sourceforge.net
      Subject: [scintilla:bugs] #1624 Brace-matching problems with batch-files

      If you make the styles of the braces more contrasting with different background colours then it will be more obvious that the braces are different styles and thus not candidates for matching with the common SCI_BRACEMATCH API. In SciTE settings like these will highlight the different styles:

      style.batch.0=fore:#000000,back:#FF0000

      style.batch.5=fore:#007090,back:#00FF00

      Notepad++ can use whatever rules it wants for matching braces so could decide to ignore styles.


      [bugs:#1624]https://sourceforge.net/p/scintilla/bugs/1624/ Brace-matching problems with batch-files

      Status: open-accepted
      Group: Bug
      Labels: scintilla batch lexer
      Created: Mon Jul 14, 2014 07:04 PM UTC by hurda77
      Last Updated: Fri Jun 15, 2018 10:53 PM UTC
      Owner: Neil Hodgson

      In the following code-example, the second brace of ") else (" isn't being matched to any other brace when the text is being set as "Batch". This throws off the matching of all following braces.

      When the text is set to "Normal Text", the brace-matching is working properly.

      if "%VC12DIR%"=="" (

      rem Prepend SDK paths - Don't use the SDK SetEnv.cmd because it pulls in
      
      rem random VC paths which we don't want.
      
      rem Add the atlthunk compat library to the end of our LIB
      
      set "PATH=%SDKDIR%\bin;%PATH%"
      
      set "LIB=%SDKDIR%\lib;%LIB%;%MOZBUILDDIR%atlthunk_compat"
      
      
      
      if "%USEPSDKATL%"=="1" (
      
          if "%USEPSDKIDL%"=="1" (
      
              set "INCLUDE=%SDKDIR%\include;%PSDKDIR%\include\atl;%PSDKDIR%\include;%INCLUDE%"
      
          ) else (
      
              set "INCLUDE=%SDKDIR%\include;%PSDKDIR%\include\atl;%INCLUDE%"
      
          )
      
      ) else (
      
          if "%USEPSDKIDL%"=="1" (
      
              set "INCLUDE=%SDKDIR%\include;%SDKDIR%\include\atl;%PSDKDIR%\include;%INCLUDE%"
      
          ) else (
      
              set "INCLUDE=%SDKDIR%\include;%SDKDIR%\include\atl;%INCLUDE%"
      
          )
      
      )
      

      )

      Reproduced in SciTE 3.4.4, Notepad++ 6.6.7 and Notepad2-Mod r906.
      Code-example taken from start-shell-msvc2013.bat of MozillaBuild 1.9 for Windows.


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/scintilla/bugs/1624/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #1624

      • Neil Hodgson

        Neil Hodgson - 2018-06-16

        There are two ways of fixing this.

        1) Change the batch lexer to use the same style for the differently placed braces.

        2) Use different logic that does not check styles when matching braces.

         
  • Neil Hodgson

    Neil Hodgson - 2020-04-27
    • status: open-accepted --> closed-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2020-04-27

    Fixed with [bc6bc2].

     

    Related

    Commit: [bc6bc2]


Log in to post a comment.

MongoDB Logo MongoDB