🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

tree-sitter-python

Package Overview
Dependencies
Maintainers
6
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-sitter-python - npm Package Compare versions

Comparing version

to
0.20.0

.github/workflows/ci.yml

134

grammar.js

@@ -10,17 +10,19 @@ const PREC = {

parenthesized_list_splat: 1,
not: 1,
compare: 2,
or: 10,
and: 11,
bitwise_or: 12,
bitwise_and: 13,
xor: 14,
shift: 15,
plus: 16,
times: 17,
unary: 18,
power: 19,
call: 20,
or: 10,
and: 11,
not: 12,
compare: 13,
bitwise_or: 14,
bitwise_and: 15,
xor: 16,
shift: 17,
plus: 18,
times: 19,
unary: 20,
power: 21,
call: 22,
}
const SEMICOLON = ';'
module.exports = grammar({

@@ -40,2 +42,4 @@ name: 'python',

[$.with_item, $._collection_elements],
[$.named_expression, $.as_pattern],
[$.match_statement, $.primary_expression],
],

@@ -83,8 +87,4 @@

_simple_statements: $ => seq(
$._simple_statement,
optional(repeat(seq(
$._semicolon,
$._simple_statement
))),
optional($._semicolon),
sep1($._simple_statement, SEMICOLON),
optional(SEMICOLON),
$._newline

@@ -196,3 +196,3 @@ ),

named_expression: $ => seq(
field('name', $.identifier),
field('name', $._named_expresssion_lhs),
':=',

@@ -202,2 +202,7 @@ field('value', $.expression)

_named_expresssion_lhs: $ => choice(
$.identifier,
alias('match', $.identifier), // ambiguity with match statement: only ":" at end of line decides if "match" keyword
),
return_statement: $ => seq(

@@ -238,3 +243,4 @@ 'return',

$.class_definition,
$.decorated_definition
$.decorated_definition,
$.match_statement,
),

@@ -264,2 +270,23 @@

match_statement: $ => seq(
'match',
commaSep1(field('subject', $.expression)),
optional(','),
':',
repeat(field('alternative', $.case_clause))),
case_clause: $ => seq(
'case',
commaSep1(
field(
'pattern',
alias(choice($.expression, $.list_splat_pattern), $.case_pattern),
)
),
optional(','),
optional(field('guard', $.if_clause)),
':',
field('consequence', $._suite)
),
for_statement: $ => seq(

@@ -332,6 +359,2 @@ optional('async'),

field('value', $.expression),
optional(seq(
'as',
field('alias', $.pattern)
))
)),

@@ -485,3 +508,4 @@

$.tuple_pattern,
alias('*', $.list_splat_pattern),
$.keyword_separator,
$.positional_separator,
$.dictionary_splat_pattern

@@ -492,2 +516,3 @@ ),

$.identifier,
alias('match', $.identifier), // ambiguity with match statement: only ":" at end of line decides if "match" keyword
$.keyword_identifier,

@@ -537,2 +562,10 @@ $.subscript,

// Extended patterns (patterns allowed in match statement are far more flexible than simple patterns though still a subset of "expression")
as_pattern: $ => prec.left(seq(
$.expression,
'as',
field('alias', alias($.expression, $.as_pattern_target))
)),
// Expressions

@@ -553,3 +586,4 @@

$.conditional_expression,
$.named_expression
$.named_expression,
$.as_pattern
),

@@ -560,2 +594,3 @@

$.identifier,
alias("match", $.identifier),
$.keyword_identifier,

@@ -635,15 +670,16 @@ $.string,

repeat1(seq(
choice(
'<',
'<=',
'==',
'!=',
'>=',
'>',
'<>',
'in',
seq('not', 'in'),
'is',
seq('is', 'not')
),
field('operators',
choice(
'<',
'<=',
'==',
'!=',
'>=',
'>',
'<>',
'in',
seq('not', 'in'),
'is',
seq('is', 'not')
)),
$.primary_expression

@@ -687,3 +723,3 @@ ))

$.pattern,
$.pattern_list
$.pattern_list,
),

@@ -768,3 +804,3 @@

keyword_argument: $ => seq(
field('name', choice($.identifier, $.keyword_identifier)),
field('name', choice($.identifier, $.keyword_identifier, alias("match", $.identifier))),
'=',

@@ -885,3 +921,3 @@ field('value', $.expression)

alias($._string_start, '"'),
repeat(choice($.interpolation, $.escape_sequence, $._not_escape_sequence, $._string_content)),
repeat(choice($.interpolation, $._escape_interpolation, $.escape_sequence, $._not_escape_sequence, $._string_content)),
alias($._string_end, '"')

@@ -893,2 +929,3 @@ ),

$.expression,
optional('='),
optional($.type_conversion),

@@ -899,2 +936,4 @@ optional($.format_specifier),

