Patch Parsec's comment parsing #2985
Open
+737
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
String
s. Parsec will immediately turn those strings intoParser String
s by runningText.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
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
andText.Parsec.Token
modules into our codebase, and modify them so they accept aParser
for comment symbols instead of only a string.