Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic literal #129

Open
david-pfx opened this issue Sep 16, 2022 · 1 comment
Open

Dynamic literal #129

david-pfx opened this issue Sep 16, 2022 · 1 comment

Comments

@david-pfx
Copy link

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
Copy link
Owner

otac0n commented Dec 2, 2023

You can kind-of do this via three approaches,

  • resource strings
    • If you want to swap out predefined strings, consider using resource strings. This was designed to support language translation for Gherkin specifically.
  • wildcard + assertion (. &{ ... })*
    • Very powerful approach for regular strings or PEG-parseable strings.
  • #PARSE expressions
    • Full control over the cursor and parse result. Shell out to some other parser and use the length of what is returned.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants