tree-sitter-python
Advanced tools
Comparing version 0.20.3 to 0.20.4
158
grammar.js
@@ -57,4 +57,4 @@ /** | ||
[$.named_expression, $.as_pattern], | ||
[$.match_statement, $.primary_expression], | ||
[$.print_statement, $.primary_expression], | ||
[$.type_alias_statement, $.primary_expression], | ||
], | ||
@@ -77,2 +77,3 @@ | ||
$._string_content, | ||
$.escape_interpolation, | ||
$.string_end, | ||
@@ -137,2 +138,3 @@ | ||
$.exec_statement, | ||
$.type_alias_statement, | ||
), | ||
@@ -315,8 +317,3 @@ | ||
'case', | ||
commaSep1( | ||
field( | ||
'pattern', | ||
alias($.expression, $.case_pattern), | ||
), | ||
), | ||
commaSep1($.case_pattern), | ||
optional(','), | ||
@@ -419,2 +416,3 @@ optional(field('guard', $.if_clause)), | ||
field('name', $.identifier), | ||
field('type_parameters', optional($.type_parameter)), | ||
field('parameters', $.parameters), | ||
@@ -470,5 +468,13 @@ optional( | ||
type_alias_statement: $ => prec.dynamic(1, seq( | ||
'type', | ||
$.type, | ||
'=', | ||
$.type, | ||
)), | ||
class_definition: $ => seq( | ||
'class', | ||
field('name', $.identifier), | ||
field('type_parameters', optional($.type_parameter)), | ||
field('superclasses', optional($.argument_list)), | ||
@@ -478,2 +484,7 @@ ':', | ||
), | ||
type_parameter: $ => seq( | ||
'[', | ||
commaSep1($.type), | ||
']', | ||
), | ||
@@ -543,4 +554,88 @@ parenthesized_list_splat: $ => prec(PREC.parenthesized_list_splat, seq( | ||
dotted_name: $ => sep1($.identifier, '.'), | ||
dotted_name: $ => prec(1, sep1($.identifier, '.')), | ||
// Match cases | ||
case_pattern: $ => prec(1, choice( | ||
alias($._as_pattern, $.as_pattern), | ||
$.keyword_pattern, | ||
$._simple_pattern, | ||
)), | ||
_simple_pattern: $ => prec(1, choice( | ||
$.class_pattern, | ||
$.splat_pattern, | ||
$.union_pattern, | ||
alias($._list_pattern, $.list_pattern), | ||
alias($._tuple_pattern, $.tuple_pattern), | ||
$.dict_pattern, | ||
$.string, | ||
$.concatenated_string, | ||
$.true, | ||
$.false, | ||
$.none, | ||
seq(optional('-'), choice($.integer, $.float)), | ||
$.complex_pattern, | ||
$.dotted_name, | ||
'_', | ||
)), | ||
_as_pattern: $ => seq($.case_pattern, 'as', $.identifier), | ||
union_pattern: $ => prec.right(seq($._simple_pattern, repeat1(prec.left(seq('|', $._simple_pattern))))), | ||
_list_pattern: $ => seq( | ||
'[', | ||
optional(seq( | ||
commaSep1($.case_pattern), | ||
optional(','), | ||
)), | ||
']', | ||
), | ||
_tuple_pattern: $ => seq( | ||
'(', | ||
optional(seq( | ||
commaSep1($.case_pattern), | ||
optional(','), | ||
)), | ||
')', | ||
), | ||
dict_pattern: $ => seq( | ||
'{', | ||
optional(seq( | ||
commaSep1(choice($._key_value_pattern, $.splat_pattern)), | ||
optional(','), | ||
)), | ||
'}', | ||
), | ||
_key_value_pattern: $ => seq( | ||
field('key', $._simple_pattern), | ||
':', | ||
field('value', $.case_pattern), | ||
), | ||
keyword_pattern: $ => seq($.identifier, '=', $._simple_pattern), | ||
splat_pattern: $ => prec(1, seq(choice('*', '**'), choice($.identifier, '_'))), | ||
class_pattern: $ => seq( | ||
$.dotted_name, | ||
'(', | ||
optional(seq( | ||
commaSep1($.case_pattern), | ||
optional(','), | ||
)), | ||
')', | ||
), | ||
complex_pattern: $ => prec(1, seq( | ||
optional('-'), | ||
choice($.integer, $.float), | ||
choice('+', '-'), | ||
choice($.integer, $.float), | ||
)), | ||
// Patterns | ||
@@ -853,3 +948,15 @@ | ||
type: $ => $.expression, | ||
type: $ => choice( | ||
$.expression, | ||
$.splat_type, | ||
$.generic_type, | ||
$.union_type, | ||
$.constrained_type, | ||
$.member_type, | ||
), | ||
splat_type: $ => prec(1, seq(choice('*', '**'), $.identifier)), | ||
generic_type: $ => prec(1, seq($.identifier, $.type_parameter)), | ||
union_type: $ => prec.left(seq($.type, '|', $.type)), | ||
constrained_type: $ => prec.right(seq($.type, ':', $.type)), | ||
member_type: $ => seq($.type, '.', $.identifier), | ||
@@ -979,3 +1086,3 @@ keyword_argument: $ => seq( | ||
choice( | ||
$._escape_interpolation, | ||
$.escape_interpolation, | ||
$.escape_sequence, | ||
@@ -1002,4 +1109,2 @@ $._not_escape_sequence, | ||
_escape_interpolation: _ => token.immediate(choice('{{', '}}')), | ||
escape_sequence: _ => token.immediate(prec(1, seq( | ||
@@ -1071,12 +1176,15 @@ '\\', | ||
keyword_identifier: $ => prec(-3, alias( | ||
choice( | ||
'print', | ||
'exec', | ||
'async', | ||
'await', | ||
'match', | ||
), | ||
$.identifier, | ||
)), | ||
keyword_identifier: $ => choice( | ||
prec(-3, alias( | ||
choice( | ||
'print', | ||
'exec', | ||
'async', | ||
'await', | ||
'match', | ||
), | ||
$.identifier, | ||
)), | ||
alias('type', $.identifier), | ||
), | ||
@@ -1106,3 +1214,3 @@ true: _ => 'True', | ||
* | ||
* @param {RegExp|Rule|String} rule | ||
* @param {RuleOrLiteral} rule | ||
* | ||
@@ -1119,5 +1227,5 @@ * @return {SeqRule} | ||
* | ||
* @param {RegExp|Rule|String} rule | ||
* @param {RuleOrLiteral} rule | ||
* | ||
* @param {RegExp|Rule|String} separator | ||
* @param {RuleOrLiteral} separator | ||
* | ||
@@ -1124,0 +1232,0 @@ * @return {SeqRule} |
{ | ||
"name": "tree-sitter-python", | ||
"version": "0.20.3", | ||
"version": "0.20.4", | ||
"description": "Python grammar for tree-sitter", | ||
@@ -13,8 +13,8 @@ "main": "bindings/node", | ||
"dependencies": { | ||
"nan": "^2.15.0" | ||
"nan": "^2.17.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.45.0", | ||
"eslint": "^8.47.0", | ||
"eslint-config-google": "^0.14.0", | ||
"tree-sitter-cli": "^0.20.1" | ||
"tree-sitter-cli": "^0.20.8" | ||
}, | ||
@@ -34,2 +34,9 @@ "scripts": { | ||
"py" | ||
], | ||
"injection-regex": "py", | ||
"highlights": [ | ||
"queries/highlights.scm" | ||
], | ||
"tags": [ | ||
"queries/tags.scm" | ||
] | ||
@@ -36,0 +43,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3785977
11135
Updatednan@^2.17.0