Skip to content

Patch Parsec's comment parsing #2985

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Patch Parsec's comment parsing #2985

wants to merge 2 commits into from

Conversation

cprecioso
Copy link
Member

@cprecioso cprecioso commented Jul 21, 2025

Part of #2949

Problem

Parsec...

When creating a parser with Parsec, you can create a base lexer over which to build up your high-level parser. This lexer accepts options for describing how comments work in the language, and will then handle them transparently as part of the whiteSpace parser.

However, the comment options only accept Strings. Parsec will immediately turn those strings into Parser Strings by running Text.Parsec.string commentLine, but it doesn't accept parsers itself.

... and Prisma

The Prisma Schema Language (PSL), has two kinds of comments: regular comments that can be ignored (start with //), and documentation comments that have to become part of the AST (start with ///).

If we just tell Parsec that comments start with //, it will ignore the documentation comments too. But if we don't let Parsec handle the comments automatically, we will have to remember to put optional comment handling in all of our parsers, spamming it semi-randomly through the codebase, and risking forgetting it some place, or not creating a test for a specific comment placements.

Solution

We need to be able to tell Parsec that the comment definition is

commentLine :: Parser ()
commentLine = string "//" >> notFollowedBy (char '/')

The patch inside of Parsec to accept that is just a couple of lines. But to do it I've needed to copy the Text.Parsec.Language and Text.Parsec.Token modules into our codebase, and modify them so they accept a Parser for comment symbols instead of only a string.

@cprecioso cprecioso force-pushed the push-tmkmvmvnruvk branch from 9a5ed83 to d47e94a Compare July 21, 2025 14:31
Copy link

Deploying wasp-docs-on-main with  Cloudflare Pages  Cloudflare Pages

Latest commit: d47e94a
Status: ✅  Deploy successful!
Preview URL: https://c0ab840a.wasp-docs-on-main.pages.dev
Branch Preview URL: https://push-tmkmvmvnruvk.wasp-docs-on-main.pages.dev

View logs

@cprecioso cprecioso changed the title Patch comment parsing Patch Parsec's comment parsing Jul 22, 2025
@cprecioso cprecioso requested a review from infomiho July 22, 2025 07:49
@cprecioso cprecioso self-assigned this Jul 22, 2025
@cprecioso cprecioso marked this pull request as ready for review July 22, 2025 07:50

oneLineComment =
do
_ <- try (commentLine languageDef)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change, this used to be

-        _ <- try (string (commentLine languageDef))
+        _ <- try (commentLine languageDef)

@cprecioso
Copy link
Member Author

If we merge this solution, I will create an issue and link to here so that we know that we must remove this workaround

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

Successfully merging this pull request may close these issues.

1 participant