mfrasca

mfrasca

I’m rewriting a query parser I have already written in Python twice, with pyparsing/sqlalchemy, and with ply/django. I am now interested in seeing it at work within Elixir. I am VERY new to Elixir, so I’m afraid I’m not yet in the right mindset.

this is the target:
https://github.com/mfrasca/luke/blob/master/src/parser.yrl

and this is the corresponding ply/Python code:
https://github.com/mfrasca/ghini/blob/master/browse/searchgrammar.py

I am not sure about a large amount of issues.

when tokenizing words, I have reserved words, too. in my ply grammar, I let the user write strings quoted or unquoted, but I think I will drop this, to make things easier. or what would you suggest?

are there guidelines / better styles to follow when speaking of Terminals and Nonterminals? I would put Terminals in ALL CAPS, but what’s the impact on the code?

to make an example, is the form ‘[’ preferable to LBRACKET ?

coming from Python, I realise I have the inclination to think I’m producing an object when parsing the query string, and in the end I would evaluate the object, which would be a query. but I guess this is not the way I should think here. I would be building a data structure, which I would then feed to one or more functions (as many as the methods of my python class), defined by pattern-match.

leaving alone when we come to Ecto, where I will need to compute unions and intersections and negations of query sets… and navigating relations between tables… and implementing aggregating functions.

just as an example, these are two legal queries:
taxon where rank.id>=17 and count(verifications)>0
accession where id in [1 5 111] and count(plants.images)>0

it would be of great help getting: code contributions and reviews, reading suggestions, related GPL software sources.

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe
kip

kip

ex_cldr Core Team

Hmmmmm I think maybe @benwilson512 meant nimble_parsec. Which would be good for this project, more expressive and easier to debug than leex and yecc.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Oops, I did!

rvirding

rvirding

Creator of Erlang

Wouldn’t leex/yecc mean writing less code and maybe be faster?

mfrasca

mfrasca OP

having seen the tiny examples in nimble_parsec, and being comfortable with the lex+yacc combination in C and Python, yes, I have this same impression.

al2o3cr

al2o3cr

Consider the leex and yecc packages in the OTP standard library:

kip

kip

ex_cldr Core Team

Less code: yes, I would agree with that (I’ve done a reasonable amount of work in leex/yecc and with nimble_parsec).

Faster: Not sure I agree. Theres some strong sub-binary optiimization in nimble_parsec too, but for sure it would require proper testing of like for like to decide. Or someone more qualified in both approaches than me,

If one has been done the learning curve of leex/yecc or their even more ancient cousins then they are certainly straight forward to use (although I do find removing shift/reduce errors/warnings less than obvious sometimes).

All said, thats why hoped to indicate that if one is getting into parsing for the first time then parse combinators are more approachable and, in my opinion, easier to debug.

mfrasca

mfrasca OP

so, I’m a few steps further. keep in mind that I already had the grammar, I only need the elixir/erlang code associated to the productions.

“a few steps further”, meaning I can parse stuff like "accession where taxon.rank.id=4", into {:where, {:domain, 'accession'}, {{:operator, :cmp_eq}, ['taxon', 'rank', 'id'], 4}}

and if you want to criticize my code to pieces, you’re most welcome! it’s as said on github.

now my question was, I come from object oriented C++ / Python, and my result of parsing would be an object which can execute tasks. in this case, it would be a database query, to which I would ask, please, the count, or again please, all the matching database records.

how would I proceed now, am not so sure, possibly just two count and add functions, defined by pattern matching, and I only need to find out how to manage the Ecto functions.

imartinat

imartinat

You should look at Filtrex, it runs ecto queries from a map of filters.
I used it in one of my project. You could also look at Forage, Mandarin + Forage - An admin tool for phoenix, it seems to be more powerful, there is no documentation but you could ask some help to the author. He answered quickly to my questions.

mfrasca

mfrasca OP

thank you for the hint, I had an extremely quick look (at Filtrex) … is it so that these filters only have intersect? and not union - exclusion? I’ll check with more time tomorrow or so. anyway looks like an interesting point, thank you.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
Since there is no ability to insert an actionable poll (or I am banned from it), here is the text version of it, please reply in comments...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews