otac0n / Pegasus

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

Dynamic literal #129

Open david-pfx opened 2 years ago

david-pfx commented 2 years ago

So we have code assertions to control parsing, and code expressions to define a return value.

I propose code Literals, which represent C# code that returns a literal value, as a string, to be used by the parser.

EndLine = ";" CommentMarker = "#"

becomes

EndLine = %{ GetEndLine() } CommentMarker = %{ GetCommentMarker() }

The point is to make dynamic literals, set externally by a configuration file or internally during the parse. The examples given are real, taken from a current project.

otac0n commented 10 months ago

You can kind-of do this via three approaches,

I am still not closing this issue because I think your suggestion is worth considering as an extension.