View mode: basic / threaded / horizontal-split · Log in · Help
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On Sun, Mar 11, 2012 at 08:26, Andrei Alexandrescu
<SeeWebsiteForEmail@erdani.org> wrote:

> Any chance you consider adding AST generator actions as discussed in the
> main forum a while ago?

The AST is automatically produced, and there are already AST actions
to simplify / guide its creation. There already is an 'ignore that
node' syntax and a 'fuse the captures here'.
Also, semantic actions are there, so I think the basis is there, I
just need to add a few tree actions : cut children, take only some
children.

I'll add it today.

But maybe you had something else in mind? I'll go and search for the
thread you refer to.
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On Sun, Mar 11, 2012 at 08:30, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> On Sunday, March 11, 2012 00:28:42 Philippe Sigaud wrote:
>> Hello,
>>
>> I created a new Github project, Pegged, a Parsing Expression
>> Grammar (PEG) generator in D.
>
> Cool! PEGs aren't used all that much for language grammars - primarily because
> BNF and EBNF are more traditional I think - but they're definitely cool. And
> it's great to see a D implementation of a PEG parser.

Is there an EBNF grammar for D somewhere, I mean outside the dlang docs?

I vaguely remember someone trying to write one.
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On 3/11/12 1:35 AM, Philippe Sigaud wrote:
> On Sun, Mar 11, 2012 at 08:26, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org>  wrote:
>> Splitting on ";" is trivial and makes client code considerably easier to
>> play with.
>
> It's already implemented! No need for ';'

Great! I think you'd be wise to add the ";", otherwise it's impossible 
to split complex rules on more than one line. Alternatively you could 
have the complement, a line continuation thingie.


Andrei
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On Sunday, March 11, 2012 08:39:47 Philippe Sigaud wrote:
> On Sun, Mar 11, 2012 at 08:30, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> > On Sunday, March 11, 2012 00:28:42 Philippe Sigaud wrote:
> >> Hello,
> >> 
> >> I created a new Github project, Pegged, a Parsing Expression
> >> Grammar (PEG) generator in D.
> > 
> > Cool! PEGs aren't used all that much for language grammars - primarily
> > because BNF and EBNF are more traditional I think - but they're
> > definitely cool. And it's great to see a D implementation of a PEG
> > parser.
> 
> Is there an EBNF grammar for D somewhere, I mean outside the dlang docs?
> 
> I vaguely remember someone trying to write one.

Someone may have been trying to write one, but I don't believe that there's an 
official one, and I recall someone complaining the the BNF grammar was 
inaccurate in a number of places, but that may have been fixed now, since 
Walter did a number of documentation fixes a few weeks back.

- Jonathan M Davis
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On Sun, Mar 11, 2012 at 08:46, Jonathan M Davis <jmdavisProg@gmx.com> wrote:

>> Is there an EBNF grammar for D somewhere, I mean outside the dlang docs?

> Someone may have been trying to write one, but I don't believe that there's an
> official one, and I recall someone complaining the the BNF grammar was
> inaccurate in a number of places, but that may have been fixed now, since
> Walter did a number of documentation fixes a few weeks back.

Hmm. I'll post on D.main and see.
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On 3/11/12 1:38 AM, Philippe Sigaud wrote:
> On Sun, Mar 11, 2012 at 08:26, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org>  wrote:
>
>> Any chance you consider adding AST generator actions as discussed in the
>> main forum a while ago?
>
> The AST is automatically produced, and there are already AST actions
> to simplify / guide its creation. There already is an 'ignore that
> node' syntax and a 'fuse the captures here'.
> Also, semantic actions are there, so I think the basis is there, I
> just need to add a few tree actions : cut children, take only some
> children.
>
> I'll add it today.
>
> But maybe you had something else in mind? I'll go and search for the
> thread you refer to.

I was thinking of ANTLR-style operators in which you say where the root 
should be and you get to drop unnecessary nodes.

(Post on 2012/02/29 10:19AM GMT-0600.)


Andrei
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On Sun, Mar 11, 2012 at 08:47, Andrei Alexandrescu
<SeeWebsiteForEmail@erdani.org> wrote:

> Great! I think you'd be wise to add the ";", otherwise it's impossible to
> split complex rules on more than one line. Alternatively you could have the
> complement, a line continuation thingie.

Complex rules can be multi-line, I'll put more examples of this in the docs.

Now that Pegged is bootstrapped (the grammar generator was generated
by Pegged itself), it's easy to change the grammar.

Anyway, the separating if done on the rule definitions  (Identifier <- ...)

A <- B   C
    / C
/D    # // OK, cut between D and E.
E <- New Def

You can insert line comments with '#'
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On Sun, Mar 11, 2012 at 08:53, Philippe Sigaud
<philippe.sigaud@gmail.com> wrote:

> Anyway, the separating if done on the rule definitions  (Identifier <- ...)

Aw, I meant, the separation is done on rule definitions. Damn children
climbing on me to get more breakfast :-)
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On Sun, Mar 11, 2012 at 08:51, Andrei Alexandrescu
<SeeWebsiteForEmail@erdani.org> wrote:

> I was thinking of ANTLR-style operators in which you say where the root
> should be and you get to drop unnecessary nodes.
>
> (Post on 2012/02/29 10:19AM GMT-0600.)

Get it, thanks for the ref!

There is an operator to drop unnecessary nodes (':'). Apart from that,
a Pegged grammar is a self-contained entity: it automatically cuts
nodes coming from other grammars, to simplify the tree (it keeps the
matcheds substrings, of course). I plan to code different type of
grammars, to play with the way the deal with nodes coming from outside
rules and grammar composition.

As for the root, the PEG rule is that the first rule in the grammar is
the root. But currently, I deliberately made my grammars unsealed, in
that the user can call any rule inside the grammar to begin parsing:

mixin(grammar("
   A <- B C
   B <- ...
   C <-
"));

A.parse("some input"); // standard way to do it, the parse tree will
be rooted on an 'A' node.
B.parse("some input"); // also possible, the parse tree will be rooted
on a 'B' node.

I'll add what I called closed and sealed grammars. I'll also add named
grammars and such in the days to come. I can add a root note
indication ("unless told otherwise, when asked to parse with grammar
G, begin with rule R).
March 11, 2012
Re: Pegged, a Parsing Expression Grammar (PEG) generator in D
On 11-03-2012 08:22, Philippe Sigaud wrote:
> On Sun, Mar 11, 2012 at 00:34, Alex Rønne Petersen<xtzgzorex@gmail.com>  wrote:
>
>> Admittedly I have not heard of PEGs before, so I'm curious: Is this powerful
>> enough to parse a language such as C?
>
> I think so. But you'd have to do add some semantic action to deal with
> typedefs and macros.

Oh, I should have mentioned I only meant the actual language (ignoring 
the preprocessor).

Why do you need semantic actions for typedefs though? Can't you defer 
resolution of types until after parsing?

>
> People parsed Java and Javascript with them. I personnally never used
> Pegged for more than JSON and custom formats, but I intend to try the
> D grammar.

-- 
- Alex
1 2 3 4 5 6
Top | Discussion index | About this forum | D home