gCode Highlighting with pygments

More
03 Nov 2019 16:06 - 03 Nov 2019 16:07 #149497 by bluebase
Hi, a long-time lurker here.

I have written a small extension to the python library pygments which is used to highlight code.
The docs/src/source-highlighter for the asciidocs is known to me. And i know gedit is probably used by many users on their controllers. However, most UI for linuxcnc are written in python now. Tinkering with some UI features, I was looking for a way to highlight code with python tools.

Currently, pygments it is missing a lexer for gcode files, though. There is one repository which was addressing this task ( lexers_pygments ) which is likely related to a stackoverflow post .
However, these were quite rudimentary. They only recognized very basic syntax.
Dissatisfied with this condition, I started over to write my own lexer for gcode. You can find it on github .

I would like to discuss the current result with interested parties. Possibly, it could be an alternative to the currently used lexers in other guis.

In the attachments are a few examples with different pygments' styles.

As you see, I choose not to recognize full G-commands, but only the "G", and a likes.

I you have some thoughts about the lexer, I'd be happy to read about them.

Best,
Sebastian





Attachments:
Last edit: 03 Nov 2019 16:07 by bluebase.
The following user(s) said Thank You: andypugh, tommylight

Please Log in or Create an account to join the conversation.

More
03 Nov 2019 18:49 #149502 by tommylight
Welcome and thank you, seems very useful.

Please Log in or Create an account to join the conversation.

More
04 Nov 2019 01:07 #149514 by cmorley
I'm not familiar with pygments - is that a text stand alone editor?

I put together a basic lexer for qtvcp's gcode editor - I'd be happy for someone to work on a better won.

Chris

Please Log in or Create an account to join the conversation.

More
04 Nov 2019 21:35 #149555 by bluebase
No, pygments is not an editor, but a library designed to do syntax highlighting, as far as i understand.

I don't have an overview over qtvcp yet. Though, I did find the current lexer in the gcode_editor widget and did some research. This did yield some interesting contribution: stackoverflow.com/questions/55775837/pyg...-qscintilla/55873245

Maybe, we can derive a drop-in class for testing from the SO post. Do you think it would be worth a try, Chris?

Best,
Sebastian

Please Log in or Create an account to join the conversation.

More
05 Nov 2019 00:53 #149563 by cmorley
I am open to any ideas. I cobbled together the lexer out of necessity.
I have not tested it on huge files.

It sounds to me you are the resident expert now :)

Chris

Please Log in or Create an account to join the conversation.

Time to create page: 0.134 seconds
Powered by Kunena Forum