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

Misc bug fixes #288

Merged
merged 16 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 25 additions & 30 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ module.exports = grammar({
$._automatic_semicolon,
$._template_chars,
$._ternary_qmark,
$.html_comment,
'||',
// We use escape sequence to tell the scanner if we're currently inside a string or template string, in which case
// it should NOT parse html comments.
$.escape_sequence,
],

extras: $ => [
$.comment,
$.html_comment,
/[\s\p{Zs}\uFEFF\u2028\u2029\u2060\u200B]/,
],

Expand Down Expand Up @@ -78,6 +84,7 @@ module.exports = grammar({
[$.primary_expression, $.statement_block, 'object'],
[$.import_statement, $.import],
[$.export_statement, $.primary_expression],
[$.lexical_declaration, $.primary_expression],
],

conflicts: $ => [
Expand Down Expand Up @@ -494,10 +501,9 @@ module.exports = grammar({
$.true,
$.false,
$.null,
$.import,
$.object,
$.array,
$.function,
$.function_expression,
$.arrow_function,
$.generator_function,
$.class,
Expand Down Expand Up @@ -701,7 +707,7 @@ module.exports = grammar({

class_heritage: $ => seq('extends', $.expression),

function: $ => prec('literal', seq(
function_expression: $ => prec('literal', seq(
optional('async'),
'function',
field('name', optional($.identifier)),
Expand Down Expand Up @@ -761,7 +767,7 @@ module.exports = grammar({

call_expression: $ => choice(
prec('call', seq(
field('function', $.expression),
field('function', choice($.expression, $.import)),
field('arguments', choice($.arguments, $.template_string)),
)),
prec('member', seq(
Expand All @@ -783,7 +789,7 @@ module.exports = grammar({
)),

member_expression: $ => prec('member', seq(
field('object', choice($.expression, $.primary_expression)),
field('object', choice($.expression, $.primary_expression, $.import)),
choice('.', field('optional_chain', $.optional_chain)),
field('property', choice(
$.private_property_identifier,
Expand Down Expand Up @@ -897,11 +903,7 @@ module.exports = grammar({
),
)),

sequence_expression: $ => seq(
field('left', $.expression),
',',
field('right', choice($.sequence_expression, $.expression)),
),
sequence_expression: $ => prec.right(commaSep1($.expression)),

//
// Primitives
Expand Down Expand Up @@ -953,30 +955,21 @@ module.exports = grammar({
)),

// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
comment: _ => token(choice(
seq('//', /.*/),
seq(
'/*',
/[^*]*\*+([^/*][^*]*\*+)*/,
'/',
),
// https://tc39.es/ecma262/#sec-html-like-comments
seq('<!--', /.*/),
amaanq marked this conversation as resolved.
Show resolved Hide resolved
// This allows code to exist before this token on the same line.
//
// Technically, --> is supposed to have nothing before it on the same line
// except for comments and whitespace, but that is difficult to express,
// and in general tree sitter grammars tend to prefer to be overly
// permissive anyway.
//
// This approach does not appear to cause problems in practice.
seq('-->', /.*/),
)),
comment: $ => choice(
token(choice(
seq('//', /.*/),
seq(
'/*',
/[^*]*\*+([^/*][^*]*\*+)*/,
'/',
),
)),
),

template_string: $ => seq(
'`',
repeat(choice(
$._template_chars,
alias($._template_chars, $.string_fragment),
$.escape_sequence,
$.template_substitution,
)),
Expand Down Expand Up @@ -1128,6 +1121,7 @@ module.exports = grammar({
seq(field('member', $.field_definition), $._semicolon),
field('member', $.class_static_block),
field('template', $.glimmer_template),
';',
)),
'}',
),
Expand Down Expand Up @@ -1211,6 +1205,7 @@ module.exports = grammar({
'async',
'static',
'export',
'let',
),

_semicolon: $ => choice($._automatic_semicolon, ';'),
Expand Down
10 changes: 5 additions & 5 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
; Function and method definitions
;--------------------------------

(function
(function_expression
name: (identifier) @function)
(function_declaration
name: (identifier) @function)
Expand All @@ -32,20 +32,20 @@

(pair
key: (property_identifier) @function.method
value: [(function) (arrow_function)])
value: [(function_expression) (arrow_function)])

(assignment_expression
left: (member_expression
property: (property_identifier) @function.method)
right: [(function) (arrow_function)])
right: [(function_expression) (arrow_function)])

(variable_declarator
name: (identifier) @function
value: [(function) (arrow_function)])
value: [(function_expression) (arrow_function)])

(assignment_expression
left: (identifier) @function
right: [(function) (arrow_function)])
right: [(function_expression) (arrow_function)])

; Function and method calls
;--------------------------
Expand Down
2 changes: 1 addition & 1 deletion queries/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(member_expression
property: (property_identifier) @injection.language)
]
arguments: (template_string) @injection.content)
arguments: (template_string (string_fragment) @injection.content))

; Parse regex syntax within regex literals

Expand Down
2 changes: 1 addition & 1 deletion queries/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[
(statement_block)
(function)
(function_expression)
(arrow_function)
(function_declaration)
(method_definition)
Expand Down
12 changes: 6 additions & 6 deletions queries/tags.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
(comment)* @doc
.
[
(function
(function_expression
name: (identifier) @name)
(function_declaration
name: (identifier) @name)
Expand All @@ -44,7 +44,7 @@
(lexical_declaration
(variable_declarator
name: (identifier) @name
value: [(arrow_function) (function)]) @definition.function)
value: [(arrow_function) (function_expression)]) @definition.function)
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
(#select-adjacent! @doc @definition.function)
)
Expand All @@ -55,7 +55,7 @@
(variable_declaration
(variable_declarator
name: (identifier) @name
value: [(arrow_function) (function)]) @definition.function)
value: [(arrow_function) (function_expression)]) @definition.function)
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
(#select-adjacent! @doc @definition.function)
)
Expand All @@ -66,12 +66,12 @@
(member_expression
property: (property_identifier) @name)
]
right: [(arrow_function) (function)]
right: [(arrow_function) (function_expression)]
) @definition.function

(pair
key: (property_identifier) @name
value: [(arrow_function) (function)]) @definition.function
value: [(arrow_function) (function_expression)]) @definition.function

(
(call_expression
Expand All @@ -96,4 +96,4 @@
(new_expression)
(binary_expression)
(call_expression)
]))) @definition.constant
]))) @definition.constant
1 change: 0 additions & 1 deletion script/known_failures.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
examples/npm/node_modules/slide/lib/async-map-ordered.js
2 changes: 1 addition & 1 deletion script/parse-examples
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function clone_repo {
popd > /dev/null
}

clone_repo npm npm ee147fbbca6f2707d3b16f4fa78f4c4606b2d9b1
clone_repo npm cli 0dd03f9450e0cf57fa85ad2ef74b5a54f3c775a9

known_failures="$(cat script/known_failures.txt)"

Expand Down
Loading
Loading