dlang-community / Pegged

A Parsing Expression Grammar (PEG) module, using the D programming language.
534 stars 66 forks source link

The Pegged parser does not build anymore #100

Closed PhilippeSigaud closed 11 years ago

PhilippeSigaud commented 11 years ago

Uh oh.

The Pegged parser, generated from regenerate.d does not work any more. DMD says there is a recursive expansion in a getName. The failed rule comes from the small D grammar embedded in the Pegged grammar to read direct code between { } brackets.

That's a mighty regression.

callumenator, could get an eye on this? I'll try to rebuild everything by ditching the D grammar part and see if that fails or not.

PhilippeSigaud commented 11 years ago

Looking a this a bit more:

commit 35a3fc9acf17fdd1d5a109d98fab36abb61c577f works. This was before cal's addition to the Pegged grammar.

But commit d2f522ee5e6c5fc6da8781ddb6374cbf303302a6 (the merging) also works.

Hmmm.

callumenator commented 11 years ago

rdmd regenerate.d works for me at 466a1c4be0f4e637ce3f41c895601dc214a7f7dd but not 99e759bbc87f2e423aac913638f307538b66590c, where I get the same error as you mentioned.

PhilippeSigaud commented 11 years ago

Same here, confirmed. So, my mistake :)

Thanks a lot for the search, I wanted to do that on Sunday, now I can concentrate on correcting this bug.

PhilippeSigaud commented 11 years ago

I did a lot of surgery on the project and stashed a bunch of recent changes into another branch (macro2).

The current master regenerates the Pegged parser OK.

callumenator commented 11 years ago

Have the semantic action changes to the pegged grammar been retained somewhere? It looks like they are no longer in examples.peggedgrammar.d?

PhilippeSigaud commented 11 years ago

On Wed, Jan 23, 2013 at 1:46 AM, callumenator notifications@github.comwrote:

Have the semantic action changes to the pegged grammar been retained somewhere? It looks like they are no longer in examples.peggedgrammar.d?

I dropped them a few commits ago (yesterday or the day before), for that was the only mean I found to get the parser to still function.

The are still there:

git checkout 35e8f7ab4e4636b2e43550fc7beb5c37d3f0e64a

Or, here in raw form:

Action Rule

Action <- :ACTIONOPEN Spacing ((Lambda / qualifiedIdentifier) (:SEPARATOR (Lambda / qualifiedIdentifier))) Spacing :ACTIONCLOSE Lambda <~ (!(ACTIONCLOSE/SEPARATOR) (LambdaItems / NestedList('{',LambdaItems,'}') / .))

LambdaItems <- ~DComment / ~DString / ~DParamList DString <- WYSString / DBQString / TKNString / DLMString

WYSString <- 'r' doublequote (!doublequote .)* doublequote / backquote (!backquote .)* backquote

DBQString <- doublequote (!doublequote Char)* doublequote

TKNString <- (&'q{' ('q' NestedList('{',DString,'}')))

DLMString <- ('q' doublequote) ( (&'{' NestedList('{',DString,'}')) / (&'',DString,') / (&'(' NestedList('(',DString,')')) / (&'<' NestedList('<',DString,'>')) ) doublequote

DComment <- DLineComment / DBlockComment / DNestingBlockComment

DLineComment <- "//" (!endOfLine .)* endOfLine DBlockComment <- "/" (!"/" .)* "*/" DNestingBlockComment <- NestedList("/+","+/")

DParamList <- NestedList('(',')')

Linear nested lists with and without special items

NestedList(L,Items,R) <- ^L ( !(L/R/Items) . )* ( Items / NestedList(L,Items,R) / ( !(L/R/Items) . ) )* ( !(L/R/Items) . )\ ^R

NestedList(L,R) <- ^L ( !(L/R) . )* (NestedList(L,R) / ( !(L/R) . ) )* ( !(L/R) . )\ ^R

PhilippeSigaud commented 11 years ago

An idea I wanted to test was to make {{ ... }} (double curly, no space) the delimiter for raw D code (that would have to contain no pair of no-spaces closing curly braces). That way, the grammar simply become:

# Action Rule
Action      <- SimpleAction / RawCode
SimpleAction <- :ACTIONOPEN Spacing qualifiedIdentifier (:SEPARATOR qualifiedIdentifier)* Spacing :ACTIONCLOSE
RawCode <~ :ACTIONOPEN :ACTIONOPEN (!(ACTIONCLOSE ACTIONCLOSE) .)* :ACTIONCLOSE :ACTIONCLOSE

And RawCode directly produce the string to be mixed in. The only limit is the code must not contain a }} pair, which I deem acceptable. That drastically simplify the grammar and we get back the capacity to insert D code in the grammar.

I thought we had tested the grammar, that's really strange.

callumenator commented 11 years ago

I thought we had tested the grammar, that's really strange.

Well it works at 466a1c4be0f4e637ce3f41c895601dc214a7f7dd, which was only a few days ago, I just thought it was some of the dynamic grammar changes that were causing the trouble.

PhilippeSigaud commented 11 years ago

On Wed, Jan 23, 2013 at 7:25 AM, callumenator notifications@github.comwrote:

I thought we had tested the grammar, that's really strange.

Well it works at 466a1c4https://github.com/PhilippeSigaud/Pegged/commit/466a1c4be0f4e637ce3f41c895601dc214a7f7dd, which was only a few days ago, I just thought it was some of the dynamic grammar changes that were causing the trouble.

I was certain to have tested this commit. Sigh. OK, here we go again.

PhilippeSigaud commented 11 years ago

OK, bad day: my newly generated DMD chokes on to!(string) conversions. Bahhh!

PhilippeSigaud commented 11 years ago

Ahhh.

OK, this seems to work! The Pegged grammar has cal's additions back and I can still dynamically graft new rules to a static parser. Maybe this is a "macros, here we come" moment.

That's commit 0b5ce1bc07541dbb5d407d90a227f42f3bf3194b