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: tomas
Subject: Re: Make peg.el a built-in library?
Date: Thu, 10 Nov 2022 09:29:32 +0100

On Thu, Nov 10, 2022 at 10:15:23AM +0200, Eli Zaretskii wrote:
> > Date: Thu, 10 Nov 2022 06:25:55 +0100
> > From: <tomas@tuxteam.de>
> > 
> > > Would someone like to tell me in 10 lines what job peg.el does?
> > 
> > PEG (Parsing Expression Grammars [1]) is a grammar notation which can
> > be automatically translated into a parser (think regular expressions).
> 
> The reference [1] was probably meant to be
> 
>   https://en.wikipedia.org/wiki/Parsing_expression_grammar

Thanks. -ENOCOFFEE, possibly :)

> or somesuch
> 
> > The notation is actually similar to that of regexps.
> 
> I believe you meant "similar to regular expressions in rx form"?

I wasn't particularly thinking of rx. PEGs in general also have a
"classical" spelling which looks deceivingly similar to "classic"
regular expressions.

[...]

> I think an example from peg.el will clarify the issue:
> 
>   ;; This file implements the macros `define-peg-rule', `with-peg-rules', and
>   ;; `peg-parse' which parses the current buffer according to a PEG.
>   ;; E.g. we can match integers with:
>   ;;
>   ;;     (with-peg-rules
>   ;;         ((number sign digit (* digit))
>   ;;          (sign   (or "+" "-" ""))
>   ;;          (digit  [0-9]))
>   ;;       (peg-run (peg number)))
>   ;; or
>   ;;     (define-peg-rule digit ()
>   ;;       [0-9])
>   ;;     (peg-parse (number sign digit (* digit))
>   ;;                (sign   (or "+" "-" "")))

Thanks for the example. This one stresses tha main "selling point" of
PEGs, that they can "do" a grown up parser without separating lex and
"parse" into two "floors". The downside is that they aren't as "tall"
(as the customary LALR/regexp combo).

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature


reply via email to

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