Community
    • Login

    How do I create a new User Defined Language "based on" an existing one ?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    13 Posts 3 Posters 5.2k 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.
    • PeterJonesP
      PeterJones @Chal Chinehsoyo
      last edited by

      @Chal-Chinehsoyo

      Existing lexer languages are a completely different creature than UDL, so you cannot start a UDL from an existing language (like C++).

      If you are just wanting to add extra keywords to the C++, use the types that have user-defined boxes in some of their keyword definitions in the Style Configurator.

      Chal ChinehsoyoC 1 Reply Last reply Reply Quote 2
      • Chal ChinehsoyoC
        Chal Chinehsoyo @PeterJones
        last edited by Chal Chinehsoyo

        @PeterJones thanks… really I’d just like to change certain colours in the C++ one.
        But there seems to be no way of doing that, like you can in the User Defined Language section. Is there?

        PeterJonesP 1 Reply Last reply Reply Quote 0
        • PeterJonesP
          PeterJones @Chal Chinehsoyo
          last edited by PeterJones

          @Chal-Chinehsoyo ,

          The Settings > Style Configurator is where you set the per-language colors for any of the builtin lexer languages.

          Chal ChinehsoyoC 2 Replies Last reply Reply Quote 3
          • Chal ChinehsoyoC
            Chal Chinehsoyo @PeterJones
            last edited by

            @PeterJones ah ok, that makes sense thanks

            1 Reply Last reply Reply Quote 0
            • Chal ChinehsoyoC
              Chal Chinehsoyo @PeterJones
              last edited by Chal Chinehsoyo

              @PeterJones said in How do I create a new User Defined Language "based on" an existing one ?:

              @Chal-Chinehsoyo ,

              The Settings > Style Configurator is where you set the per-language colors for any of the builtin lexer languages.

              I’ve settled with using C++ language.
              But, is there anyway to change this Style’s colours? Is there a file in the resources directories I can edit somehow?
              Is it C:\Program Files\Notepad++\stylers.model.xml ?

              Also, is it possible in Notepad++ to tell it to change the colour of any word beginning with “M_” for example.

              Or the colour of the word following, for example, "void " ?

              PeterJonesP 1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @Chal Chinehsoyo
                last edited by PeterJones

                @Chal-Chinehsoyo

                But, is there anyway to change this Style’s colours?

                Yes, using the Style Configurator, as I said. Use this dialog, with C++ selected on the left, and cycle through all the entries in the Style column and edit the Colour Style for any that you want to change.
                0d990290-1eb1-4992-b971-718b160b0017-image.png

                Or if you really want to punish yourself by editing the raw XML, you can edit %AppData%\Notepad++\stylers.xml if you have the default style selected – though you will need to follow the Editing Configuration File advice in the Online User Manual if you want to do that. (Your location for that file may be different, depending on your configuration)

                Is it C:\Program Files\Notepad++\stylers.model.xml ?

                That is the default version of stylers.xml that Notepad++ will copy into %AppData%\Notepad++\stylers.xml(or equivalent) if it doesn’t find stylers.xml in the right place. Changing that file will not help if you already have a copy of stylers.xml in the right place, because changes to stylers.model.xml do not automatically propagate to stylers.xml.

                Also, is it possible in Notepad++ to tell it to change the colour of any word beginning with “M_” for example.
                Or the colour of the word following, for example, "void " ?

                Not without a plugin. The Enhance Any Lexer would allow you to specify colors in GBR format (0xGGBBRR) on the left of the equals and a regex for what. The following configuration for EnhanceAnyLexer will make M_... be red and the word after void be blue, in addition to the styles that the C++ lexer already applies.

                [c++]
                0x0000FF = M_\w+
                0x00FF00 = (?<=void\h+)\w+
                
                Chal ChinehsoyoC 1 Reply Last reply Reply Quote 2
                • Chal ChinehsoyoC
                  Chal Chinehsoyo @PeterJones
                  last edited by

                  @PeterJones said in How do I create a new User Defined Language "based on" an existing one ?:

                  [c++]
                  0x0000FF = M_\w+
                  0x00FF00 = (?<=void\h+)\w+

                  Great, thats working for me : )
                  I changed the colour of the word as you described above.
                  Is there anyway of making it bold ?

                  PeterJonesP 1 Reply Last reply Reply Quote 0
                  • PeterJonesP
                    PeterJones @Chal Chinehsoyo
                    last edited by

                    @Chal-Chinehsoyo ,

                    The EnhanceAnyLexer will only affect foreground colour. It cannot change background colour; it cannot make matched text bold, italic, or underlined; it cannot change the font size or font name.

                    Chal ChinehsoyoC 1 Reply Last reply Reply Quote 1
                    • Chal ChinehsoyoC
                      Chal Chinehsoyo @PeterJones
                      last edited by

                      @PeterJones Thanks…
                      This line for void is not working.
                      ;0x00FF00 = (?<=void\h+)\w+

                      Is there a reference guide to the regular expressions and what they mean ? I didn’t see one on his github.

                      PeterJonesP EkopalypseE 2 Replies Last reply Reply Quote 0
                      • PeterJonesP
                        PeterJones @Chal Chinehsoyo
                        last edited by PeterJones

                        @Chal-Chinehsoyo said in How do I create a new User Defined Language "based on" an existing one ?:

                        @PeterJones Thanks…
                        This line for void is not working.
                        ;0x00FF00 = (?<=void\h+)\w+

                        With a semicolon, it won’t , because that comments out that line of the config file. I am assuming you don’t actually have that semicolon there.

                        That said, the reason it didn’t work, even without the semicolon, is because I didn’t try it myself, and I forgot that lookbehinds have to be fixed-length, but \h+ is not fixed-length. If you know it will always be exactly one space, then change the regex to (?<=void\h)\w+ … but if you need to allow any number of spaces or tabs between void and the word, then use void\h+\K\w+ instead; if you want void and the word to also allow linebreaks between (which are valid in c/c++, and even meet some of the style guides out there, though I dislike that style, personally), then void\s+\K\w+ will work. (I tested all three of these before posting, this time).

                        Is there a reference guide to the regular expressions and what they mean ? I didn’t see one on his github.

                        I think that it’s using boost regular expressions, which match what is available to Notepad++, so you can look at the Notepad++ regex docs. But @Ekopalypse can chime in if a different regex library is being used.

                        1 Reply Last reply Reply Quote 2
                        • EkopalypseE
                          Ekopalypse
                          last edited by

                          @Chal-Chinehsoyo said in How do I create a new User Defined Language "based on" an existing one ?:

                          ;0x00FF00 = (?<=void\h+)\w+

                          EnhanceAnyLexer uses what Npp uses, there is no own regex implementation.
                          I have been thinking about this problem and will implement a function to notify about invalid regex.
                          I am thinking of something like this

                          94072f3c-bd74-49c7-8397-e4ff2a22abc3-image.png

                          1 Reply Last reply Reply Quote 2
                          • EkopalypseE
                            Ekopalypse @Chal Chinehsoyo
                            last edited by

                            @Chal-Chinehsoyo

                            see here for the news :-)

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