gCode Highlighting with pygments

More
6 years 11 months ago #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

Attachment not found



Attachment not found



Attachment not found

Please Log in to join the conversation.

More
6 years 11 months ago #149502 by tommylight
Welcome and thank you, seems very useful.

Please Log in to join the conversation.

More
6 years 11 months ago #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 to join the conversation.

More
6 years 11 months ago #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 to join the conversation.

More
6 years 11 months ago #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 to join the conversation.

More
6 years 10 months ago #151761 by colincci
This looks excellent. I have forked your code on github. Let me know if there is anything I can do to assist in getting your lexer ready for a pull request to the pygments repo.

Please Log in to join the conversation.

More
4 years 5 months ago #243603 by silopolis
Hello friends :)

Trying to polish documentation formatting of @cmorley 's QtVCP I broke PDF building because, in state of researches, the current `listings` LaTeX package doesn't supports CSS :/

A short search revealed that AsciiDoc supports Pygments natively (but we use `source-highlight` ATM) and that LaTeX can support it too by switching to the `minted` package. No wonder Pygment supports CSS !

Next search was for support of our "specific" languages support, namely `G-Code`, `HAL` and `INI`... Which led me here :)

So, this is a very good start for a proposal to switch to Pygments for all of our code highlighting needs, be it HTML docs, PDF docs or in app.

To avoid holding work on QtVCP docs, I'll temporarily switch css type to html for qss code blocks as suggested by @smoe here github.com/LinuxCNC/linuxcnc/pull/1742#issuecomment-1133903706

After docs migration work will be over, I'll dig into this deeper and most probably ask for with lexer development for INI and HAL files as this will be very new to me.

Edit: Of course INI files are already supported by pygments.lexers.configs.IniLexer :)

TY
J

Please Log in to join the conversation.

Time to create page: 0.106 seconds
Powered by Kunena Forum