Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add Grit target node bindings #2746

Merged
merged 3 commits into from
May 6, 2024

Conversation

arendjr
Copy link
Contributor

@arendjr arendjr commented May 6, 2024

Summary

This adds a few things in relation to Grit node bindings:

  • It adds a GritTargetNode node in addition to the existing GritNode. The main difference is that GritNode wraps GritSyntaxNode, while GritTargetNode is an enum that can wrap nodes for any language we support in the Grit runtime (for now JS only, but other languages will likely follow).
  • Similarly GritTargetToken and GritTargetSyntaxKind were added as well.
  • GritTargetLanguage has been further implemented along the same lines as well. JsTargetLanguage was added so there's a concrete implementation.
  • A JS_GRIT_METAVARIABLE kind has been added to the JavaScript grammar specification. We don't have a parser/lexer for it yet, but this will be the kind to match against for Grit metavariables.

Test Plan

None yet.

@github-actions github-actions bot added A-Project Area: project A-Parser Area: parser A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages labels May 6, 2024
Comment on lines 83 to 89
fn language_name(&self) -> &'static str;

fn snippet_context_strings(&self) -> &[(&'static str, &'static str)];

fn is_comment(&self, node: &GritTargetNode) -> bool;

fn metavariable_kind() -> Self::Kind;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we document the functions? For example, I checked snippet_context_strings and really can't understand what it is.

Comment on lines +511 to +512
// Grit metavariable
"JS_GRIT_METAVARIABLE",
Copy link
Member

@ematipico ematipico May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings about this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some thoughts I don't know if they fit here. If we are to support embedded language formatting in the future, we may also need a "metavaraiable" kind node. For example, in JavaScript (there may be similar concepts in other languages), the embedded language are usually embedded as a template string literal that can optionally hold expression placeholders. When we want to parse and format the template literal, I think we can see those placeholders as metavariables in our internal structure.

const foo = JSON.stringify("bar");
const snippet = js`console.log(${ foo })`; // the "${ foo }" is a placeholder

So I think this kind of node is necessary but I just don't know if we should have GRIT in the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a very insightful comment, @Sec-ant , thanks! There is definitely a parallel between metavariables as used in Grit snippets and embedded expressions inside template literals, even though the syntax is different.

I would be happy to revise this (in a separate PR) if we can reuse these node kinds for that. Definitely something to keep in mind!

Copy link

codspeed-hq bot commented May 6, 2024

CodSpeed Performance Report

Merging #2746 will not alter performance

Comparing arendjr:more-node-bindings (195d13b) with main (62beb76)

Summary

✅ 85 untouched benchmarks

@arendjr arendjr merged commit b9482ec into biomejs:main May 6, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Parser Area: parser A-Project Area: project A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants