kswoll / npeg

This parser is an implementation of a Packrat Parser with support for left-recursion. The algorithm for left recursion is a modified version of Packrat parsers can support left recursion.
MIT License
16 stars 5 forks source link

Optional causes issue when mapping List property #6

Closed andrew-boyarshin closed 4 years ago

andrew-boyarshin commented 4 years ago

https://github.com/kswoll/npeg/blob/51d0302348f9574845d3221fe8748e5298498cf0/PEG/Builder/PegBuilder.cs#L366-L376

System.InvalidCastException: Unable to cast object of type 'PEG.SyntaxTree.Optional' to type 'PEG.SyntaxTree.OneOrMore'.

It's logical to process Optional in the same way as ZeroOrMore

kswoll commented 4 years ago

That makes sense to me. Out of curiosity, what line was throwing that cast exception?

andrew-boyarshin commented 4 years ago

@kswoll line 375 of course, if you're talking about line in the snippet above. But that doesn't matter, since I had to refactor the whole function to fix all arising issues (it wasn't just this one). I'll send a PR with it today.

This project is truly amazing, the use of code generation behind the scenes really simplified the PEG description in natural C#. It was a bit unfortunate that there is no docs or example on how to use Consume and AST attributes, but I figured it out and will soon publish a project with a sample of Consume usage.

andrew-boyarshin commented 4 years ago

The exception was due to my mistake, but it still wouldn't hurt.

andrew-boyarshin commented 4 years ago

This can be considered as closed and fixed by #7.