_escape_interpolation: $ => choice('{{', '}}'),
escape_sequence: $ => token(prec(1, seq(

@@ -965,3 +1004,3 @@ '\\',

identifier: $ => /[a-zA-Zα-ωΑ-Ω_][a-zA-Zα-ωΑ-Ω_0-9]*/,
identifier: $ => /[_\p{XID_Start}][_\p{XID_Continue}]*/,

@@ -989,12 +1028,13 @@ keyword_identifier: $ => prec(-3, alias(

_semicolon: $ => ';'
positional_separator: $ => '/',
keyword_separator: $ => '*',
}
})
function commaSep1 (rule) {
function commaSep1(rule) {
return sep1(rule, ',')
}
function sep1 (rule, separator) {
function sep1(rule, separator) {
return seq(rule, repeat(seq(separator, rule)))
}
{
"name": "tree-sitter-python",
"version": "0.19.0",
"version": "0.20.0",
"description": "Python grammar for tree-sitter",

@@ -13,6 +13,6 @@ "main": "bindings/node",

"dependencies": {
"nan": "^2.14.0"
"nan": "^2.15.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.19.1"
"tree-sitter-cli": "^0.20.1"
},

@@ -22,2 +22,3 @@ "scripts": {

"test": "tree-sitter test && script/parse-examples",
"parse": "tree-sitter parse",
"test-windows": "tree-sitter test"

@@ -24,0 +25,0 @@ },

tree-sitter-python
==================
[![Build Status](https://travis-ci.org/tree-sitter/tree-sitter-python.svg?branch=master)](https://travis-ci.org/tree-sitter/tree-sitter-python)
[![Build status](https://ci.appveyor.com/api/projects/status/ddxtf154nsck4wbe/branch/master?svg=true)](https://ci.appveyor.com/project/maxbrunsfeld/tree-sitter-python/branch/master)
[![build](https://github.com/tree-sitter/tree-sitter-python/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-python/actions/workflows/ci.yml)

@@ -7,0 +6,0 @@ Python grammar for [tree-sitter][].

@@ -27,2 +27,6 @@ [

{
"type": "match_statement",
"named": true
},
{
"type": "try_statement",

@@ -112,2 +116,6 @@ "named": true

{
"type": "as_pattern",
"named": true
},
{
"type": "await",

@@ -163,2 +171,6 @@ "named": true

{
"type": "keyword_separator",
"named": true
},
{
"type": "list_splat_pattern",

@@ -168,2 +180,6 @@ "named": true

{
"type": "positional_separator",
"named": true
},
{
"type": "tuple_pattern",

@@ -368,2 +384,28 @@ "named": true

{
"type": "as_pattern",
"named": true,
"fields": {
"alias": {
"multiple": false,
"required": true,
"types": [
{
"type": "as_pattern_target",
"named": true
}
]
}
},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
}
},
{
"type": "assert_statement",

@@ -763,2 +805,61 @@ "named": true,

{
"type": "case_clause",
"named": true,
"fields": {
"consequence": {
"multiple": false,
"required": true,
"types": [
{
"type": "block",
"named": true
}
]
},
"guard": {
"multiple": false,
"required": false,
"types": [
{
"type": "if_clause",
"named": true
}
]
},
"pattern": {
"multiple": true,
"required": true,
"types": [
{
"type": "case_pattern",
"named": true
}
]
}
}
},
{
"type": "case_pattern",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "attribute",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "subscript",
"named": true
}
]
}
},
{
"type": "chevron",

@@ -817,3 +918,50 @@ "named": true,

"named": true,
"fields": {},
"fields": {
"operators": {
"multiple": true,
"required": true,
"types": [
{
"type": "!=",
"named": false
},
{
"type": "<",
"named": false
},
{
"type": "<=",
"named": false
},
{
"type": "<>",
"named": false
},
{
"type": "==",
"named": false
},
{
"type": ">",
"named": false
},
{
"type": ">=",
"named": false
},
{
"type": "in",
"named": false
},
{
"type": "is",
"named": false
},
{
"type": "not",
"named": false
}
]
}
},
"children": {

@@ -1604,2 +1752,7 @@ "multiple": true,

{
"type": "keyword_separator",
"named": true,
"fields": {}
},
{
"type": "lambda",

@@ -1738,3 +1891,3 @@ "named": true,

"multiple": false,
"required": false,
"required": true,
"types": [

@@ -1757,2 +1910,28 @@ {

{
"type": "match_statement",
"named": true,
"fields": {
"alternative": {
"multiple": true,
"required": false,
"types": [
{
"type": "case_clause",
"named": true
}
]
},
"subject": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
}
]
}
}
},
{
"type": "module",

@@ -1941,2 +2120,7 @@ "named": true,

{
"type": "positional_separator",
"named": true,
"fields": {}
},
{
"type": "print_statement",

@@ -2411,12 +2595,2 @@ "named": true,

"fields": {
"alias": {
"multiple": false,
"required": false,
"types": [
{
"type": "pattern",
"named": true
}
]
},
"value": {

@@ -2580,2 +2754,6 @@ "multiple": false,

{
"type": ";",
"named": false
},
{
"type": "<",

@@ -2677,2 +2855,6 @@ "named": false

{
"type": "case",
"named": false
},
{
"type": "class",

@@ -2774,2 +2956,6 @@ "named": false

{
"type": "match",
"named": false
},
{
"type": "none",

@@ -2835,2 +3021,6 @@ "named": true

{
"type": "{{",
"named": false
},
{
"type": "|",

@@ -2848,2 +3038,6 @@ "named": false

{
"type": "}}",
"named": false
},
{
"type": "~",

@@ -2850,0 +3044,0 @@ "named": false

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 not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet