tree-sitter-typescript
tree-sitter-typescript copied to clipboard
Add Python usage instructions to README and create test.py for installation verification
Description
This pull request includes the following changes:
1 - Updated README.md:
- Added a new section titled "Python usage" that provides instructions on how to install and use the
tree-sitterlibrary with TypeScript and TSX grammars in Python. - Included a practical example section that directs users to the test.py file for a demonstration of how to use the library.
- Added instructions on how to test a successful installation by running the
test.pyscript.
2- Created test.py:
- Added a new file
test.pythat contains a script to verify the successful installation of thetree-sitterlibrary. - The script demonstrates how to parse TypeScript and TSX code using the
tree-sitterlibrary.
Testing
To verify the changes:
1- Follow the installation instructions in the README.md. 2- Run the test script using the command:
python bindings/python/tree_sitter_typescript/test.py
3- Ensure that the script runs successfully and parses the provided TypeScript and TSX code snippets.
Output
TypeScript root node: (program (function_declaration name: (identifier) parameters: (formal_parameters (required_parameter pattern: (identifier) type: (type_annotation (predefined_type))) (required_parameter pattern: (identifier) type: (type_annotation (predefined_type)))) return_type: (type_annotation (predefined_type)) body: (statement_block (return_statement (binary_expression left: (identifier) right: (identifier))))))
TSX root node: (program (import_statement (import_clause (identifier)) source: (string (string_fragment))) (function_declaration name: (identifier) parameters: (formal_parameters) body: (statement_block (return_statement (parenthesized_expression (jsx_element open_tag: (jsx_opening_element name: (identifier) attribute: (jsx_attribute (property_identifier) (string (string_fragment)))) (jsx_element open_tag: (jsx_opening_element name: (identifier) attribute: (jsx_attribute (property_identifier) (string (string_fragment)))) (jsx_element open_tag: (jsx_opening_element name: (identifier)) (jsx_text) close_tag: (jsx_closing_element name: (identifier))) close_tag: (jsx_closing_element name: (identifier))) close_tag: (jsx_closing_element name: (identifier))))))) (export_statement value: (identifier)))
TypeScript tree structure:
├── program
│ └── function_declaration
│ ├── function
│ ├── identifier
│ ├── formal_parameters
│ │ ├── (
│ │ ├── required_parameter
│ │ │ ├── identifier
│ │ │ └── type_annotation
│ │ │ ├── :
│ │ │ └── predefined_type
│ │ │ └── number
│ │ ├── ,
│ │ ├── required_parameter
│ │ │ ├── identifier
│ │ │ └── type_annotation
│ │ │ ├── :
│ │ │ └── predefined_type
│ │ │ └── number
│ │ └── )
│ ├── type_annotation
│ │ ├── :
│ │ └── predefined_type
│ │ └── number
│ └── statement_block
│ ├── {
│ ├── return_statement
│ │ ├── return
│ │ ├── binary_expression
│ │ │ ├── identifier
│ │ │ ├── +
│ │ │ └── identifier
│ │ └── ;
│ └── }
TSX tree structure:
├── program
│ ├── import_statement
│ │ ├── import
│ │ ├── import_clause
│ │ │ └── identifier
│ │ ├── from
│ │ ├── string
│ │ │ ├── '
│ │ │ ├── string_fragment
│ │ │ └── '
│ │ └── ;
│ ├── function_declaration
│ │ ├── function
│ │ ├── identifier
│ │ ├── formal_parameters
│ │ │ ├── (
│ │ │ └── )
│ │ └── statement_block
│ │ ├── {
│ │ ├── return_statement
│ │ │ ├── return
│ │ │ ├── parenthesized_expression
│ │ │ │ ├── (
│ │ │ │ ├── jsx_element
│ │ │ │ │ ├── jsx_opening_element
│ │ │ │ │ │ ├── <
│ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ ├── jsx_attribute
│ │ │ │ │ │ │ ├── property_identifier
│ │ │ │ │ │ │ ├── =
│ │ │ │ │ │ │ └── string
│ │ │ │ │ │ │ ├── "
│ │ │ │ │ │ │ ├── string_fragment
│ │ │ │ │ │ │ └── "
│ │ │ │ │ │ └── >
│ │ │ │ │ ├── jsx_element
│ │ │ │ │ │ ├── jsx_opening_element
│ │ │ │ │ │ │ ├── <
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ ├── jsx_attribute
│ │ │ │ │ │ │ │ ├── property_identifier
│ │ │ │ │ │ │ │ ├── =
│ │ │ │ │ │ │ │ └── string
│ │ │ │ │ │ │ │ ├── "
│ │ │ │ │ │ │ │ ├── string_fragment
│ │ │ │ │ │ │ │ └── "
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ ├── jsx_element
│ │ │ │ │ │ │ ├── jsx_opening_element
│ │ │ │ │ │ │ │ ├── <
│ │ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ │ └── >
│ │ │ │ │ │ │ ├── jsx_text
│ │ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ ├── </
│ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ └── >
│ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ ├── </
│ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ ├── </
│ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ └── >
│ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ ├── </
│ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ └── >
│ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ ├── </
│ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ ├── </
│ │ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ │ └── >
│ │ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ │ ├── </
│ │ │ │ │ │ ├── identifier
│ │ │ │ │ │ └── >
│ │ │ │ │ └── jsx_closing_element
│ │ │ │ │ ├── </
│ │ │ │ │ ├── identifier
│ │ │ │ │ └── >
│ │ │ │ └── )
│ │ │ └── ;
│ │ └── }
│ └── export_statement
│ ├── export
│ ├── default
│ ├── identifier
│ └── ;
tree_sitter_typescript package is working!```