From ef60b730ea45847d7b472d774a930e160786d20b Mon Sep 17 00:00:00 2001 From: Taus Date: Mon, 28 Oct 2024 14:49:45 +0000 Subject: [PATCH] Python: Fix parenthesized tuple parser bug We were writing the `parenthesised` attribute twice on tuples, once because of the explicit parenthetisation, and once because all non-empty tuples are parenthesised. This made `tree-sitter-graph` unhappy. To fix this, we now explicitly check whether a tuple is already parenthesised, and do nothing if that is the case. --- python/extractor/tests/parser/collections.py | 2 ++ python/extractor/tsg-python/python.tsg | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/python/extractor/tests/parser/collections.py b/python/extractor/tests/parser/collections.py index 4e570fd0adc..9331cd467c0 100644 --- a/python/extractor/tests/parser/collections.py +++ b/python/extractor/tests/parser/collections.py @@ -35,3 +35,5 @@ t, u, x, y, #comment ) + +((z,)) diff --git a/python/extractor/tsg-python/python.tsg b/python/extractor/tsg-python/python.tsg index c7c339b96fb..89ff50ec4a8 100644 --- a/python/extractor/tsg-python/python.tsg +++ b/python/extractor/tsg-python/python.tsg @@ -3485,5 +3485,9 @@ [(tuple element: (_)) (tuple_pattern)] @tup { - attr (@tup.node) parenthesised = #true + ; In order to avoid writing to the `parenthesised` attribute twice, we only set it here + ; if the surrounding expression is not a `parenthesized_expression`. + if (not (instance-of (get-parent @tup) "parenthesized_expression")) { + attr (@tup.node) parenthesised = #true + } }