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: Eric Abrahamsen
Subject: Re: Make peg.el a built-in library?
Date: Fri, 27 Aug 2021 09:57:21 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Helmut Eller <eller.helmut@gmail.com> writes:

Thanks for jumping in (and thanks for the package)!

> On Thu, Aug 26 2021, Eric Abrahamsen wrote:
>
>> Whoo, I've been trying to get enough of a handle on the parsing actions
>> to write a documentation patch for them -- now I'm seeing what Helmut
>> meant by "semantically unintuitive".
>
> What I actually meant with "semantically unintuitive" are issues
> described in Roman Redziejowski's "Trying to understand PEG" paper[*].
> He writes:
>
>    The problem with limited backtracking is that by not trying hard it
>    may miss some inputs that it should accept.  A notorious example is
>    the rule A = aAa | aa that defines the set of strings of a’s of even
>    length. Implemented with limited backtracking, this rule accepts only
>    strings of length 2^n.

Oh... well personally I haven't got to the stage where this is an
issue...

>> The sum total of docs regarding
>> actions is:
>>
>> A "stack action" takes VARs from the "value stack" and pushes the result
>> of evaluating FORMs to that stack.
>
> Using an "open stack" for actions was my rather idiosyncratic choice and
> I'm sure that many people will not like it.  The syntax ( a b -- b a )
> should be familiar to Forth programmers, where it's used to describe the
> stack-effect of commands.  The example would be the SWAP operator.  If
> you have never, or not recently, written some Forth or Postscript, then
> mentally keeping track of the stack state can be challenging.

The stack itself isn't that hard to handle, but I do think the
documentation could be fleshed out with a little hand-holding. The
examples are good, _after_ you understand the basics. I've never written
Forth, and we probably shouldn't expect anyone else to have, either.

I originally assumed the `(a b -- b a) bits could just be replaced with
lambda forms, but I suppose the problem there is that a lambda has a
single return value, and we'd have to do something ugly if we wanted to
push multiple values back onto the stack.

Eric



reply via email to

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