dlang-community / Pegged

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

Parameterized rules still have problems #52

Closed PhilippeSigaud closed 12 years ago

PhilippeSigaud commented 12 years ago

This is a'post'it' issue:

There are problems with the way parameterized rules are generated: string/TParseTree overloading does not work.

Valloric commented 12 years ago

I think I've just hit this issue. I'm getting a compilation error from dmd telling me that a template (generated from a parametrized rule) matches more than one template declaration.

Any chance of getting this fixed soon?

PhilippeSigaud commented 12 years ago

I'll do that in the 24h to come, I know what I have to do, but was away from home for a long time. Can you send me the faulty grammar please?

Valloric commented 12 years ago

I'll create a test case and send it to you as soon as I arrive back home.

On Thu, Oct 4, 2012 at 11:43 PM, Philippe Sigaud notifications@github.comwrote:

I'll do that in the 24h to come, I know what I have to do, but was away from home for a long time. Can you send me the faulty grammar please?

— Reply to this email directly or view it on GitHubhttps://github.com/PhilippeSigaud/Pegged/issues/52#issuecomment-9166902.

Valloric commented 12 years ago

Here's a test case that fails to compile with the 'matches more than one template declaration' error message. The test code doesn't necessarily make much sense, but it does exhibit the problem.

#!/usr/bin/env rdmd

import std.stdio;
import pegged.grammar;

mixin( grammar( `
Test:
  HtmlBlockInTags <- HtmlBlockTag( 'div' )

  Spaces     <~ Spacechar*
  Spacechar  <- " " / "\t"

  HtmlBlockTagOpen( Tag ) <- "<" Spaces Tag Spaces ">"
  HtmlBlockTagClose( Tag ) <- "<" Spaces "/" Tag Spaces ">"
  HtmlBlockTag( Tag ) <- HtmlBlockTagOpen( Tag ) HtmlBlockInTags* HtmlBlockTagClose( Tag )
`));

void main() {
  auto tree = Test("<div></div>");
  writeln( tree );
  writeln( tree.matches );
}
PhilippeSigaud commented 12 years ago

I pushed a commit that should correct the problem. It was not heavily tested, though.

Valloric commented 12 years ago

Does it at least pass the test case I posted here?

Valloric commented 12 years ago

Just tried it and it does pass the test case and both the code I was working on when I discovered the problem. Thanks for the fix!

I'll report any other problems if I find them.