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
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bindings/node/gts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bindings/node/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 34 additions & 3 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ module.exports = function defineGrammar(dialect) {
]).concat(
dialect === 'typescript' ? [
[$.primary_type, $.type_parameter],
] : [
] : dialect === 'tsx' ? [
[$.jsx_opening_element, $.type_parameter],
[$.jsx_namespace_name, $.primary_type],
],
] : dialect === 'gts' ? [
[$.glimmer_template, $.primary_type, $.type_parameter],
] : [],
),

inline: ($, previous) => previous
Expand Down Expand Up @@ -215,22 +217,50 @@ module.exports = function defineGrammar(dialect) {
$.satisfies_expression,
$.instantiation_expression,
$.internal_module,
$.glimmer_template,
];

if (dialect === 'typescript') {
choices.push($.type_assertion);
choices.push(...previous.members.filter((member) => {
return member.name !== '_jsx_element' && member.name !== 'glimmer_template';
},
));
} else if (dialect === 'gts') {
choices.push($.type_assertion);
choices.push(...previous.members.filter((member) =>
member.name !== '_jsx_element',
));
} else if (dialect === 'tsx') {
choices.push(...previous.members);
choices.push(...previous.members.filter(member => {
return member.name !== 'glimmer_template';
}));
} 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?

// glimmer_template: $ => choice(
// seq(
// field('open_tag', $.glimmer_opening_tag),
// field('content', repeat($._glimmer_template_content)),
// field('close_tag', $.glimmer_closing_tag),
// ),
// // empty template has no content
// // <template></template>
// seq(
// field('open_tag', $.glimmer_opening_tag),
// field('close_tag', $.glimmer_closing_tag),
// ),
// ),
//
// _glimmer_template_content: _ => /.{1,}/,
// glimmer_opening_tag: _ => '<template>',
// glimmer_closing_tag: _ => '</template>',

_jsx_start_opening_element: $ => seq(
'<',
optional(
Expand Down Expand Up @@ -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

seq(
repeat(field('decorator', $.decorator)),
$.method_definition,
Expand Down
3 changes: 3 additions & 0 deletions gts/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions gts/grammar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const defineGrammar = require('../common/define-grammar');

module.exports = defineGrammar('gts');
3 changes: 3 additions & 0 deletions gts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "../bindings/node/gts"
}
Loading
Loading