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

Sample for parsing comments #100

Open
jorgeleo opened this issue May 8, 2024 · 1 comment
Open

Sample for parsing comments #100

jorgeleo opened this issue May 8, 2024 · 1 comment

Comments

@jorgeleo
Copy link

jorgeleo commented May 8, 2024

hi,

I was looking for example of parsing comments.

Single line // And this will be a comment

And multiline

/*
 Comment
*/*
   Still a comment
 */
Closing of the second comment, but still in the first comment
*/

@sebastienros
Copy link
Owner

Might require some "counting" and a custom parser context to maintain this counter.

Example in Fluid: https://github.com/sebastienros/fluid/blob/main/Fluid/FluidParser.cs#L226-L247

This is the context class: https://github.com/sebastienros/fluid/blob/main/Fluid/Parser/FluidParseContext.cs

The idea is that when you find /* you increment a counter and decrement it when you find */. But the result of the parser can differ if the counter is back to zero. And if you reach EOF while the counter is positive then everything is a comment, or you can return an error.

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

No branches or pull requests

2 participants