marcuslankenau

marcuslankenau

ExLR - LR Parser library

Today I published a toy project, that I worked on in the last couple of weeks. It is an LR Parser generator. I normally use yecc in my projects for parsing. It works ok, but I am not happy with usability. Besides that it seems to have issues with special (utf-8) characters. I also tried other libraries (like xpet), but struggling to use them for my purpose (probably my fault understanding the concepts). I created an LR parser years ago in c# and always dreamed of redoing it in elixir.

The parser is defined using a DSL:

  use ExLR

  lr skip_whitespaces: true do
    S <- S + "+" + :integer = fn ([a, _, b]) -> a + b end
    S <- :integer           = fn ([a]) -> a end
  end

It provides a parse function that can be used like

# parse("3+4")
{:ok, 7}

It contains a scanner, but it can also be called with a list of symbols (using a different scanner). Each symbol is a tuple of 3 containing the symbol, the data and the position:

parse([{:integer, 3, {0, 0}}, {"+", nil, {0, 1}}, {:integer, 4, {0, 2}}, {:"$", nil, {0, 3}}])

The scanner is initialised by going through the rules. It accepts:

  • Strings
  • :integer
  • :text
  • :quoted_text
  • :ws

Special terminals can also be defined:

  terminal :zip_code, chars: ?0..?9, min: 4, max: 5

  lr skip_whitespaces: true do
    Address <- Zip + City = fn [zip, city] -> %{zip: zip, city: city} end
    Zip <- :zip_code
    City <- :text
  end

You can find the repository here: GitHub - mlankenau/exlr · GitHub
I put a couple of examples in the test folder. I think they are a good reference.

I hope it is adding some values for other devs and highly appreciate any feedback.

Happy easter :slight_smile:

Where Next?

Popular in Announcing Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story &lt;- Meeseeks.all(html, css("tr.athing")) do...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19228 141
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
pkrawat1
Presenting Aviacommerce, open source e-commerce platform in Elixir Aviacommerce is an open source e-commerce platform in Elixir. We at...
New
riverrun
I’ve just released version 3 of Comeonin, a password hashing library. The following small changes have been made: changes to the NIF c...
New
Eiji
ExApi is a library that I’m developing now and hope release soon This library will allow to: list all apis list all api implementation...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
cjen07
parameterized pipe in elixir: |n&gt; edit: negative index in |n&gt; and mixed usage with |&gt; are supported example: use ParamPipe ...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
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
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
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
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement