Skip to content

chore: rebase to latest tree-sitter #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-python"
description = "Python grammar for the tree-sitter parsing library"
version = "0.19.0"
version = "0.20.2"
authors = [
"Max Brunsfeld <[email protected]>",
"Douglas Creager <[email protected]>",
Expand Down
37 changes: 34 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ module.exports = grammar({
$._string_start,
$._string_content,
$._string_end,

// Mark comments as external tokens so that the external scanner is always
// invoked, even if no external token is expected. This allows for better
// error recovery, because the external scanner can maintain the overall
// structure by returning dedent tokens whenever a dedent occurs, even
// if no dedent is expected.
$.comment,

// Allow the external scanner to check for the validity of closing brackets
// so that it can avoid returning dedent tokens between brackets.
']',
')',
'}',
],

inline: $ => [
Expand Down Expand Up @@ -313,6 +326,11 @@ module.exports = grammar({
optional($.else_clause),
optional($.finally_clause)
),
seq(
repeat1($.except_group_clause),
optional($.else_clause),
optional($.finally_clause)
),
$.finally_clause
)
),
Expand All @@ -330,7 +348,20 @@ module.exports = grammar({
$._suite
),

finally_clause: $ => seq(
except_group_clause: $ => seq(
'except*',
seq(
$.expression,
optional(seq(
'as',
$.expression
))
),
':',
$._suite
),

finally_clause: $ => seq(
'finally',
':',
$._suite
Expand All @@ -345,8 +376,8 @@ module.exports = grammar({
),

with_clause: $ => choice(
commaSep1($.with_item),
seq('(', commaSep1($.with_item), ')')
seq(commaSep1($.with_item), optional(',')),
seq('(', commaSep1($.with_item), optional(','), ')')
),

with_item: $ => prec.dynamic(1, seq(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tree-sitter-python",
"version": "0.19.0",
"version": "0.20.2",
"description": "Python grammar for tree-sitter",
"main": "bindings/node",
"keywords": [
Expand Down
160 changes: 144 additions & 16 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,42 @@
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "except_group_clause"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "else_clause"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "finally_clause"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "SYMBOL",
"name": "finally_clause"
Expand Down Expand Up @@ -1330,6 +1366,53 @@
}
]
},
"except_group_clause": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "except*"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "as"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "_suite"
}
]
},
"finally_clause": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -1391,24 +1474,41 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "with_item"
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "with_item"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "with_item"
}
]
}
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "with_item"
}
]
}
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down Expand Up @@ -1444,6 +1544,18 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
Expand Down Expand Up @@ -5469,6 +5581,22 @@
{
"type": "SYMBOL",
"name": "_string_end"
},
{
"type": "SYMBOL",
"name": "comment"
},
{
"type": "STRING",
"value": "]"
},
{
"type": "STRING",
"value": ")"
},
{
"type": "STRING",
"value": "}"
}
],
"inline": [
Expand Down
27 changes: 27 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,25 @@
]
}
},
{
"type": "except_group_clause",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "block",
"named": true
},
{
"type": "expression",
"named": true
}
]
}
},
{
"type": "exec_statement",
"named": true,
Expand Down Expand Up @@ -2422,6 +2441,10 @@
"type": "except_clause",
"named": true
},
{
"type": "except_group_clause",
"named": true
},
{
"type": "finally_clause",
"named": true
Expand Down Expand Up @@ -2951,6 +2974,10 @@
"type": "except",
"named": false
},
{
"type": "except*",
"named": false
},
{
"type": "exec",
"named": false
Expand Down
Loading