Community
    • Login

    Keyword prefix constraint possible ?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 3 Posters 462 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 @Klasen Eric
      last edited by

      @Klasen-Eric said in Keyword prefix constraint possible ?:

      Is there a way to constrain what can follow the keyword ?

      UDL does not inherently have that ability.

      However, if you are willing to install the PythonScript plugin, then you can add extra highlighting to a UDL language using regexes via the script EnhanceUDLLexer.py that @Ekopalypse shares in this linked post – so with multiple regexes, you could color G\d+ green, M\d+ magenta, and so on (color choices are up to you; I based them on the letter of the alphabet).

      Klasen EricK 2 Replies Last reply Reply Quote 1
      • Klasen EricK
        Klasen Eric
        last edited by

        Sounds good ! :D

        I’ll give it a try right now (well, not sure to be efficient, it’s 1:35am here ;) ).

        1 Reply Last reply Reply Quote 0
        • Klasen EricK
          Klasen Eric @PeterJones
          last edited by Klasen Eric

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • Klasen EricK
            Klasen Eric @PeterJones
            last edited by

            @PeterJones I installed pythonscript, edited the enhance UDL lexer script, but it don’t seem to work… I go to [Plugins] > [Python Script] > [Scripts] > “My Script”

            “My Script” is the modified (copy & paste + update of regex) of the one of your link.

            I tried placing it in the “user” folder (with the new script menu) and by hand in the scripts folder. Both case does not work…

            But nothing happens. I’m sure I’m missing something…

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @Klasen Eric
              last edited by PeterJones

              @Klasen-Eric ,

              Please go to Plugins > PythonScript and open the Console window after running it: there is likely an error message, which you can share with us

              Klasen EricK 1 Reply Last reply Reply Quote 0
              • Klasen EricK
                Klasen Eric @PeterJones
                last edited by Klasen Eric

                @PeterJones Nothing in the console… I tried opening it before running the script or after running it (with restart of N++ ). Nothing…
                Full content of console :

                Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (Intel)]
                Initialisation took 32ms
                Ready.
                

                I also modified my code to print something at the beginning, and it works (displays my “Hello World” ;) )

                PeterJonesP 1 Reply Last reply Reply Quote 0
                • PeterJonesP
                  PeterJones @Klasen Eric
                  last edited by

                  @Klasen-Eric ,

                  Did you put the name of your UDL in the appropriate spot? Is that UDL active on the active file?

                  Klasen EricK 2 Replies Last reply Reply Quote 0
                  • Klasen EricK
                    Klasen Eric @PeterJones
                    last edited by

                    @PeterJones I think so. My UDL is just called “gcode”. Quite simple to handle… but I’ll check again… a typo is never too far ;-)

                    And yes, this UDL is active on my file (when I change values in its configuration window, colors changes in the file.

                    1 Reply Last reply Reply Quote 0
                    • Klasen EricK
                      Klasen Eric @PeterJones
                      last edited by

                      @PeterJones

                      I’ve put some print at the beginning of each method of the code. But even the one at the beginning of the “main” method is not printed. The print at the beginning of the file (just after regex configuration) is still ok.

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

                        @Klasen-Eric

                        So my understanding is, that you run it once, right?
                        And after executing you got your main print statement in the console, correct?
                        After that, you need to activate the buffer aka clicking into it or switching
                        from another document into the one which should be handled and then
                        it should start coloring your regex matches.
                        Did you ensure that the match group is 0? Only if you used G\d+.
                        If you used something like
                        G0(\d+) and you are interested to get the digit colored which follow G0
                        you would need to use match group 1.
                        So for example this

                        regexes[(0, (79, 175, 239))] = (r'G\d+', 1)'
                        

                        would be an error as no match group 1 gets created

                        either use this

                        regexes[(0, (79, 175, 239))] = (r'G\d+', 0)'
                        

                        or that (which really doesn’t make sense in this case but …

                        regexes[(0, (79, 175, 239))] = (r'(G\d+)', 1)'
                        
                        1 Reply Last reply Reply Quote 2
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors