CMake grammar for tree-sitter
Project description
This is a tree-sitter grammar for CMake.
Note: This repository is a fork of uyha/tree-sitter-cmake. If you encounter any issues or have questions, please submit them to the issue tracker.
Installation
You can install the Python binding via pip:
pip install tree-sitter-cmake
Usage
Here’s a simple example of how to use this grammar to parse CMake code in Python:
import tree_sitter_cmake
import tree_sitter
# Load the CMake language
cmake_language = tree_sitter.Language(tree_sitter_cmake.language())
# Initialize the parser
parser = tree_sitter.Parser(cmake_language)
# Parse some CMake code
source_code = b"""
cmake_minimum_required(VERSION 3.10)
project(Test)
set(CMAKE_CXX_STANDARD 17)
add_executable(main main.cpp)
"""
tree = parser.parse(source_code)
root_node = tree.root_node
# Print the syntax tree as an S-expression
print(str(root_node))
Parsed Syntax
This grammar supports most CMake constructs, including:
Commands: General commands, flow control (if, while, foreach), functions, and macros.
Arguments: Quoted, bracket, and unquoted arguments.
Variables: Normal, cache, and environment variable references.
Comments: Line and bracket comments.
Requirements
Python >= 3.10
tree-sitter ~= 0.24
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tree_sitter_cmake-0.7.2.post1.tar.gz.
File metadata
- Download URL: tree_sitter_cmake-0.7.2.post1.tar.gz
- Upload date:
- Size: 47.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.7 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64a3751ca67f37112821d67057b8de6ecab5c7e94d6053467a4b78ceab348640
|
|
| MD5 |
fd4c9b30140918bc536e6af7fb6286a5
|
|
| BLAKE2b-256 |
d0f4928d5378ef701577ef1b19658fc626a8c70b32447148898771a17c3c66a1
|
File details
Details for the file tree_sitter_cmake-0.7.2.post1-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: tree_sitter_cmake-0.7.2.post1-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 28.0 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.7 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1b7a754e17442087df3efccea6535a9f2a8c4b4bf558e31fd3caccd8d1ce830
|
|
| MD5 |
03a72f7f552fa32bdcf95ef089a7ee34
|
|
| BLAKE2b-256 |
f80b820ab5f8581f3b39e4bb6837e9f8573d70cfa71e8530a7a97355898b8751
|