otac0n / Pegasus

A PEG parser generator for .NET that integrates with MSBuild and Visual Studio.

Home Page:http://otac0n.com/Pegasus/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sequence not working as expected

david-pfx opened this issue · comments

I rather expected these two ways of defining an Ident to work the same, but they don't.

    Ident = Letter IdChar* WSC
    Ident = v:( Letter IdChar*) WSC { v }
    WSC = SP* { "" }

The first one includes trailing whitespace, which is unexpected given that WSC is supposed to translate into empty. The generated code goes to all the trouble of acquiring the correct values for each component and then just does a substring from first to last for the returned value.

Not really that useful as it stands. Not a biggie, but annoying.

This is by design, but if you have a proposal for a different behavior, I'm open to taking a change. I agree that this is a bit of a rough edge.

The existing generated code looks like this:
state.Subject.Substring(startCursor0.Location, len)

It's a simple solution, to treat a sequence as just a chunk of characters, but really a sequence is the concatenation of its components. The aim would be to generate code more like:
String.Concat(r0, r1, r2, ...)

But I agree, it would be a breaking change, so it would be best if it could be optional.