Skip to content
Open
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
26 changes: 25 additions & 1 deletion python/extractor/tests/parser/exception_groups_new.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Module: [1, 0] - [27, 0]
Module: [1, 0] - [32, 0]
body: [
Try: [1, 0] - [1, 4]
body: [
Expand Down Expand Up @@ -153,4 +153,28 @@ Module: [1, 0] - [27, 0]
]
]
finalbody: []
Try: [28, 0] - [28, 4]
body: [
Pass: [29, 4] - [29, 8]
]
orelse: []
handlers: [
ExceptGroupStmt: [30, 0] - [31, 8]
type:
Tuple: [30, 8] - [30, 12]
elts: [
Name: [30, 8] - [30, 9]
variable: Variable('x', None)
ctx: Load
Name: [30, 11] - [30, 12]
variable: Variable('y', None)
ctx: Load
]
ctx: Load
name: None
body: [
Pass: [31, 4] - [31, 8]
]
]
finalbody: []
]
5 changes: 5 additions & 0 deletions python/extractor/tests/parser/exception_groups_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@
pass
except *foo as e:
pass

try:
pass
except* x, y:
pass
64 changes: 64 additions & 0 deletions python/extractor/tests/parser/exceptions_new.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Module: [1, 0] - [9, 0]
body: [
Try: [1, 0] - [1, 4]
body: [
Pass: [2, 4] - [2, 8]
]
orelse: []
handlers: [
ExceptStmt: [3, 0] - [3, 12]
type:
Tuple: [3, 7] - [3, 11]
elts: [
Name: [3, 7] - [3, 8]
variable: Variable('a', None)
ctx: Load
Name: [3, 10] - [3, 11]
variable: Variable('b', None)
ctx: Load
]
ctx: Load
name: None
body: [
Pass: [4, 4] - [4, 8]
]
ExceptStmt: [5, 0] - [5, 14]
type:
Tuple: [5, 8] - [5, 12]
elts: [
Name: [5, 8] - [5, 9]
variable: Variable('c', None)
ctx: Load
Name: [5, 11] - [5, 12]
variable: Variable('d', None)
ctx: Load
]
ctx: Load
parenthesised: True
name: None
body: [
Pass: [6, 4] - [6, 8]
]
ExceptStmt: [7, 0] - [7, 19]
type:
Tuple: [7, 8] - [7, 12]
elts: [
Name: [7, 8] - [7, 9]
variable: Variable('e', None)
ctx: Load
Name: [7, 11] - [7, 12]
variable: Variable('f', None)
ctx: Load
]
ctx: Load
parenthesised: True
name:
Name: [7, 17] - [7, 18]
variable: Variable('g', None)
ctx: Store
body: [
Pass: [8, 4] - [8, 8]
]
]
finalbody: []
]
8 changes: 8 additions & 0 deletions python/extractor/tests/parser/exceptions_new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
try:
pass
except a, b: # new, relaxed syntax
pass
except (c, d): # old syntax
pass
except (e, f) as g: # old syntax
pass
6 changes: 5 additions & 1 deletion python/extractor/tsg-python/python.tsg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(assignment !type) @assign
{ let @assign.node = (ast-node @assign "Assign") }

[ (expression_list) (tuple) (tuple_pattern) (pattern_list) (index_expression_list) ] @tuple
[ (expression_list) (tuple) (tuple_pattern) (pattern_list) (index_expression_list) (exception_list)] @tuple
{ let @tuple.node = (ast-node @tuple "Tuple") }

(list_pattern) @list
Expand Down Expand Up @@ -3445,6 +3445,9 @@
(tuple element: (_) @elt) @parent

(tuple_pattern element: (_) @elt) @parent

; An exception list, as in `except A, B, C: ...`
(exception_list element: (_) @elt) @parent
]
{
edge @parent.node -> @elt.node
Expand Down Expand Up @@ -3480,6 +3483,7 @@
(parenthesized_expression inner: (_) @elt)
(set element: (_) @elt)
(match_sequence_pattern (_) @elt)
(exception_list element: (_) @elt)
] @seq
{
attr (@elt.node) _inherited_ctx = @seq.node
Expand Down
4 changes: 4 additions & 0 deletions python/extractor/tsg-python/tsp/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Mark tree-sitter generated files
src/grammar.json linguist-generated
src/node-types.json linguist-generated
src/parser.c linguist-generated
15 changes: 12 additions & 3 deletions python/extractor/tsg-python/tsp/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,21 @@ module.exports = grammar({
)
),

exception_list: $ => seq(
field('element', $.expression),
repeat1(
seq(
',',
field('element', $.expression))
)
),

except_clause: $ => seq(
'except',
optional(seq(
field('type', $.expression),
field('type', choice($.expression, $.exception_list)),
optional(seq(
choice('as', ','),
'as',
field('alias', $.expression)
))
)),
Expand All @@ -314,7 +323,7 @@ module.exports = grammar({
'except',
'*',
seq(
field('type', $.expression),
field('type', choice($.expression, $.exception_list)),
optional(seq(
'as',
field('alias', $.expression)
Expand Down
72 changes: 57 additions & 15 deletions python/extractor/tsg-python/tsp/src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions python/extractor/tsg-python/tsp/src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading