|
1 | 1 | import path from 'path'; |
2 | 2 | import Parser from 'web-tree-sitter'; |
3 | | -import { Language } from 'web-tree-sitter'; |
| 3 | +import { Language } from './language'; |
4 | 4 |
|
5 | 5 | const PYTHON_LANG = await Parser.Language.load(path.join(process.cwd(), 'app/parsers/tree-sitter-python.wasm')); |
6 | 6 |
|
7 | 7 | //----------------------------------------------------------------------------- |
8 | 8 | // Tree-Sitter queries |
9 | 9 | //----------------------------------------------------------------------------- |
10 | | -export class Python { |
11 | | - |
12 | | - public language: Language; |
13 | | - |
14 | | - // class definition tree-sitter query |
15 | | - // responsible for matching class definition, in addition to extracting the class name |
16 | | - public class_definition_query: Parser.Query; |
17 | | - |
18 | | - // function definition tree-sitter query |
19 | | - // responsible for matching function definition, in addition to extracting the function name |
20 | | - public function_definition_query: Parser.Query; |
21 | | - |
22 | | - // function call tree-sitter query |
23 | | - // responsible for matching function calls, in addition to extracting the callee function name |
24 | | - public function_call_query: Parser.Query; |
25 | | - |
26 | | - // function call tree-sitter query |
27 | | - // responsible for matching function calls of type self.f() |
28 | | - // in addition to extracting the callee function name |
29 | | - public function_attr_call_query: Parser.Query; |
30 | | - |
31 | | - // identifier tree-sitter query |
32 | | - // responsible for matching Identifier nodes |
33 | | - public identifier_query: Parser.Query; |
| 10 | +export class Python extends Language { |
34 | 11 |
|
35 | 12 | constructor() { |
36 | | - this.language = PYTHON_LANG; |
37 | | - this.class_definition_query = PYTHON_LANG.query(`(class_definition name: (identifier) @class-name) @class-definition`); |
38 | | - this.function_definition_query = PYTHON_LANG.query(`((function_definition name: (identifier) @function-name parameters: (parameters) @parameters) @function-definition)`); |
39 | | - this.function_call_query = PYTHON_LANG.query(`((call function: (identifier) @function-name) @function-call)`); |
40 | | - this.function_attr_call_query = PYTHON_LANG.query(`((call function: (attribute object: (identifier) attribute: (identifier) @function-name )) @function-call)`); |
41 | | - this.identifier_query = PYTHON_LANG.query(`((identifier) @identifier)`); |
42 | | - |
| 13 | + super( |
| 14 | + PYTHON_LANG, |
| 15 | + PYTHON_LANG.query(`(class_definition name: (identifier) @class-name) @class-definition`), |
| 16 | + PYTHON_LANG.query(`((function_definition name: (identifier) @function-name parameters: (parameters) @parameters) @function-definition)`), |
| 17 | + PYTHON_LANG.query(`((call function: (identifier) @function-name) @function-call)`), |
| 18 | + PYTHON_LANG.query(`((call function: (attribute object: (identifier) attribute: (identifier) @function-name )) @function-call)`), |
| 19 | + PYTHON_LANG.query(`((identifier) @identifier)`)) |
43 | 20 | } |
44 | | - |
45 | 21 | } |
0 commit comments