lark icon indicating copy to clipboard operation
lark copied to clipboard

testing/debugging grammar interactively ?

Open asmodehn opened this issue 6 years ago • 12 comments

I am thinking something along the lines of https://omrelli.ug/nearley-playground/ that provides an interactive feedback to the user creating a grammar, via examples or other way. The nicest tool I know is about regular expressions only : https://regex101.com/

Is there something like that for parser grammars ? where we could just add lark syntax?

I am not used to write parser grammars, and I am currently doing this in a python interpreter. The raw python error messages can be quite cryptic for a newcomer. Any idea ? Am I missing an obvious tool here ?

asmodehn avatar May 22 '18 14:05 asmodehn

Sorry, there isn't an interactive tool for Lark.

Lark does have syntax highlighting for sublime-text, so you could use it to edit the grammar file and load it from the interpreter (it would probably be more convenient than writing the grammar in the interpreter).

erezsh avatar May 22 '18 14:05 erezsh

It should probably be pretty simple to fork nearley-playground and change the syntax to Lark's. It could be a nice addition to the lark toolbox.

erezsh avatar May 22 '18 14:05 erezsh

I am already using sublime for syntax highlighting. Syntax is usually correct, but I guess I'm getting trapped into all the non obvious cases (using this parser fails, but why ?).

Related "feature request" issue is at https://github.com/lark-parser/lark_syntax/issues/2

We probably would want to run Lark (python code) in the browser, somehow... Just to make sure we are actually testing lark while using it, and providing a strong guarantee for the grammar one would copy/paste between web page and lark file...

Let me know if you have any preference for a Browser Python implementation ( brython, skulpt, etc.) I might give it a try sometime...

asmodehn avatar May 22 '18 16:05 asmodehn

Just for the record, and maybe inspiration, the two best tools I could find around the net :

  • https://mdaines.github.io/grammophone
  • https://web.stanford.edu/class/archive/cs/cs103/cs103.1156/tools/cfg/

asmodehn avatar May 22 '18 21:05 asmodehn

The first one seems nice, but a little primitive. Ideally, you'd have syntax highlighting, proper error handling, and a display of the resulting tree (when given an input).

I don't have experience with brython or skulpt, or alternatives, so I'll leave it to whoever chooses to implement it. I can say that from a cursory glance, brython seems like the best choice.

erezsh avatar May 23 '18 06:05 erezsh

Now that Lark has an online IDE, this should be easier to implement: ~~https://lark-parser.github.io/lark/ide/app.html~~ new link: https://www.lark-parser.org/ide/

erezsh avatar Aug 06 '20 19:08 erezsh

Oh the online IDE is very nice indeed ! Sadly, I probably won't have time to come back to this in the near future though, but I ll give it a spin whenever I can.

asmodehn avatar Aug 07 '20 08:08 asmodehn

Now that Lark has an online IDE, this should be easier to implement: https://lark-parser.github.io/lark/ide/app.html

Never loads, mon! :>

enjoysmath avatar May 16 '23 21:05 enjoysmath

Sorry, that's an old link! New link is https://www.lark-parser.org/ide/

erezsh avatar May 17 '23 14:05 erezsh

P.S. @enjoysmath You should be able to share the same Lark instance with as many modules that you want. As long as you use the documented API, it should work fine.

erezsh avatar May 17 '23 15:05 erezsh

I asked in the Django forums, but was unable to get a clear answer. What about Lark in a Django application? Do I create an instance for every user in their request.session?

On Wed, May 17, 2023 at 8:04 AM Erez Shinan @.***> wrote:

P.S. @enjoysmath https://github.com/enjoysmath You should be able to share the same Lark instance with as many modules that you want. As long as you use the documented API, it should work fine.

— Reply to this email directly, view it on GitHub https://github.com/lark-parser/lark/issues/149#issuecomment-1551568481, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMIF56WIHFX7LGIX6EEILDXGTSHFANCNFSM4FBC6WTQ . You are receiving this because you were mentioned.Message ID: @.***>

enjoysmath avatar May 17 '23 17:05 enjoysmath

@enjoysmath I don't remember Django well enough, but if it's technically possible to share the same Lark instance, I don't see a reason not to.

erezsh avatar May 17 '23 18:05 erezsh