Keyword prefix constraint possible ?
-
@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 colorG\d+
green,M\d+
magenta, and so on (color choices are up to you; I based them on the letter of the alphabet). -
Sounds good ! :D
I’ll give it a try right now (well, not sure to be efficient, it’s 1:35am here ;) ).
-
This post is deleted! -
@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…
-
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
-
@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” ;) )
-
Did you put the name of your UDL in the appropriate spot? Is that UDL active on the active file?
-
@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.
-
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.
-
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 usedG\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 thisregexes[(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)'