SyntaxTokenParser API Additions #73002
Labels
api-approved
API was approved in API review, it can be implemented
Area-Compilers
Concept-API
This issue involves adding, removing, clarification, or modification of an API.
Feature Request
untriaged
Issues and PRs which have not yet been triaged by a lead
Background and Motivation
Followup to #72518 with a couple of more APIs for some edge cases in Razor. The motivations here are the same, we just need a bit more flexibility around trivia and error recovery than is currently exposed. There are two main changes:
Reset
to get before a token, but we will want all the trivia from before that token handled correctly (particularly any directives). There's no way of doing this with the current API; adding the ability to callParseLeadingTrivia
will give us the necessary granularity. Technically, Razor doesn't need theParseTrailingTrivia
API, and it could be skipped if we don't want to commit to it, but I added it for completeness.@:
to treat it like a single-line comment. Unfortunately, there's some edge cases that make this unworkable, mainly when we need to parse C# from somewhere else later on that same line. To handle this, we add a dedicated token type for bad razor content,BadRazorContentToken
, which will cover this case. We don't use the existingBadToken
type here becauseBadToken
is a bit special; it can cause parsing loops to decide that no further progress can be made and that they should bail upwards to let a containing scope handle the bad tokens. We don't want this to happen in regular C# parsing, so we introduce a specific token kind that will mainly just get converted into a SkippedTokenTrivia by most parsing loops without causing them to exit.Proposed API
Usage Examples
Alternative Designs
None
Risks
We do have to add a dedicated token type here, which isn't the cleanest design, but we don't have another token type to use here that won't have potential negative effects on the actual C# parser.
The text was updated successfully, but these errors were encountered: