tmbb

tmbb

Elixir alternative to pygments

Is there any elixir alternative to pygments? I can’t find anything on hex. The core is obviously very easy to port, but the real work is in porting all the lexers. It’s probably very easy too, but tedious and repetitive, and to be properly done it probably requires at least a cursory knowledge of the programming language the lexer is highlighting.

Marked As Solved

tmbb

tmbb

Thanks, but I’ve already written my pure elixir version of pygments:

It only has two lexers right now (elixir and HTML), but I’ll keep adding the in the future and write some docs so that you can contribute your own.

My approach is technically superior to Pygments, and can do more interesting things (like highlighting matching delimiters or do ... end blocks). This is becaus I use a real PEG parser instead of the Regex approach taken by Pygments.

Also Liked

tmbb

tmbb

An alternative is to copy what haskell has done. They’ve got a library that parses kate syntax XML highlighting files and generates lexers from them at compile time. The format of the XML files is quite simple, but most of the XML files are LGPL, which is probably too restrictive for most people.

Another alternative is to parse textmate’s syntax highlighting files, but their grammar is more confusing because they do funny things with regexs…

tmbb

tmbb

The obvious answer is that yes, you can port the lexers as long as you port the Python code to Elixir.

The practical answer is: Yes, but you have to rewrite the weird Pygments’ state-machines into a grammar for a PEG parser (which is way simpler than the original state-machines.

The crazy answer is that tah Pygments lexers are somewhat data-driven, if you squint a little (a lot), so it’s probably possible to write a Python program that compiles most of the Lexers into Elixir. Writing such program would be highly non-trivial, and my library is technically superior (and more powerful) than Pygments in a fundamental way, so I think that it’s better to just port the lexers.

I’d like to write a guide on how to write the lexers and crowdsource it to the polyglot members of the Elixir community, but I have no time for that now…

tmbb

tmbb

The elixir lexer had some problems too. I’ve corrected them in my implementation. Pygments in general is not a very good piece of software. The real killer feature of pygments is the enormous number of man-hours put into writing lexers for all those languages. The lexers themselves are not necessarily very good.

Last Post!

ShalokShalom

ShalokShalom

I guess this fundamentally supported by the huge Python community itself.

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement