otac0n / Pegasus

A PEG parser generator for .NET that integrates with MSBuild and Visual Studio.
http://otac0n.com/Pegasus/
MIT License
203 stars 37 forks source link

Sequence not working as expected #104

Open david-pfx opened 6 years ago

david-pfx commented 6 years ago

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.

otac0n commented 6 years ago

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.

david-pfx commented 6 years ago

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.