diff --git a/python/extractor/tests/parser/comprehensions.py b/python/extractor/tests/parser/comprehensions.py index e82ac1289093..1fade0f26b8c 100644 --- a/python/extractor/tests/parser/comprehensions.py +++ b/python/extractor/tests/parser/comprehensions.py @@ -65,3 +65,10 @@ d for e in f if g # comment # comment ] # comment + +# Generator expression with comments +(# comment + alpha # comment + for beta in gamma # comment + # comment +) diff --git a/python/extractor/tsg-python/python.tsg b/python/extractor/tsg-python/python.tsg index 89ff50ec4a85..07c79f0ba0ab 100644 --- a/python/extractor/tsg-python/python.tsg +++ b/python/extractor/tsg-python/python.tsg @@ -404,7 +404,7 @@ ;;; GeneratorExp -(generator_expression . "(" . (comment)* . (_) @start (_) @end . (comment)* . ")" .) @generatorexp +(generator_expression . "(" . (comment)* . (expression) @start [(for_in_clause) (if_clause)] @end . (comment)* . ")" .) @generatorexp { attr (@generatorexp.node) _location_start = (location-start @start) attr (@generatorexp.node) _location_end = (location-end @end) @@ -416,13 +416,13 @@ attr (@if.node) _location_end = (location-end @expr) } -(generator_expression . "(" . (comment)* . (_) @start (for_in_clause) @child (_) @end . (comment)* . ")" .) @genexpr +(generator_expression . "(" . (comment)* . (expression) @start (for_in_clause) @child [(for_in_clause) (if_clause)] @end . (comment)* . ")" .) @genexpr { attr (@child.node) _location_start = (location-start @start) attr (@child.node) _location_end = (location-end @end) } -(generator_expression . "(" . (comment)* . (_) @start (for_in_clause) @end . (comment)* . ")" .) @genexpr +(generator_expression . "(" . (comment)* . (expression) @start (for_in_clause) @end . (comment)* . ")" .) @genexpr { attr (@end.node) _location_start = (location-start @start) attr (@end.node) _location_end = (location-end @end) @@ -863,7 +863,7 @@ ; information for the entire generator expression (yes, it is a wide parameter!) and so we must recreate the logic for ; setting this location information correctly. -(generator_expression . "(" . (comment)* . (_) @start (_) @end . (comment)* . ")" .) @genexpr +(generator_expression . "(" . (comment)* . (expression) @start [(for_in_clause) (if_clause)] @end . (comment)* . ")" .) @genexpr { ; Synthesize the `genexpr` function let @genexpr.fun = (ast-node @genexpr "Function")