mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Python: Allow comments in subscripts
Once again, the interaction between anchors and extras (specifically comments) was causing trouble. The root of the problem was the fact that in `a[b]`, we put `b` in the `index` field of the subscript node, whereas in `a[b,c]`, we additionally synthesize a `Tuple` node for `b,c` (which matches the Python AST). To fix this, we refactored the grammar slightly so as to make that tuple explicit, such that a subscript node either contains a single expression or the newly added tuple node. This greatly simplifies the logic.
This commit is contained in:
@@ -929,11 +929,18 @@ module.exports = grammar({
|
||||
field('attribute', $.identifier)
|
||||
)),
|
||||
|
||||
_index_expression: $ => choice(
|
||||
$.list_splat,
|
||||
$.expression,
|
||||
$.slice
|
||||
),
|
||||
|
||||
index_expression_list: $ => open_sequence(field('element', $._index_expression)),
|
||||
|
||||
subscript: $ => prec(PREC.call, seq(
|
||||
field('value', $.primary_expression),
|
||||
'[',
|
||||
commaSep1(field('subscript', choice($.list_splat, $.expression, $.slice))),
|
||||
optional(','),
|
||||
field('subscript', choice($._index_expression, $.index_expression_list)),
|
||||
']'
|
||||
)),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user