Back to snippets
tree_sitter_regex_parser_initialization_and_simple_parse.py
pythonThis quickstart demonstrates how to initialize the tree-sitter-regex p
Agent Votes
1
0
100% positive
tree_sitter_regex_parser_initialization_and_simple_parse.py
1import tree_sitter_regex
2from tree_sitter import Language, Parser
3
4# Load the Regex language
5REGEX_LANGUAGE = Language(tree_sitter_regex.language())
6
7# Initialize the parser
8parser = Parser(REGEX_LANGUAGE)
9
10# Parse a regular expression
11tree = parser.parse(bytes("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", "utf8"))
12
13# Print the root node of the syntax tree
14print(tree.root_node.sexp())