Skip to content

Commit

Permalink
public field and class body work as is, but need to be converted to n…
Browse files Browse the repository at this point in the history
…ew grammar which is commented out
  • Loading branch information
ilevyor committed Mar 22, 2024
1 parent 07c9415 commit c25a571
Show file tree
Hide file tree
Showing 22 changed files with 620,839 additions and 666,213 deletions.
Binary file modified crates/wasm-bindings/wasm_parsers/tree-sitter-tsx.wasm
Binary file not shown.
Binary file modified crates/wasm-bindings/wasm_parsers/tree-sitter-typescript.wasm
Binary file not shown.
12 changes: 6 additions & 6 deletions resources/edit_grammars.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ async function buildLanguage(language) {
await execPromise(
`cd ${tsLangDir} && yarn && yarn build && echo "Generated grammar for ${language}"`,
);
await Promise.all([
execPromise(`cd ${tsLangDir}/tsx && npx tree-sitter build-wasm`),
execPromise(`cd ${tsLangDir}/typescript && npx tree-sitter build-wasm`),
]);
// await Promise.all([
// execPromise(`cd ${tsLangDir}/tsx && npx tree-sitter build-wasm`),
// execPromise(`cd ${tsLangDir}/typescript && npx tree-sitter build-wasm`),
// ]);

await copyNodeTypes('typescript/typescript', 'typescript');
await copyNodeTypes('typescript/tsx', 'tsx');

await copyWasmParser('typescript', 'tree-sitter-typescript/');
await copyWasmParser('tsx', 'tree-sitter-typescript/');
// await copyWasmParser('typescript', 'tree-sitter-typescript/');
// await copyWasmParser('tsx', 'tree-sitter-typescript/');
} else if (language === 'vue') {
log(`Copying files`);
await fs.copyFile(
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,26 @@ $(OBJS): GYP_OBJCXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_

# Suffix rules, putting all outputs into $(obj).

$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.c FORCE_DO_CMD
@$(call do_cmd,cc,1)

$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD
@$(call do_cmd,cxx,1)

# Try building from generated source, too.

$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD
$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.c FORCE_DO_CMD
@$(call do_cmd,cc,1)

# Try building from generated source, too.

$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD
@$(call do_cmd,cxx,1)

$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD
$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD
@$(call do_cmd,cc,1)

$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.cc FORCE_DO_CMD
@$(call do_cmd,cxx,1)

$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD
@$(call do_cmd,cc,1)

# End of this set of suffix rules
### Rules for final target.
LDFLAGS_Debug := \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,41 @@ module.exports = function defineGrammar(dialect) {
]),

rules: {
public_field_definition: ($) => seq(
repeat(field('decorator', $.decorator)),
optional(choice(
seq('declare', optional($.accessibility_modifier)),
seq($.accessibility_modifier, optional('declare')),
)),
choice(
seq(field('static', optional($.static)), optional($.override_modifier), optional('readonly')),
seq(optional('abstract'), optional('readonly')),
seq(optional('readonly'), optional('abstract')),
public_field_definition: ($) =>
seq(
optional('declare'),
optional($.accessibility_modifier),
choice(
seq(
field('static', optional($.static)),
optional($.override_modifier),
optional('readonly'),
),
seq(optional('abstract'), optional('readonly')),
seq(optional('readonly'), optional('abstract')),
),
field('name', $._property_name),
optional(choice('?', '!')),
field('type', optional($.type_annotation)),
optional($._initializer),
),
field('name', $._property_name),
optional(choice('?', '!')),
field('type', optional($.type_annotation)),
optional($._initializer),
),

// public_field_definition: ($) => seq(
// repeat(field('decorator', $.decorator)),
// optional(choice(
// seq('declare', optional($.accessibility_modifier)),
// seq($.accessibility_modifier, optional('declare')),
// )),
// choice(
// seq(field('static', optional($.static)), optional($.override_modifier), optional('readonly')),
// seq(optional('abstract'), optional('readonly')),
// seq(optional('readonly'), optional('abstract')),
// ),
// field('name', $._property_name),
// optional(choice('?', '!')),
// field('type', optional($.type_annotation)),
// optional($._initializer),
// ),

// override original catch_clause, add optional type annotation
catch_clause: ($) => seq(
Expand Down Expand Up @@ -388,39 +407,73 @@ module.exports = function defineGrammar(dialect) {
choice($._semicolon, $._function_signature_automatic_semicolon),
),

class_body: ($) => seq(
'{',
repeat(choice(
seq(
repeat(field('decorator', $.decorator)),
field('member', $.method_definition),
optional($._semicolon),
),
// As it happens for functions, the semicolon insertion should not
// happen if a block follows the closing paren, because then it's a
// *definition*, not a declaration. Example:
// public foo()
// { <--- this brace made the method signature become a definition
// }
// The same rule applies for functions and that's why we use
// "_function_signature_automatic_semicolon".
seq(field('member', $.method_signature), choice($._function_signature_automatic_semicolon, ',')),
field('member', $.class_static_block),
seq(
field('member',
class_body: ($) =>
seq(
'{',
field(
'members',
repeat(
choice(
$.abstract_method_signature,
$.index_signature,
$.method_signature,
$.public_field_definition,
$.decorator,
seq($.method_definition, optional($._semicolon)),
// As it happens for functions, the semicolon insertion should not
// happen if a block follows the closing paren, because then it's a
// *definition*, not a declaration. Example:
// public foo()
// { <--- this brace made the method signature become a definition
// }
// The same rule applies for functions and that's why we use
// "_function_signature_automatic_semicolon".
seq($.method_signature, choice($._function_signature_automatic_semicolon, ',')),
$.class_static_block,
seq(
choice(
$.abstract_method_signature,
$.index_signature,
$.method_signature,
$.public_field_definition,
),
choice($._semicolon, ','),
),
),
),
choice($._semicolon, ','),
),
';',
)),
'}',
),
'}',
),

// class_body: ($) => seq(
// '{',
// repeat(choice(
// seq(
// repeat(field('decorator', $.decorator)),
// field('member', $.method_definition),
// optional($._semicolon),
// ),
// // As it happens for functions, the semicolon insertion should not
// // happen if a block follows the closing paren, because then it's a
// // *definition*, not a declaration. Example:
// // public foo()
// // { <--- this brace made the method signature become a definition
// // }
// // The same rule applies for functions and that's why we use
// // "_function_signature_automatic_semicolon".
// seq(field('member', $.method_signature), choice($._function_signature_automatic_semicolon, ',')),
// field('member', $.class_static_block),
// seq(
// field('member',
// choice(
// $.abstract_method_signature,
// $.index_signature,
// $.method_signature,
// $.public_field_definition,
// ),
// ),
// choice($._semicolon, ','),
// ),
// ';',
// )),
// '}',
// ),

method_definition: ($) => prec.left(seq(
optional($.accessibility_modifier),
Expand Down

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

Binary file not shown.
Loading

0 comments on commit c25a571

Please sign in to comment.