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

Add GritQL grammar #1951

Merged
merged 8 commits into from
Mar 7, 2024
Merged

Add GritQL grammar #1951

merged 8 commits into from
Mar 7, 2024

Conversation

arendjr
Copy link
Contributor

@arendjr arendjr commented Mar 1, 2024

Summary

This implements the GritQL grammar based on my original (oversized) PR: #1922

This is just the grammar and the grit_kinds_src.rs along with the accompanying generated files and the minimal set of changes to make everything compile again. The actual parser will follow in the next PR.

Test Plan

CI should remain green.

@arendjr arendjr requested a review from a team as a code owner March 1, 2024 17:09
Copy link

netlify bot commented Mar 1, 2024

Deploy Preview for biomejs ready!

Name Link
🔨 Latest commit b78c4ff
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/65e8d530a5ed830008f7b017
😎 Deploy Preview https://deploy-preview-1951--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 (🔴 down 1 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.

@github-actions github-actions bot added A-Tooling Area: internal tools A-Website Area: website labels Mar 1, 2024
Copy link

codspeed-hq bot commented Mar 1, 2024

CodSpeed Performance Report

Merging #1951 will not alter performance

Comparing arendjr:gritql-grammar (b78c4ff) with main (465df11)

Summary

✅ 93 untouched benchmarks

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.

I skimmed the grammar, and I found some inconsistencies and errors that should be addressed before merging.

  • comments with example: they are important for the review and provide context
  • bogus nodes: I noticed that there's some misuse of the bogus nodes. Usually they are always part of a Any* node, and they are never part of the definition of a specific node
  • naming: all nodes must start with Grit* unless they are known nodes
  • inconsistencies: some nodes are defined like Node = 'literal', which isn't a pattern we use throughout our grammars
  • lists: they should always be NOT optional

xtask/codegen/gritql.ungram Outdated Show resolved Hide resolved
xtask/codegen/gritql.ungram Outdated Show resolved Hide resolved
xtask/codegen/gritql.ungram Outdated Show resolved Hide resolved
'language'
name: GritLanguageName
flavor: GritLanguageFlavor?
GritBogus?
Copy link
Member

Choose a reason for hiding this comment

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

A bogus should not be in this position. Usually bogus nodes are part of a Any** node.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It helped me to implement patterns such as this in the parser:

let _ = parse_pattern(p).or_recover_with_token_set(
    p,
    &ParseRecoveryTokenSet::new(GRIT_BOGUS_PATTERN, PATTERN_RECOVERY_SET),
    expected_pattern,
);

Without this, it appeared as though the bogus nodes wouldn't automatically "bubble up" to the next Any** node. I suppose that might simply be because I had made some other mistake, what steps do I need to follow to make sure the Any* nodes can consume these?

Copy link
Member

@ematipico ematipico Mar 5, 2024

Choose a reason for hiding this comment

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

There aren't any particular steps to follow, really - other than the fact that a bogus node must be part of a Any* node. The recovering logic is up to us entirely, and we decide what to wrap in bogus node. We just make judgement calls based on the DX we want to offers to our tools (formatter, linter, etc.).

By looking at the snippet of the parser, I would expect a grammar like this:

GritNode =
	some_node: GritSomeNode
	pattern: AnyGritPattern

AnyGritPattern =
	GritBogusPattern
	GritSpecificPattern

This means when you're parsing the pattern node, you have to account any possible errors, and make sure the parser is able to recover itself and emit a GRIT_BOGUS_PATTERN.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, maybe I was just trying to do the recovery in the wrong node then.

Copy link
Member

Choose a reason for hiding this comment

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

If you have questions, @denbezrukov is an expert in the field :)

xtask/codegen/gritql.ungram Show resolved Hide resolved
xtask/codegen/gritql.ungram Show resolved Hide resolved
xtask/codegen/gritql.ungram Outdated Show resolved Hide resolved
xtask/codegen/gritql.ungram Outdated Show resolved Hide resolved
xtask/codegen/gritql.ungram Outdated Show resolved Hide resolved
xtask/codegen/gritql.ungram Outdated Show resolved Hide resolved
@github-actions github-actions bot added A-Parser Area: parser L-JSON Language: JSON and super languages and removed A-Website Area: website labels Mar 5, 2024
@arendjr arendjr requested a review from ematipico March 5, 2024 19:27
@arendjr
Copy link
Contributor Author

arendjr commented Mar 5, 2024

Think I've processed them all :)

@arendjr
Copy link
Contributor Author

arendjr commented Mar 5, 2024

Is the unused dependency lint safe to ignore in this case? Or how would I ignore it until the parser PR is ready?

@ematipico
Copy link
Member

Is the unused dependency lint safe to ignore in this case? Or how would I ignore it until the parser PR is ready?

Something didn't go as expected, I advise you to check why to check what is causing the warning. When I created the HTML grammar, I didn't get any warning. Unless there's something more that I missed

@arendjr
Copy link
Contributor Author

arendjr commented Mar 6, 2024

Thanks! I misread the warning about the unused dependencies. I thought it complained because biome_grit_syntax was unused, but it was because biome_grit_syntax listed some dependencies it didn't use.

@arendjr arendjr merged commit d064dcd into biomejs:main Mar 7, 2024
18 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-Tooling Area: internal tools L-JSON Language: JSON and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants