chore: Refactor AstNode
creation #400
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#400
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "wetneb/mergiraf:refactor_AstNode_creation"
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?
The goal of this PR is to integrate the creation and initialization of the tree-sitter parser inside the constructor of the
AstNode
struct.This allows for removing a bunch of duplicate initializations of parsers in various areas of the code.
This is in preparation for #5 where we'll need to intertwine the parsing of multiple languages together, making it impossible to use just one tree-sitter parser to parse a given string.
By doing that we are losing the ability to re-use a parser for parsing multiple strings in a row, but I think it should be okay performance-wise.
@ -86,0 +87,4 @@
let mut parser = Parser::new();
parser
.set_language(&lang_profile.language)
.map_err(|err| format!("Error loading {} grammar: {}", lang_profile.name, err))?;
aside: maybe implement
Display
forLangProfile
by just printing outname
?@ -86,0 +78,4 @@
/// Internal method to parse a string to a tree,
/// without doing the DFS precomputation and starting
/// allocation of node ids at the supplied counter.
fn parse_root(
I.. don't know how much sense it makes to have this as a separate method? If you inline it into
Ast::parse
and reorder the lines a bit, you end up with a pretty logical arrangement imo:It's for #5, when we'll need to parse multiple roots with the same id counter. I can delay the introduction of the method if you prefer… maybe a sign that I'm making too small PRs?
I see!
No no, don't bother – it's just that I was genuinely unable to understand the reasoning behind having this method based on the desciption of this PR alone
I suspect you already have a long-ish list of commits, which you're now batching into these PRs.
Maybe try to _over_estimate the number of commits per PR? I'll probably be able to tell if it becomes too much, in which case we can move some of the commits over to the next PR.
One other way to solve this could be for you to upload the branch where you're working on this all, so that I could peek a bit into the future and ask you to pull some commits from there into the PR; but I understand if you don't really want to do that.
sure, it's here: https://codeberg.org/wetneb/mergiraf/src/branch/5-nested-languages
@ -38,4 +36,0 @@
parser
.set_language(&lang_profile.language)
.unwrap_or_else(|_| panic!("Error loading {} grammar", lang_profile.name));
debug!("initializing the parser took {:?}", start.elapsed());
might consider moving the timing thing into
AstNode::parse
-- or maybe not, given that this is the only place of parser initialization that had ityeah probably a bad idea, since it will end up being printed three times for the places where we parse all three sides
I don't know, I'd also be fine with that, but also fine with the current state… up to you!
As far as I can see, the timers are only really placed in the functions closer to the outer API, like
line_merge_and_structured_resolution
. And I'd sayAstNode::parse
is a bit more low-level than that, so let's not bother...@ -58,2 +50,3 @@
let tree_left = parse(&mut parser, contents_left, lang_profile, &arena, &ref_arena);
let tree_base = AstNode::parse(contents_base, lang_profile, &arena, &ref_arena);
let tree_left = AstNode::parse(contents_left, lang_profile, &arena, &ref_arena);
#[rustfmt::skip]
this is no longer necessary now!
well spotted!