refactor: Store a reference to LangProfile in each AstNode #386
No reviewers
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: mergiraf/mergiraf#386
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "wetneb/mergiraf:refactor_lang_profile"
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?
This is the first step towards #5. Keeping track of which language a node comes from will make it possible to store nodes coming from different languages in the same tree, while still being able to look up their commutative parent and signature definitions from the correct language profile.
@ada4a I've tried to make sufficiently granular commits to ease the review, I hope it works for you! I'm curious how much reviewing effort that represents on your side :)
Very nice! Having commits nicely split like this was indeed very helpful.
I didn't have too many things to add this time -- maybe more will come to mind when I take another look at this later
@ -705,0 +712,4 @@
.children
.iter()
.copied()
.filter_map(AstNode::signature)
nice:)
@ -37,6 +37,7 @@ impl<'tree> Matching<'tree> {
/// Is it possible to add this pair while keeping the matching consistent?
pub fn can_be_matched(&self, from: &AstNode<'tree>, to: &AstNode<'tree>) -> bool {
from.grammar_name == to.grammar_name
&& from.lang_profile.name == to.lang_profile.name // TODO rely on a better identifier, as there could be name collisions? Just pointer equality?
I'd say add a test to
supported_langs.rs
that there are no name collisions, and then continue using this comparison, yes.Also it might be a good idea to have a helper for this, something like
LangProfile::eq
(seeIterator::eq
for a precedent), which would initially just comparename
s, but which we'd be free to refactor/improve later, instead of needing to modify all the code everywhereHm, not sure if this should be a
PartialEq
impl (I was thinking of a free-standing method), but since we've decided names are unique identifiers, this is probably okay?@ -829,0 +837,4 @@
let definition = match self {
MergedTree::ExactTree { node, .. }
| MergedTree::MixedTree { node, .. }
| MergedTree::LineBasedMerge { node, .. } => node
The following 3 lines (the ability to highlight multiple lines for a comment is something I always miss from GitLab), are basically
AstNode::signature
, but we can't call that because we have aLeader
instead. Maybe it'd make sense to surface that method toLeader
, like it was done withAstNode::commutative_parent_definition
?Though one might argue that it's less important in this case, since that newly created method would only really be used here, whereas
Leader::commutative_parent_definition
is used in at least 3 placesOTOH adding
Leader::commutative_parent_definition
would remove the only use ofLeader::lang_profile
, so we could be able to remove that at least? But maybe having access to a leader's language profile is helpful in some other occasionsI think the reason the semicolon wasn't added is that
assert!
technically returns()
, so it could be a last expression of a block (or a function, in this case), defining the return type of the latterDo you mind if I leave this open for a bit longer? I'd like to take another look at it this evening
Sure, take your time!