emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make peg.el a built-in library?


From: Adam Porter
Subject: Re: Make peg.el a built-in library?
Date: Thu, 26 Aug 2021 12:02:09 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

FWIW, I've been happy using peg.el in org-ql.  I use it to parse strings
like:

  "todo:WAITING scheduled:from=2021-08-01,to=2021-08-31"

into a sexp like:

  (and (todo "WAITING")
       (scheduled :from "2021-08-01" :to "2021-08-31"))

You can see the code I use here:

https://github.com/alphapapa/org-ql/blob/master/org-ql.el#L854

I can't speak much to its performance, because it's plenty fast enough for the
relatively light usage it gets in org-ql.  My only, minor complaint is
that I ended up having to use `eval' on its `with-peg-rules' macro at
runtime:

https://github.com/alphapapa/org-ql/blob/94f9e6f3031b32cf5e2149beca7074807235dcb0/org-ql.el#L908

I tried many, many things before resorting to that, so I don't think I
missed any alternatives at the time.  If that aspect of the API could be
improved, it would be welcomed, but I don't think it's necessary to do
so before adding it to Emacs.

(The issue is that the tokens that are parsed can be added to at
runtime, so they are stored in a variable, and the parsing function is
redefined as necessary at runtime, so it's not possible to define the
parser fully at expansion time.)

Thanks for suggesting this, Eric.  And thanks to Helmut and Stefan for
their work on peg.  It's a great tool.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]