sheharyarn

sheharyarn

I would really like to see Syntax Highlighting support for Elixir on Stackoverflow. Someone already created a topic on Meta StackExchange but since SE relies on an external syntax highlighting tool (Google’s code-prettify), there hasn’t been any work to support Elixir (even though an issue was also opened there over a year ago).

I’m interested in making this happen (as someone who spends 5+ hours daily on SO - especially in the Elixir tag). So my questions are:

  • How do I get started in adding Elixir support to code-prettify?
  • How do I represent Elixir constructs that need to be highlighted?
  • And should I even send in a pull request? There seems to be minimal activity in the project, and many pull requests haven’t been merged or closed for a while.

Showing Posts 1 to 10

nietaki

nietaki

I was thinking about the same thing and slowly started looking into that. It seems like the syntax highlighting definitions for erlang or Scala aren’t really that complicated, and I would argue Scala has a more ambiguous syntax than Elixir.

It also seems like the code-prettify project is still pretty alive and they do accept PRs, so that’s all looking good.

Is there a good place to get Elixir’s grammar or something similar? It would probably help make the highlighter more comprehensive.

tyro

tyro

In the Elixir issue for code-prettify (here), they link to the atom editor elixir grammar (here) which looks quite useful.

nietaki

nietaki

I looked into how the google-prettify works and prepared a plugin for elixir that seems to be working. Now I could use you guys’ help making sure it’s nice and robust.

Here’s how you can try it out: I put an editable example in the live-preview branch of my fork of the repo. Clone it and open it in a browser or go to rawgit and you can play around with the source code and see how the prettifier behaves.

Let me know what you think! Please point out what needs improving.

Notes:

  • The main things that can be broken is probably false positives on some classes. For example 1_000 is a correct integer, but 1__000 isn’t and shouldn’t be highlighted like one.
  • Things to be treated as “keywords” in Elixir are a bit of a judgement call, since most of the functionality is implemented with macros. I used my gut on this one - let me know if you think any constructs should (not) be treated as keywords but are(n’t).
  • Before I submit a PR to the main fork I’ll want to add some unit tests for the elixir prettifier - I just wanted to get some feedback first.
  • If you want to submit some changes to the prettifier in my fork, submit it to the lang-elixir branch - the live preview is just a utility and won’t be included in the PR for the main project.
  • I’m not sure what class the sigils should be highlighted as - they’re currently being coloured the same as atoms, because it’s consistent with the highlighting I have in my main editor.
  • I don’t think it’s worth it to support highlighting inside string interpolation - It would probably be more trouble than it’s worth using their createSimpleLexer
OvermindDL1

OvermindDL1

As long as their lexer is not something stupid like regex it should not be hard.

I really really hate the idiotic highlighting libraries that think everything can be lexed with regex, morons…

nietaki

nietaki

Don’t look in the source then :slight_smile: It is what it is though, as long as it makes the StackOverflow questions/answers more readable, I’m a happy person.

nietaki

nietaki

I have tried the highlighting with some more code and ironed out some issues. An updated interactive demo still available on rawgit.

I’m aiming to write some tests and submit a PR this weekend, so if you have any feedback, speak up :wink:

nietaki

nietaki

It feels like I’m mostly talking to myself here, but here’s the PR for the Elixir support: Add Elixir language support by nietaki · Pull Request #478 · googlearchive/code-prettify · GitHub

OvermindDL1

OvermindDL1

Cool, better syntax highlighting on popular syntax highlighters, even if the syntax highlighter itself is stupidly made in regex but nothing you can do about that, is still a great help due to the visibility! :slight_smile:

notriddle

notriddle

Breaks when I type this in:

"I love me some #{ "string" <> "y" } interpolation"

It might not support hilighting inside string interpolation, but it should at least ignore quotes inside of an interpolated part, so it doesn’t just look wrong.

notriddle

notriddle

Your example here:

%{foo: :bar, "yes, this compiles": :"also an atom"}

Both of them are atoms; :“also an atom” and :“yes, this compiles” are both atoms. Your syntax hilighter thinks that “yes, this compiles” is a string.

iex(1)> %{ "yes, this compiles": :"also an atom" } |> Enum.map(fn {key, val} -> is_atom key end)
[true]

Where Next? Top

Trending in Discussions Top

wmnnd
Hey folks, I wanted to share with you a project I’ve been working on for a while: It’s an Open Source (AGPLv3) newsletter tool. Think Ma...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
sntran
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
Ganna
Hi everyone, I have 8 years of production experience with Erlang/OTP and I’m just starting to get to know Elixir. What would you learn f...
New
johnkirkham
A note on form. Joe Armstrong, co-creator of the Erlang programming language, died in April 2019. What follows is a work of narrative non...
New
gtcode
I’ve been tinkering with Lynx (by José) via hold_ledger. I used AI to write the code, a separate specification, the tests, and the Lean p...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews