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

GTS Dialect #308

Closed
wants to merge 4 commits into from
Closed

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Aug 7, 2024

Resolves #307

wip -- not ready for review

} else {
throw new Error(`Unknown dialect ${dialect}`);
}

return choice(...choices);
},

// This rule is only referenced by expression when the dialect is 'gts'
Copy link
Contributor Author

@NullVoxPopuli NullVoxPopuli Aug 7, 2024

Choose a reason for hiding this comment

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

this would be provided by tree-sitter-javascript, yea?

@@ -419,6 +449,7 @@ module.exports = function defineGrammar(dialect) {
class_body: $ => seq(
'{',
repeat(choice(
field('template', $.glimmer_template),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

only one of these may be present within the class_body


----

(program
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is wrong, but I haven't gotten to the point where I can run the tests with the gts language yet, because I haven't been able to build them yet

@amaanq
Copy link
Member

amaanq commented Aug 16, 2024

I appreciate the PR, but this should really be its own grammar that extends typescript, and not built into this one. (See how C++ extends C)

@amaanq amaanq closed this Aug 16, 2024
@NullVoxPopuli
Copy link
Contributor Author

Should that then also be true of tsx?

@amaanq
Copy link
Member

amaanq commented Aug 16, 2024

No, since TSX isn't an extension (in the same manner that GTS is) of Typescript, and users of one dialect will oftentimes want to be using both.

@NullVoxPopuli
Copy link
Contributor Author

Theyre Both implemented upstream in tree-sitter-glimmer.

The glimmer_* nodes were implemented here: https://github.com/tree-sitter/tree-sitter-javascript/pull/208/files#diff-919ac210accac9ecc55a76d10a7590e3d85ca3f0e165b52d30f08faee486d0cbr547

And right now, it seems those nodes are deprioritized / covered up by generic-type tokens.

If the conflict were resolved, we wouldn't even need a dialect - no extra grammar either.

Maybe this is the path i take in tree-sitter-typescript? Find the conflict and fix it?

@amaanq
Copy link
Member

amaanq commented Aug 17, 2024

FWIW, I totally disagree with glimmer being added in JavaScript, but that PR predates my involvement (and I'm not even sure why that was merged, but it wasn't by Max). I would rather remove glimmer support from JS/TS since IMO, it should be built on top of the languages in a GJS/GTS grammar - adding support just sets the precedence that any framework can be added, which doesn't make sense

@NullVoxPopuli
Copy link
Contributor Author

As does jsx.

In any case, is the strategy to do as tree-sitter-typescript does, and extend tree-sitter-javascript?

Originally, Adding glimmer to JavaScript makes more sense to me, because it's just one ast node. As injection query takes it from there in tree-sitter-glimmer, and the precedence is jsx -- albeit, waaaaay less invasive than jsx (as jsx has to interveve it's syntax in and out of regular JavaScript recursively -- and this is not the case for the one glimmer_template node).

@amaanq
Copy link
Member

amaanq commented Aug 17, 2024

In any case, is the strategy to do as tree-sitter-typescript does, and extend tree-sitter-javascript?

Yeah, this is how you should do it (for glimmer JS and TS)

As does jsx.

But JSX is valid in Javascript (.js) files, and is very tightly coupled to the ecosystem, unlike Glimmer. "Just one ast node" is not a compelling argument to support any third party framework

@NullVoxPopuli
Copy link
Contributor Author

But JSX is valid in Javascript (.js) files

This is surprising to me, and it feels like someone made a mistake 🙈

Yeah, this is how you should do it (for glimmer JS and TS)

Thank you!

@amaanq
Copy link
Member

amaanq commented Aug 17, 2024

No problem 🙂 do you mind letting me know when you have those grammars ready, and then we can remove it from the JavaScript grammar itself? It'd be a breaking change technically, but as long as there's a viable alternative that's fine for us then.

@NullVoxPopuli
Copy link
Contributor Author

Will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: how can I PR an extension like tsx, but for another superset language?
2 participants