Skip to content

Commit

Permalink
get it nearly working
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Nov 30, 2024
1 parent 62c0d3c commit 719c93e
Show file tree
Hide file tree
Showing 4 changed files with 111,800 additions and 61,679 deletions.
67 changes: 31 additions & 36 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,43 @@ module.exports = grammar({
],

reserved: {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
global: $ => [
'break',
'case',
'catch',
'class',
'const',
'continue',
'debugger',
'default',
'delete',
'do',
'else',
'export',
'extends',
'false',
'finally',
'for',
'function',
'if',
'let',
'import',
'in',
'instanceof',
'new',
'null',
'return',
'super',
'switch',
'this',
'throw',
'true',
'try',
'typeof',
'var',
'void',
'while',
'with',
],
properties: $ => [],
},
Expand All @@ -62,7 +86,6 @@ module.exports = grammar({
$._expressions,
$._semicolon,
$._identifier,
$._reserved_identifier,
$._jsx_attribute,
$._jsx_element_name,
$._jsx_child,
Expand Down Expand Up @@ -108,9 +131,6 @@ module.exports = grammar({

conflicts: $ => [
[$.primary_expression, $._property_name],
[$.primary_expression, $._property_name, $.arrow_function],
[$.primary_expression, $.arrow_function],
[$.primary_expression, $.method_definition],
[$.primary_expression, $.rest_pattern],
[$.primary_expression, $.pattern],
[$.primary_expression, $._for_header],
Expand All @@ -122,7 +142,6 @@ module.exports = grammar({
[$.labeled_statement, $._property_name],
[$.computed_property_name, $.array],
[$.binary_expression, $._initializer],
[$.class_static_block, $._property_name],
],

word: $ => $.identifier,
Expand Down Expand Up @@ -191,6 +210,7 @@ module.exports = grammar({
_module_export_name: $ => choice(
$.identifier,
$.string,
'default',
),

declaration: $ => choice(
Expand Down Expand Up @@ -443,7 +463,7 @@ module.exports = grammar({
empty_statement: _ => ';',

labeled_statement: $ => prec.dynamic(-1, seq(
field('label', alias(choice($.identifier, $._reserved_identifier), $.statement_identifier)),
field('label', alias($.identifier, $.statement_identifier)),
':',
field('body', $.statement),
)),
Expand Down Expand Up @@ -515,7 +535,6 @@ module.exports = grammar({
$.member_expression,
$.parenthesized_expression,
$._identifier,
alias($._reserved_identifier, $.identifier),
$.this,
$.super,
$.number,
Expand Down Expand Up @@ -548,10 +567,7 @@ module.exports = grammar({
$.pair,
$.spread_element,
$.method_definition,
alias(
choice($.identifier, $._reserved_identifier),
$.shorthand_property_identifier,
),
alias($.identifier, $.shorthand_property_identifier),
))),
'}',
)),
Expand All @@ -562,10 +578,7 @@ module.exports = grammar({
$.pair_pattern,
$.rest_pattern,
$.object_assignment_pattern,
alias(
choice($.identifier, $._reserved_identifier),
$.shorthand_property_identifier_pattern,
),
alias($.identifier, $.shorthand_property_identifier_pattern),
))),
'}',
)),
Expand All @@ -579,10 +592,7 @@ module.exports = grammar({
object_assignment_pattern: $ => seq(
field('left', choice(
$._destructuring_pattern,
alias(
choice($._reserved_identifier, $.identifier),
$.shorthand_property_identifier_pattern,
),
alias($.identifier, $.shorthand_property_identifier_pattern),
)),
'=',
field('right', $.expression),
Expand Down Expand Up @@ -784,7 +794,6 @@ module.exports = grammar({
optional('async'),
choice(
field('parameter', choice(
alias($._reserved_identifier, $.identifier),
$.identifier,
)),
$._call_signature,
Expand Down Expand Up @@ -847,7 +856,6 @@ module.exports = grammar({
$.member_expression,
$.subscript_expression,
$._identifier,
alias($._reserved_identifier, $.identifier),
$._destructuring_pattern,
),

Expand All @@ -860,7 +868,6 @@ module.exports = grammar({
_augmented_assignment_lhs: $ => choice(
$.member_expression,
$.subscript_expression,
alias($._reserved_identifier, $.identifier),
$.identifier,
$.parenthesized_expression,
),
Expand Down Expand Up @@ -1218,10 +1225,7 @@ module.exports = grammar({
),

_property_name: $ => reserved('properties', choice(
alias(choice(
$.identifier,
$._reserved_identifier,
), $.property_identifier),
alias($.identifier, $.property_identifier),
$.private_property_identifier,
$.string,
$.number,
Expand All @@ -1234,15 +1238,6 @@ module.exports = grammar({
']',
),

_reserved_identifier: _ => choice(
'get',
'set',
'async',
'static',
'export',
'let',
),

_semicolon: $ => choice($._automatic_semicolon, ';'),
},
});
Expand Down
Loading

0 comments on commit 719c93e

Please sign in to comment.