Remarks Bug?



  • Using Notepad++ for batch programming and when a remark is the second command on a line it is not highlighted as a remark.

    Example:
    (some valid batch command) & :: a remark
    then :: a remark is NOT highlighted



  • @Zaidy036,

    The batch-file lexer is part of the scintilla-component library, which is a separate project whose source code gets embedded
    in the projects that include that library. Per the Sctintilla source code included in Notepad++, LexBatch.cxx line 92,
    “// Colorize Fake Label (Comment) - :: is similar to REM, see http://content.techweb.com/winmag/columns/explorer/2000/21.htm
    According to the wayback
    for that linked article,

    What’s a “fake label?” Commonly, it’s two (or more) colons at the start of a line. The first colon makes it a label, but DOS doesn’t know what to do with the second colon, so it simply abandons the line and moves on, at high speed.

    ? So, you can, if you wish, substitute “::” for REM in your batch files

    Thus, using :: as a pseudo-REM comment is making use of the fact that any invalid label-line is ignored and processed quickly

    The official GOTO docs are very specific:

    The label within the batch program must begin with a colon (:). If a line begins with a colon, it is treated as a label and any commands on that line are ignored.

    Note, both those docs specific “start of a line” or “line begins”. After some other command and the & command separator is not the beginning of a line.

    It’s not a comment (or event a “fake label”) after another command. Technically, it’s not even a comment at the beginning of a line. The fact that the lexer treats :: as a comment-start in any situation is just a concession to how abuses of a language can become considered “features” with enough people abusing it.

    Whether you think that it’s a bug, or whether you think the compromise that the Scintilla authors used is reasonable (my camp), or whether you think that the Scintilla authors should have never allowed for the abuse of the technical batch-file definition is, however, irrelevant. The Notepad++ project takes the source code for the Scintilla component wholesale from Scintilla. If you want a change in the built-in batch-file parser, you will have to check the Scintilla bug list and feature tracker; then, if you can convince the Scintilla team to incorporate your bug-fix or improvement, and an updated Scintilla version is released, you can then create a Notepad++ issue to request that Notepad++ update its Scintilla version. That process may take a while, especially if you have to try to convince the Scintilla side that your use of “fake label after ampersand is still a comment” should be implemented.

    In the mean time, since your batch files are obviously using that syntax successfully, regardless of the Sctinilla-team’s opinion, you can add extra highlighting to a builtin lexer (like the batch-file lexer) using regexes, via the script EnhanceAnyBuiltinLexer.py that @Ekopalypse shares in this linked post. That would allow you to define a regex like (?-s)\&\h*\K::.*$ that could be used to add highlighting for that circumstance (the regex might need to be tweaked to handle all your variations for ampersands and spacing; I haven’t tested it in the script; might need to check if the match-reset \K works in the python regex (I forget), or whether you’ll have to use some other lookbehind mechanism for that).