feat(microsyntax): introduce structured microsyntax grammar for structural directives#97
Open
albaniosi wants to merge 8 commits into
Open
feat(microsyntax): introduce structured microsyntax grammar for structural directives#97albaniosi wants to merge 8 commits into
albaniosi wants to merge 8 commits into
Conversation
introduce a new microsyntax grammar that is used to parse the microsyntax of structural directives. This allows us to better understand the structure of structural directives and to provide better support for them in our parser. fix: an issue breaking on ampersand in text
microsyntax grammar nodes
add comprehensive corpus cases for structural directives, including primary bindings, variable declarations, keyword bindings, property bindings, delimiter-less forms, and mixed edge-case combinations update expected parse trees to reflect refined microsyntax node mapping, especially for keyword vs property bindings and variable declarations revert grammar file types in tree-sitter metadata to component.html only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Replaces the ad-hoc
structural_expression/structural_declaration/structural_assignmentgrammar nodes with a new, purpose-built microsyntax grammar that more precisely models the Angular structural directive microsyntax language.This also fixes a small bug where naked
&characters in text nodes would break the parser. (which in theory is correct by the HTML specification, but is ignored in reality by all parsers and renderers)Motivation
The previous grammar did not model the possible syntax of Angulars microsyntax for directives very well. For example:
I use Zed whose angular plugin uses this. The parsing was resulting in completely broken files, so i fixed it locally for me. But I thought this might be useful for the project in general.
I hope this helps and I am happy to alter my code to comply with your wishes and standards if possible.
Changes
Grammar (
grammar.js)structural_expression,structural_declaration,structural_assignment,_else_template_expression, and_context_expression.microsyntax— top-level container for the full directive valuemicrosyntax_anonymous_binding— the primary/leading expression (e.g.items,condition ? a : b)microsyntax_binding— any subsequent named binding (dispatches to one of the three below)microsyntax_keyword_binding— reserved keywords (else,then,of) with an optional expression and aliasmicrosyntax_variable_declaration—let name = value/let namedeclarationsmicrosyntax_property_binding— arbitrary identifier bindings with an expressiontextrule to accept a bare&as a fallback, preventing parse failures on ampersands in template text.[$._any_expression, $.arguments],[$.expression, $.arguments], and[$.microsyntax_property_binding, $._primitive].Highlights (
queries/highlights.scm)structural_assignment operatorhighlight rule.Tests (
test/corpus/structural-directives.txt)structural_expression/structural_declarationnodes to the newmicrosyntax_*node hierarchy.letvariable declarations with and without initializerselse,then,of) with aliasesBreaking Change
Any downstream consumers (syntax highlighting, queries, linters) that reference
structural_expression,structural_declaration, orstructural_assignmentnodes will need to be updated to use the newmicrosyntax_*node names.