3

In a Node.js project I wrote a query parser in ANTLR4 (JS target). The user queries have a simplified SQL-like grammar that are then processed to full SQL on the server. The query structure can be arbitrarily nested.

I am now porting this app to go. There is, at the moment, no ANTLR4 target for go. I started exploring Ragel but according to the documentation, it expects a regular grammar and does not handle recursion, except for really simple tasks like balancing parentheses.

Another solution is to use my ANTRL4 grammar with the C++ target and then link the C++ classes to go with SWIG (or something) which feels kinda hairy and last resort type of solution.

Yet another solution is to do the parsing on the client side but this would explode the amount of js needed for the client to download. Also feels a bit desparate.

So my questions are:

1) Are there any parser libraries able to handle recursive grammars usable from Go?

2) I am completely unfamiliar with ragel and as it seems quite a complicated tool I want to get this straight before investing time into learning it: Is there any way to handle some recursion (say up to a certain level) in ragel if the grammar is simple enough?

kliron
  • 4,383
  • 4
  • 31
  • 47
  • The standard library has a YACC port, I think it will work (though it's pretty ugly) – Not_a_Golfer Mar 04 '16 at 13:06
  • [Jan Mercl](https://github.com/cznic?tab=repositories) has a lot of packages related to generating parsers. You should be able to build your parser together from them. – thwd Mar 04 '16 at 13:53
  • Go-target is in development. You can try ask author about it: https://github.com/antlr/antlr4/issues/659 – Ivan Kochurkin Mar 04 '16 at 22:40
  • @KvanTTT I know, I followed the discussion on github. It is, as I understand, quite far from production ready yet. – kliron Mar 05 '16 at 08:52

0 Answers0