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

Implement graphql grammar #1949

Merged
merged 11 commits into from
Mar 27, 2024
Merged

Conversation

vohoanglong0107
Copy link
Contributor

@vohoanglong0107 vohoanglong0107 commented Mar 1, 2024

Summary

Add the graphql grammar.

Part of #1927

Test Plan

It could be compiled.

@github-actions github-actions bot added the A-Tooling Area: internal tools label Mar 1, 2024
Copy link

netlify bot commented Mar 1, 2024

Deploy Preview for biomejs ready!

Name Link
🔨 Latest commit 8157aff
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/65ffed0d4afd460008df2ddd
😎 Deploy Preview https://deploy-preview-1949--biomejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 4 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 93 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codspeed-hq bot commented Mar 1, 2024

CodSpeed Performance Report

Merging #1949 will degrade performances by 8.48%

Comparing vohoanglong0107:feat-graphql (8157aff) with main (2edcd59)

Summary

❌ 1 regressions
✅ 92 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main vohoanglong0107:feat-graphql Change
db.json[cached] 66.7 ms 72.9 ms -8.48%

@vohoanglong0107 vohoanglong0107 force-pushed the feat-graphql branch 5 times, most recently from 492a3e3 to a51d604 Compare March 18, 2024 10:58
@vohoanglong0107 vohoanglong0107 changed the title Implement graphql parser Implement graphql syntax Mar 18, 2024
@vohoanglong0107 vohoanglong0107 changed the title Implement graphql syntax Implement graphql grammar Mar 18, 2024
@vohoanglong0107 vohoanglong0107 marked this pull request as ready for review March 19, 2024 08:39
@vohoanglong0107 vohoanglong0107 mentioned this pull request Mar 19, 2024
3 tasks
Copy link
Member

@ematipico ematipico left a 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.

Comment on lines 17 to 18
schemars = { version = "0.8.10", optional = true }
serde = { version = "1.0.136", features = ["derive"], optional = true }
Copy link
Member

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 =
Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

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.

Copy link
Contributor Author

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",
Copy link
Member

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?

Copy link
Contributor Author

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

@@ -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_"
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor

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.

@vohoanglong0107
Copy link
Contributor Author

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?

@ematipico
Copy link
Member

We can add bogus nodes in another PR if you want, although that needs to be addressed. :)

@ematipico
Copy link
Member

Heads up @vohoanglong0107, I pushed a commit to update few files.

knope.toml Outdated Show resolved Hide resolved
Co-authored-by: unvalley <38400669+unvalley@users.noreply.github.com>
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Great work @vohoanglong0107 !

@ematipico ematipico merged commit 7bf1861 into biomejs:main Mar 27, 2024
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Tooling Area: internal tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants