Skip to content

Commit

Permalink
feat: expand python language support
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Feb 1, 2024
1 parent 306cd74 commit 8869e67
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
33 changes: 29 additions & 4 deletions languages/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,39 @@ func TestPython(t *testing.T) {
Name: "Simple",
FileName: "simple.py",
Input: `
class Square:
side = 1
def __init__(self, side):
self.side = side
def area(self):
return self.side * self.side
def perimeter(self):
return 4 * self.side
def main():
a = 1
`,
Expected: `
(tree [0,0 | 0]-[1,6 | 18]
(function [0,0 | 0]-[1,6 | 18]
(tree [0,0 | 0]-[1,6 | 18]
(assignment a [1,1 | 13]-[1,2 | 14]))))
(tree [0,0 | 0]-[13,6 | 185]
(class Square Square [0,0 | 0]-[10,22 | 165]
(tree [1,1 | 15]-[10,22 | 165]
(assignment int side [1,1 | 15]-[1,5 | 19])
(function any __init__ [3,1 | 26]-[4,18 | 70]
(tree [3,1 | 26]-[4,18 | 70]
(variable any self [3,13 | 38]-[3,25 | 50])
(variable any side [3,13 | 38]-[3,25 | 50])))
(function any area [6,1 | 73]-[7,30 | 119]
(tree [6,1 | 73]-[7,30 | 119]
(variable any self [6,9 | 81]-[6,15 | 87])))
(function any perimeter [9,1 | 122]-[10,22 | 165]
(tree [9,1 | 122]-[10,22 | 165]
(variable any self [9,14 | 135]-[9,20 | 141])))))
(function any main [12,0 | 167]-[13,6 | 185]
(tree [12,0 | 167]-[13,6 | 185]
(assignment int a [13,1 | 180]-[13,2 | 181]))))
`,
},
}
Expand Down
49 changes: 36 additions & 13 deletions languages/python/symbols.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
(import_statement
name: (_) @import.path) @import
name: (_) @import.path) @import

(module [(class_definition
name: (identifier) @class.name
body: (block [
(expression_statement
(assignment
left: (identifier) @variable.name
type: (_)? @variable.return-type
right: (_) @variable.content) @variable)

(function_definition
name: (identifier) @method.name
parameters: (parameters
[
(identifier) @parameter.name
(typed_parameter
((identifier) @parameter.name)
type: (_) @parameter.return-type)
]? @parameter) @parameters
body: (block
(return_statement (_) @block.content)?) @block) @method
]) @class.body) @class

(function_definition
parameters: (parameters
[
(identifier) @parameter.name
(typed_parameter
((identifier) @parameter.name)
type: (_) @parameter.return-type)
]? @parameter) @parameters) @function
(return_statement
(_) @block.content)?
name: (identifier) @function.name
parameters: (parameters
[
(identifier) @parameter.name
(typed_parameter
((identifier) @parameter.name)
type: (_) @parameter.return-type)
]? @parameter) @parameters
body: (block
(return_statement (_) @block.content)?) @block) @function])

(expression_statement
(assignment
left: (identifier) @assignment.name
right: (identifier) @assignment.content) @assignment)
(assignment
left: (identifier) @assignment.name
right: (_) @assignment.content) @assignment)

0 comments on commit 8869e67

Please sign in to comment.