Support for nested languages #5
Labels
No labels
Compat/Breaking
Kind
Bad merge
Kind
Bug
Kind
Documentation
Kind
Enhancement
Kind
Feature
Kind
New language
Kind
Security
Kind
Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: mergiraf/mergiraf#5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
It is common for HTML documents to contain embedded CSS or JS.
It would be nice if Mergiraf could use different language profiles for each part of the document, so that it's able to resolve Javascript conflicts with language-awareness even if they are embedded in an HTML document.
I've been considering an implementation strategy for this. Tree-sitter parsers already come with an injections query which defines which nodes of the language contain foreign content that can be parsed in another language (and how to identify that language). It feels natural to reuse this existing functionality.
My goal would be to represent the nested trees directly at the parsing stage (when creating the
AstNode
s) and then keep the matching and merging heuristics untouched. The only places where our merging heuristics are language-dependent are the dependencies on commutative parents and signatures, which are defined in theLangProfile
.Here's a proposal:
AstNode
pointing to theLangProfile
from which the node came. It has a slight memory footprint cost, as we're adding a pointer to all nodes, but I think we can afford it.LangProfile
parameters from methods, so that they access it from the nodes they work on instead. From my initial investigation, this seems to bring quite a nice simplification in a lot of places.AstNode
s, run the injections query associated with the tree-sitter language to check for nodes that contain content parseable in another language. When the query matches, look up the language in our own supported languages by name, and if there is a match, recursively parse the contents with the language and include the results as children of the outer tree.With this, we should already have basic support for nested languages.
AstNode
creation #400AstNode
creation #400AstNode
creation #400