[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Make peg.el a built-in library?
From: |
Helmut Eller |
Subject: |
Re: Make peg.el a built-in library? |
Date: |
Sat, 09 Oct 2021 10:12:03 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
On Sat, Oct 09 2021, Michael Heerdegen wrote:
>> "how do you jump over arbitrary text preceding a match?" (the answer
>> seems to be: "use `or' and recursion", at least this is what I found
>> out by myself after a while).
>
> No - using recursive rules of the kind
>
> (rule [maches what I want])
> (search (or rule (and (any) search)))
>
> to advance over preceding text is not a good method in Emacs, this hits
> Emacs' maximum recursion level after a bunch of lines if we advance one
> character each time (which can't be avoided when searching text). Is
> there a better solution for this kind of problem?
Self-recursion can sometimes be rewritten using *. In peg.el, * is "inlined"
and so doesn't run out of stack:
(rule [maches what I want])
(search (and (* (not rule) (any)) rule))
It's kinda like rewriting a self tail call to a while loop.
For the general case, peg.el would need some form of proper tail calls.
Helmut
Re: Make peg.el a built-in library?, Stefan Monnier, 2021/10/09
Re: Make peg.el a built-in library?, Eric Abrahamsen, 2021/10/09