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.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 11 to 20- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
rvirding
Yes, shift-reduce errors can be quite difficult to find and fix. From the very start I sort of dived in at the deep end by implementing leex
, and yecc is actually a very old erlang tool.
mfrasca
but I’m wondering … should I be scared of the quoted format. I’m not sure why I should not just produce it from my parser and put it into a macro?
tmbb
Currently forage only supports intersection, not union. It’s easy to add support for unions, though.
kip
Well my first unix was pre-System III and it’s friends lex and yacc. I think they qualify as ancient
And thanks for writing them as part of Erlang, it feels like they should belong in any build system and it’s great they are standard issue.
rvirding
Yes, pre-System III lex and yacc qualify as ancient
While I did implement leex, I cannot take credit for yecc. The first yecc versions were implemented by another guy at the Ericsson Computer Science Lab, Carl Wilhelm Welin.
mfrasca
since I’m here to learn, I would like to go through this macro idea.
I met two difficulties producing that Elixir quote directly from yecc:
I’m in Erlang, which I know even less than Elixir,
so for example the
<expression> ::= <expression> or <bterm>production:I would write the corresponding action as
{or, [context: Elixir, import: Kernel], '$1', '$3'}.but I get a
syntax error before: 'or',and once I replace the atom with the string
"or", just to see what other problems there are, I get twoillegal expression.This one works, but is obviously not what I need:
{"or", [context, "Elixir", import, "Kernel"], '$1', '$3'}.I miss the leading ‘c.’ (and would not want to ask the user to add it).
I guess than a function in the
Erlang code.section can solve this one.rvirding
Some quick comments:
oris a reserved word, hence the syntax error, so to get the atom you need to write'or'.[context: Eiixir, import: Kernel]is illegal so you would have to write[{context,'Elixir'},{import,'Elixir.Kernel'}]to get the corresponding structure. Erlang has very few special syntax cases like Elixir property lists.c.?mfrasca
single quoting the
orworks, thank you. and yes I remembered that the[a: b]was a reduced representation of something else. I could just nor remember what.the leading
c.is the partfrom c in <table-name>of the Ecto query I’m reconstructing.in Erlang I’m working with single quoted strings, and in Elixir I need double quoted ones, so I will need a conversion function. but I also need to convert single quoted strings to the corresponding atom. I will review in the light of your hint, and hope to be more specific, but it has to do with the production
<query> ::= <domain> where <expression>. I have the name of the table in an Erlang single-quotes string, and I need the atom by that name. like'City'and I need:City. see above, the third line in the quoted form of the Ecto query.mfrasca
the leading
domain(orc.), I can do easily, and the conversion from string to binary and string to atom I also found their names.so I’m all set I guess,
the single quotes to produce atoms, and the syntax for associative lists, …,
I’ll report here if I manage to get anything working, or at least looking like something that could work.
thank you all!
mfrasca
I’m almost there, sorry for the interruptions.
the rest looks fine to me, but what do I do with this
import: :"Ecto.Query", which in my quoted target should look likeimport: Ecto.Query? same for the:Kernel, what’s that leading colon?the yecc code looks like this:
query -> domain where expression : {from, [{context, 'Elixir'}, {import, 'Ecto.Query'}], [{in, [{context, 'Elixir'}, {import, 'Kernel'}], [{domain, [], 'Elixir'}, '$1']}, [{where, '$3'}]]}.