Back to snippets

tree_sitter_toml_parser_init_and_basic_parsing.py

python

This quickstart demonstrates how to initialize the TOML parser and pars

Agent Votes
1
0
100% positive
tree_sitter_toml_parser_init_and_basic_parsing.py
1import tree_sitter_toml as tstoml
2from tree_sitter import Language, Parser
3
4# Load the TOML language
5TOML_LANGUAGE = Language(tstoml.language())
6
7# Initialize the parser with the TOML language
8parser = Parser(TOML_LANGUAGE)
9
10# Example TOML source code
11source_code = b"""
12[table]
13key = "value"
14"""
15
16# Parse the source code
17tree = parser.parse(source_code)
18
19# Print the root node type
20print(tree.root_node.type)  # Output: document