Community
    • Login

    Enhance UDL lexer

    Scheduled Pinned Locked Moved General Discussion
    udl
    41 Posts 9 Posters 11.5k 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.
    • Alan KilbornA
      Alan Kilborn @Ekopalypse
      last edited by

      @Ekopalypse said:

      I’ve opened two issues one here and one there to address this.

      I don’t mean to be a debbie downer but good luck with the “there” one. The “here” one is much more likely to happen, although it seems that even PS development has slowed way down after being encouragingly active for a while.

      1 Reply Last reply Reply Quote 2
      • Meta ChuhM
        Meta Chuh moderator @Ekopalypse
        last edited by

        @Ekopalypse

        Hopefully this will be implemented soon.

        my experience says this is rather “en attendant godot” or “warten auf godot” ;-)

        1 Reply Last reply Reply Quote 1
        • HasenederH
          Haseneder
          last edited by Haseneder

          @Ekopalypse
          What is this script for, please ?
          I have come here, because I was looking up existing Notepad++ issues, have found this https://github.com/notepad-plus-plus/notepad-plus-plus/issues/7622 and followed a link in a comment pointing to here.

          My problem is that I am trying to configure a UDL in Notebook++ for Jenkins Pipeline syntax,
          but the UDL lexer in Notepad++ does not find and colour string “stage” if there is “stage(”.

          Can I use your script to replace the Notepad++’ lexer ?

          BR
          Rainer
          NotepadPP_keyword_stage_NotFound.JPG

          EkopalypseE 1 Reply Last reply Reply Quote 0
          • EkopalypseE
            Ekopalypse @Haseneder
            last edited by Ekopalypse

            @Haseneder

            If this is still an issue for you, let me know.

            The idea of the script is to enhance the existing UDL
            with coloring which otherwise isn’t possible to do
            with the builtin lexer, means, script, normally,
            runs together with the UDL lexer.

            1 Reply Last reply Reply Quote 0
            • c siebesterC
              c siebester
              last edited by

              I found this and am quite interested in it but am not sure how to implement this. I’m an engineer not a CS so my programing is only fair. Can someone tell me how to actually use this in notepad++ or where to go to read what I will need to get it going? Thanks

              EkopalypseE 1 Reply Last reply Reply Quote 1
              • EkopalypseE
                Ekopalypse @c siebester
                last edited by Ekopalypse

                @c-siebester

                You must have installed the PythonScript plugin, which you can do via PluginAdmin in the plugin menu.

                Use plugins->pythonscript->new script and save it under a meaningful name. Copy the content from here into the script.

                Save it. Now you need to define the regexes to add additional colours to the lexer. The script is commented, let me know if anything is unclear.

                c siebesterC 1 Reply Last reply Reply Quote 3
                • c siebesterC
                  c siebester @Ekopalypse
                  last edited by

                  @ekopalypse
                  I have now had a chance to give this a solid go and have not been able to get it working. To start with I installed the PythonScript plugin.

                  In your comments I do not understand what is meant by “d = integer, denotes which match group should be considered” because I’m not clear on what a match group does.

                  I defined my own user defined language ml and then just tried to highlight letters in one color and digits in another. I followed your examples and now have the following in the file:

                  ml_regexes = _dict()
                  ml_regexes = [(0, (0, 0, 224))] = (r’\d’, 0)
                  ml_regexes = [(1, (224, 0, 0))] = (r’\w’, 0)
                  ml_excluded_styles = []
                  _enhance_lexer = EnhanceLexer()
                  _enhance_lecer.register_lexer(‘ml’, ml_regexes, ml_excluded_styles)

                  I saved the modified code as ml.py in the folder C:\Users\CS_laptop\AppData\Roaming\Notepad++\plugins\config\PythonScript\scripts

                  Then I made a new file to test with containing the following:
                  hello
                  12345

                  I set language to the empty user defined language ml.
                  Then I went to Plugins>Python Scripts>scripts> and selected ml.
                  This produced no result.

                  Please let me know where I have gone wrong. Thanks for your help.

                  EkopalypseE 1 Reply Last reply Reply Quote 0
                  • EkopalypseE
                    Ekopalypse @c siebester
                    last edited by

                    @c-siebester said in Enhance UDL lexer:

                    An error has crept in here that

                    ml_regexes = [(0, (0, 0, 224))] = (r’\d’, 0)
                    ml_regexes = [(1, (224, 0, 0))] = (r’\w’, 0)
                    

                    is not valid Python code, it must be like this

                    ml_regexes[(0, (0, 0, 224))] = (r’\d’, 0)
                    ml_regexes[(1, (224, 0, 0))] = (r’\w’, 0)
                    

                    If you open the PythonScript Console, this should also appear as an error when you run the script.

                    Regarding match groups, we assume the following regular expression \d\d\d.
                    This expression returns at most one match if it can find 3 consecutive digits. If the expression were \d(\d)\d, the regex engine would produce two matches, the standard match of the 3 digits and a second match of the middle digit. This is reflected by the number in the regular expression. If there is a 0, the standard match, which is always present if something is found, is determined and coloured. If there were a 1, only the 2nd match would be taken into account. Of course, only if there is a corresponding regular expression, as in my second example.

                    Does that make sense?

                    c siebesterC 1 Reply Last reply Reply Quote 2
                    • c siebesterC
                      c siebester @Ekopalypse
                      last edited by

                      @ekopalypse
                      You’re right. I changed it to the following.
                      ml_regexes [(0, (0, 0, 224))] = (r’\d*‘, 0)
                      ml_regexes [(1, (224, 0, 0))] = (r’\w*', 0)

                      Obviously I have more interesting things I will want to match, I’m just trying to get it working. I’m still not getting any highlighting in my test document with the hello and 12345. Maybe I don’t have the setup right?

                      EkopalypseE 1 Reply Last reply Reply Quote 0
                      • EkopalypseE
                        Ekopalypse @c siebester
                        last edited by

                        @c-siebester

                        The only pitfall I see at the moment might be that your UDL name is not ml but something else.
                        When you run the script, do you see any errors in the console?
                        I assume you copied the whole script and not just the part you mentioned here, right?
                        If you click on the script from the Python script menu while holding down the CTRL key, will the expected script open in Npp?

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