Comment folding for languages that only support line commenting

ALC
2014-04-03
2014-04-06
  • ALC
    ALC
    2014-04-03

    Greetings!

    I was attempting to see if I could configure NPP to fold comments in VBScript. I tried tinkering with a UDL, and and used the comment line symbol (apostrophe) as the open/continue char/close and it almost worked...

    The problem was that if an additional apostrophe found within the same line, the lexer seems to define it as the end of the comment block for example, the comment block below:

    ' Comment 1
    ' Comment 2
    ' Comment 3, but I don't want to stop commenting here
    ' Comment 4
    ' Comment 5

    Would fold into:

    +' Comment 1
    ' Comment 3, but I don't want to stop commenting here
    +' Comment 4

    But what I really wanted was:

    +'Comment 1

    Since comment blocks aren't really defined for VBScript, I'd like to be able to configure NPP to be able to comment fold appropriately, but I'm not sure where to start. So the questions I have are:

    1.Is it possible to take the existing definition of the VB language settings and add ones own modification? And is it possible to configure it to behave the way I indicate above?

    2.Is creating a custom lexer the only way to deal with this? And if so, is it possible to use the current one that is processing VBScript and add modifications to it?

     
  • Loreia2
    Loreia2
    2014-04-03

    Hi ALC,

    1. built in syntax highlighters are not compatible with UDL. So, you can't use VB language as basis and just add your own modifications.

    2. Line comments need just the Open keyword, don't set continue or close characters

    BR,
    Loreia

     
  • ALC
    ALC
    2014-04-03

    Hi Loreia,

    Thanks for the reply!

    So when I switch over to a UDL, just using the Open keyword, the comment folding works perfectly...however I lose the built in syntax highlighting for VB.

    I'm guessing the answer to my next question is probably no...

    Does the langs.model.xml have a "Open" keyword that I could use for VBScript?

     
  • Loreia2
    Loreia2
    2014-04-03

    Hi ACL,

    Scintilla (component that does the source code highlighting within Notepad++) uses separate lexer for each built in language. Each lexer is a custom highlighter written in C++ just for given language. Lexers know nothing about other lexers, and there is nothing one lexer could do with keywords and styles from another lexer.

    UDL is another Scintilla highlighter, but specific because it tries to implement highlighting in a generic way (i.e. it is not tied to any specific language). So, mixing UDL with say VB lexer makes as much sense as mixing VB lexer with C++ lexer :-)

    If you wish to extend VB lexer, you need to patch LexVB.cxx file (C++ source code for VB lexer), or define VB-like UDL language. In UDL you start from scratch, you need to define every keyword, and every style manually. There are no shortcuts, no copying of anything.

    If you wish to use UDL, I would recommend to first obtain a list of all VB keywords, and a list all VB styles as defined in Scintilla's built-in VB lexer (you can use langs.model.xml file). Then you can try to define UDL as close as possible to built in lexer. If you succeed, share your definition here:
    http://sourceforge.net/apps/mediawiki/notepad-plus/?title=User_Defined_Language_Files

    I hope that answers your question.

    BR,
    Loreia

     
  • THEVENOT Guy
    THEVENOT Guy
    2014-04-06

    Hello Loreia2,

    What a interesting and clear information about lexers, languages and, especially, about the UDL feature !! You just show the right structure of your excellent UDL 2.0 :-)

    I'll try, in 2/3 months by now, to adapt my two define languages, that I built with the last ANSI 5.9.8 version of N+. Hope, I could benefit of your promising UDL 3.0 version !

    Cheers,

    guy038