#cmake #incremental #parser

tree-sitter-cmake

cmake grammar for the tree-sitter parsing library

9 releases

0.4.3 Mar 19, 2024
0.4.2 Feb 22, 2024
0.4.1 Nov 8, 2023
0.4.0 Jun 29, 2023
0.0.3 Jul 8, 2022

#127 in Text editors

Download history 484/week @ 2023-12-23 475/week @ 2023-12-30 532/week @ 2024-01-06 565/week @ 2024-01-13 514/week @ 2024-01-20 523/week @ 2024-01-27 496/week @ 2024-02-03 525/week @ 2024-02-10 666/week @ 2024-02-17 678/week @ 2024-02-24 1017/week @ 2024-03-02 1225/week @ 2024-03-09 996/week @ 2024-03-16 737/week @ 2024-03-23 1219/week @ 2024-03-30 935/week @ 2024-04-06

4,031 downloads per month
Used in neocmakelsp

MIT license

570KB
21K SLoC

C 21K SLoC JavaScript 87 SLoC Rust 34 SLoC // 0.1% comments

A Tree-sitter parser for CMake

This project provides a cmake parser. Its primary use case is to provide a cmake parser for nvim-treesitter.

Parsed syntax

  • Command
    • General commands
    • For and while loops
    • If conditions
    • Functions and macros
  • Arguments
    • Quoted arguments
    • Bracket arguments
    • Unquoted arguments
    • Parentheses
  • Variable refences
    • Environment and cache variables
    • Normal variables
  • Generator expression

lib.rs:

This crate provides cmake language support for the tree-sitter parsing library.

Typically, you will use the language function to add this language to a tree-sitter Parser, and then use the parser to parse some code:

let code = "";
let mut parser = tree_sitter::Parser::new();
parser.set_language(tree_sitter_cmake::language()).expect("Error loading cmake grammar");
let tree = parser.parse(code, None).unwrap();

Dependencies

~2.7–4MB
~71K SLoC