gCode Highlighting with pygments
03 Nov 2019 16:06 - 03 Nov 2019 16:07 #149497
by bluebase
gCode Highlighting with pygments was created 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
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
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.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19304
- Thank you received: 6463
03 Nov 2019 18:49 #149502
by tommylight
Replied by tommylight on topic gCode Highlighting with pygments
Welcome and thank you, seems very useful.
Please Log in or Create an account to join the conversation.
04 Nov 2019 01:07 #149514
by cmorley
Replied by cmorley on topic gCode Highlighting with pygments
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
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.
04 Nov 2019 21:35 #149555
by bluebase
Replied by bluebase on topic gCode Highlighting with pygments
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
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.
05 Nov 2019 00:53 #149563
by cmorley
Replied by cmorley on topic gCode Highlighting with pygments
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
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.
02 Dec 2019 16:33 #151761
by colincci
Replied by colincci on topic gCode Highlighting with pygments
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 or Create an account to join the conversation.
23 May 2022 09:37 - 23 May 2022 09:44 #243603
by silopolis
Replied by silopolis on topic gCode Highlighting with pygments
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
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
Last edit: 23 May 2022 09:44 by silopolis.
Please Log in or Create an account to join the conversation.
Time to create page: 0.116 seconds