-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
Implement graphql grammar #1949
Conversation
✅ Deploy Preview for biomejs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
CodSpeed Performance ReportMerging #1949 will degrade performances by 8.48%Comparing Summary
Benchmarks breakdown
|
4ef42ab
to
da7dd60
Compare
492a3e3
to
a51d604
Compare
a51d604
to
c6f0f00
Compare
c6f0f00
to
55875bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @vohoanglong0107 for taking charge of this task. I left some comments.
The PR/grammar doesn't take into account any error recovery strategy. Is it on purpose? Do you plan to address it later? Here's some piece of documentation that should help: https://biomejs.dev/internals/architecture/#parser-and-cst
I plan to add more documentation on the subject, but it would nice to understand what you plan to do about it.
schemars = { version = "0.8.10", optional = true } | ||
serde = { version = "1.0.136", features = ["derive"], optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use workspace = true
instead of using the the version
|
||
GraphqlDefinitionList = AnyGraphqlDefinition* | ||
|
||
AnyGraphqlDefinition = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you define an Any*
among the variants, you usually want to have a Bogus
node. This isn't valid for each variant, but top-level variants should usually a bogus node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things that we should look after:
- Mixed tabs and spaces. Let's fix that and use only tabs (you can ignore the legend).
- Documentation: take a look at the other grammars, and you will notice how we try to document each node by writing an example of code, and highlighting the part of the code the node covers. This is very important to the project because we want other developers to understand your code quickly, especially if someone doesn't know the grammar. Please make sure to address that.
/// Returns `true` for any contextual (await) or non-contextual keyword | ||
#[inline] | ||
pub const fn is_keyword(self) -> bool { | ||
(self as u16) <= (GraphqlSyntaxKind::I_N_P_U_T_F_I_E_L_D_D_E_F_I_N_I_T_I_O_N_KW as u16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this is... but I_N_P_U_T_F_I_E_L_D_D_E_F_I_N_I_T_I_O_N_KW
seems wrong to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is the result of trying to differentiate between uppercase and lowercase keyword 😅
@@ -679,6 +679,7 @@ impl Field { | |||
("||", _) => "logical_or", | |||
("&&", _) => "logical_and", | |||
("$=", _) => "suffix", | |||
("$", LanguageKind::Graphql) => "dollar", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Graphql use $ for parameter, and without this there will be an invalid $_token
xtask/codegen/src/generate_nodes.rs
Outdated
@@ -976,7 +978,21 @@ pub(crate) fn token_kind_to_code(name: &str, language_kind: LanguageKind) -> Tok | |||
} else if kind_source.keywords.contains(&name) { | |||
// we need to replace "-" with "_" for the keywords | |||
// e.g. we have `color-profile` in css but it's an invalid ident in rust code | |||
let token: TokenStream = name.replace('-', "_").parse().unwrap(); | |||
// also mark uppercase differently from lowercase | |||
// e.g. "query" => "QUERY", "QUERY" => "Q_U_E_R_Y_" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to mark upper-case keywords differently?
If so, is there a better way to tag them instead of using all underscores? Maybe with a postfix or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Graphql have both uppercase (QUERY
) and lowercase keyword (query
) so I want to have a way to differentiate them. I don't know what is the best way to do this, maybe adding a postfix if all the letters are uppercase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Graphql have both uppercase (
QUERY
) and lowercase keyword (query
) so I want to have a way to differentiate them. I don't know what is the best way to do this, maybe adding a postfix if all the letters are uppercase?
I think this could help the readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest QUERY_KW
vs UPPER_QUERY_KW
.
I didn't know about the error recovery strategy (especially about those bogus nodes 😅), so if you prefer I will include it in this PR. According to the linked docs, I should only need to add those bogus nodes in this PR right? |
We can add bogus nodes in another PR if you want, although that needs to be addressed. :) |
b66eda4
to
a653337
Compare
Heads up @vohoanglong0107, I pushed a commit to update few files. |
Co-authored-by: unvalley <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @vohoanglong0107 !
Summary
Add the graphql grammar.
Part of #1927
Test Plan
It could be compiled.