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

hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement