mirror of
https://github.com/github/codeql.git
synced 2026-05-14 03:09:26 +02:00
unified: Get rid of $children* on key_path_expression
Doing this involved materialising a lot of previously anonymous nodes, and I'm not entirely sure it's the best solution, but the node types look decent enough.
This commit is contained in:
@@ -97,7 +97,7 @@ module.exports = grammar({
|
||||
[$.attribute],
|
||||
[$._attribute_argument],
|
||||
// Is `foo { ... }` a constructor invocation or function invocation?
|
||||
[$._simple_user_type, $.expression],
|
||||
[$.simple_user_type, $.expression],
|
||||
// To support nested types A.B not being interpreted as `(navigation_expression ... (type_identifier)) (navigation_suffix)`
|
||||
[$.user_type],
|
||||
// How to tell the difference between Foo.bar(with:and:), and Foo.bar(with: smth, and: other)? You need GLR
|
||||
@@ -116,7 +116,7 @@ module.exports = grammar({
|
||||
[$.referenceable_operator, $._prefix_unary_operator],
|
||||
// `{ [self, b, c] ...` could be a capture list or an array literal depending on what else happens.
|
||||
[$.capture_list_item, $.expression],
|
||||
[$.capture_list_item, $.expression, $._simple_user_type],
|
||||
[$.capture_list_item, $.expression, $.simple_user_type],
|
||||
[$._primary_expression, $.capture_list_item],
|
||||
// a ? b : c () could be calling c(), or it could be calling a function that's produced by the result of
|
||||
// `(a ? b : c)`. We have a small hack to force it to be the former of these by intentionally introducing a
|
||||
@@ -436,13 +436,13 @@ module.exports = grammar({
|
||||
)
|
||||
),
|
||||
// The grammar just calls this whole thing a `type-identifier` but that's a bit confusing.
|
||||
user_type: ($) => sep1(field("part", $._simple_user_type), $._dot),
|
||||
_simple_user_type: ($) =>
|
||||
user_type: ($) => sep1(field("part", $.simple_user_type), $._dot),
|
||||
simple_user_type: ($) =>
|
||||
prec.right(
|
||||
PRECS.ty,
|
||||
seq(
|
||||
alias($.simple_identifier, $.type_identifier),
|
||||
optional($.type_arguments)
|
||||
field("name", alias($.simple_identifier, $.type_identifier)),
|
||||
field("arguments", optional($.type_arguments))
|
||||
)
|
||||
),
|
||||
tuple_type: ($) =>
|
||||
@@ -1110,27 +1110,27 @@ module.exports = grammar({
|
||||
PRECS.keypath,
|
||||
seq(
|
||||
"\\",
|
||||
optional(
|
||||
choice($._simple_user_type, $.array_type, $.dictionary_type)
|
||||
),
|
||||
repeat(seq(".", $._key_path_component))
|
||||
field("type", optional(
|
||||
choice($.simple_user_type, $.array_type, $.dictionary_type)
|
||||
)),
|
||||
repeat(seq(".", field("component", $.key_path_component)))
|
||||
)
|
||||
),
|
||||
key_path_string_expression: ($) =>
|
||||
prec.left(seq($._hash_symbol, "keyPath", "(", field("expr", $.expression), ")")),
|
||||
_key_path_component: ($) =>
|
||||
key_path_component: ($) =>
|
||||
prec.left(
|
||||
choice(
|
||||
seq($.simple_identifier, repeat($._key_path_postfixes)),
|
||||
repeat1($._key_path_postfixes)
|
||||
seq(field("name", $.simple_identifier), repeat(field("postfix", $.key_path_postfix))),
|
||||
repeat1(field("postfix", $.key_path_postfix))
|
||||
)
|
||||
),
|
||||
_key_path_postfixes: ($) =>
|
||||
key_path_postfix: ($) =>
|
||||
choice(
|
||||
"?",
|
||||
$.bang,
|
||||
field("force_unwrap", $.bang),
|
||||
"self",
|
||||
seq("[", optional(sep1($.value_argument, ",")), "]")
|
||||
seq("[", optional(sep1(field("argument", $.value_argument), ",")), "]")
|
||||
),
|
||||
try_operator: ($) =>
|
||||
prec.right(
|
||||
|
||||
@@ -371,8 +371,15 @@ named:
|
||||
reference_specifier*: value_argument_label
|
||||
type_modifiers?: type_modifiers
|
||||
value?: expression
|
||||
key_path_component:
|
||||
name?: simple_identifier
|
||||
postfix*: key_path_postfix
|
||||
key_path_expression:
|
||||
$children*: [array_type, bang, dictionary_type, simple_identifier, type_arguments, type_identifier, value_argument]
|
||||
component*: key_path_component
|
||||
type?: [array_type, dictionary_type, simple_user_type]
|
||||
key_path_postfix:
|
||||
argument*: value_argument
|
||||
force_unwrap?: bang
|
||||
key_path_string_expression:
|
||||
expr: expression
|
||||
lambda_function_type:
|
||||
@@ -551,6 +558,9 @@ named:
|
||||
mutation?: mutation_modifier
|
||||
shebang_line:
|
||||
simple_identifier:
|
||||
simple_user_type:
|
||||
arguments?: type_arguments
|
||||
name: type_identifier
|
||||
source_file:
|
||||
shebang?: shebang_line
|
||||
statement*: [do_statement, expression, for_statement, global_declaration, guard_statement, repeat_while_statement, statement_label, throw_keyword, while_statement]
|
||||
@@ -634,7 +644,7 @@ named:
|
||||
type_parameters?: type_parameters
|
||||
value: type
|
||||
user_type:
|
||||
part+: [type_arguments, type_identifier]
|
||||
part+: simple_user_type
|
||||
value_argument:
|
||||
name?: value_argument_label
|
||||
reference_specifier*: value_argument_label
|
||||
|
||||
Reference in New Issue
Block a user