frescobaldi / python-ly

A Python package and commandline tool to manipulate LilyPond files
https://pypi.org/project/python-ly
137 stars 33 forks source link

Pygments Lexer? #116

Closed rpspringuel closed 1 year ago

rpspringuel commented 6 years ago

Can the syntax highlighting information in this package be used in a pygments lexer? If not, could a way of translating to that format be devised?

uliska commented 6 years ago

That should certainly be possible, but I don't know how much work it is and how many unexpected complexities would be faced. Actually I had even once looked at that but was scared away.

Another thing I had thought of was adding an option to export to LaTeX, with macros that match those used by Pandoc's highlighting engine. For my own purposes I have extracted Pandoc's Shaded environment and formatting macros so I can also make use of syntax highlighting with custom templates. This could of course be wrapped in a proper package.

But I agree that making Pygments use python-ly would be a more generic approach that would improve a wider variety of tools. I just don't have the time to dive into that area of the code (and I'm not familiar enough with it to do it "along the way").

wbsoft commented 4 years ago

Re the OP: the best way would be manually write a pygments lexer, mimicing the behaviour of ly.lex.

I have also considered using pygments instead of ly.slexer for lexing, but in pygments it is difficult to resuming lexing and only re-tokenize modified parts like slexer does.

jeanas commented 3 years ago

I am interested in tackling this issue, reusing code from parce. It seems to me that this package closely mimics the structure of Pygments lexers in generator methods instead of dictionaries.

The problem is, I legally cannot contribute something based on the GPL-licensed parce to the BSD-licensed Pygments.

@wbsoft, would you make an exception and release lilypond.py as well as lilypond_words.py from parce under a permissive license?

jeanas commented 2 years ago

Almost exactly one year later…

I opened https://github.com/pygments/pygments/pull/1845 against Pygments some months ago. It doesn't reuse anything from Frescobaldi due to the licensing issues (and it also doesn't really need to, given that it just attempts to highlight the file and not to recognize the structure, which is much more involved). However, it is currently stuck on review

jeanas commented 2 years ago

The PR is merged now. A maintainer can close this issue.