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
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 Libraries Top

kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
574 16576 179
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: https://github.com/devonestes/assertions ...
New
mathieuprog
Hello :wave: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First and fore...
New
praveenperera
FastRSS Parse RSS feeds very quickly: This is rust NIF built using rustler Uses the RSS rust crate to do the actual RSS parsing Speed...
New
josevalim
EDIT: since Ecto 3.0 final version is out, this post was amended to use the final versions in the instructions below. Hi everyone, We a...
New
mcrumm
If you would like to migrate away from node/npm/webpack while still using sass, the dart_sass package provides a installer and runner for...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
Jskalc
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue. It’s a seamless integration of Vue and Phoenix LiveView, i...
New
gjaldon
As the title states, EctoEnum has just been updated after some time of hardly any activity in the repo. Here’s the latest release: https:...
New
ostinelli
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

Sub Categories:

We're in Beta

About us Mission Statement