Compare commits
5 commits
tree-sitte
...
master
Author | SHA1 | Date | |
---|---|---|---|
e409ae33f0 | |||
f2569dd1fc | |||
5c493f3722 | |||
69d7a8b0f7 | |||
4864abb95a |
|
@ -2,8 +2,8 @@
|
||||||
A Tree-sitter parser for CMake
|
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`.
|
This project provides a `cmake` parser. Its primary use case is to provide a `cmake`
|
||||||
|
parser for `nvim-treesitter`.
|
||||||
|
|
||||||
Parsed syntax
|
Parsed syntax
|
||||||
=============
|
=============
|
||||||
|
@ -22,10 +22,8 @@ Parsed syntax
|
||||||
- Unquoted arguments
|
- Unquoted arguments
|
||||||
- Parentheses
|
- Parentheses
|
||||||
|
|
||||||
- Variable refences
|
- Variable references
|
||||||
|
|
||||||
- Environment and cache variables
|
- Environment and cache variables
|
||||||
- Normal variables
|
- Normal variables
|
||||||
|
|
||||||
- Generator expression
|
|
||||||
|
|
||||||
|
|
5
bindings/rust/build.rs
generated
5
bindings/rust/build.rs
generated
|
@ -2,7 +2,7 @@ fn main() {
|
||||||
let src_dir = std::path::Path::new("src");
|
let src_dir = std::path::Path::new("src");
|
||||||
|
|
||||||
let mut c_config = cc::Build::new();
|
let mut c_config = cc::Build::new();
|
||||||
c_config.include(&src_dir);
|
c_config.std("c11").include(src_dir);
|
||||||
c_config
|
c_config
|
||||||
.flag_if_supported("-Wno-unused-parameter")
|
.flag_if_supported("-Wno-unused-parameter")
|
||||||
.flag_if_supported("-Wno-unused-but-set-variable")
|
.flag_if_supported("-Wno-unused-but-set-variable")
|
||||||
|
@ -17,6 +17,5 @@ fn main() {
|
||||||
c_config.file(&scanner_path);
|
c_config.file(&scanner_path);
|
||||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||||
|
|
||||||
c_config.compile("parser");
|
c_config.compile("tree-sitter-cmake");
|
||||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
20
bindings/rust/lib.rs
generated
20
bindings/rust/lib.rs
generated
|
@ -4,10 +4,12 @@
|
||||||
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! let code = "";
|
//! let code = r#"
|
||||||
|
//! "#;
|
||||||
//! let mut parser = tree_sitter::Parser::new();
|
//! let mut parser = tree_sitter::Parser::new();
|
||||||
//! parser.set_language(tree_sitter_cmake::language()).expect("Error loading cmake grammar");
|
//! parser.set_language(&tree_sitter_cmake::language()).expect("Error loading cmake grammar");
|
||||||
//! let tree = parser.parse(code, None).unwrap();
|
//! let tree = parser.parse(code, None).unwrap();
|
||||||
|
//! assert!(!tree.root_node().has_error());
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||||
|
@ -31,14 +33,14 @@ pub fn language() -> Language {
|
||||||
/// The content of the [`node-types.json`][] file for this grammar.
|
/// The content of the [`node-types.json`][] file for this grammar.
|
||||||
///
|
///
|
||||||
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
||||||
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
|
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
||||||
|
|
||||||
// Uncomment these to include any queries that this grammar contains
|
// Uncomment these to include any queries that this grammar contains
|
||||||
|
|
||||||
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
|
||||||
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
|
// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
|
||||||
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
|
// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
|
||||||
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
@ -46,7 +48,7 @@ mod tests {
|
||||||
fn test_can_load_grammar() {
|
fn test_can_load_grammar() {
|
||||||
let mut parser = tree_sitter::Parser::new();
|
let mut parser = tree_sitter::Parser::new();
|
||||||
parser
|
parser
|
||||||
.set_language(super::language())
|
.set_language(&super::language())
|
||||||
.expect("Error loading cmake language");
|
.expect("Error loading cmake grammar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
commands = [
|
const commands = [
|
||||||
"if",
|
"if",
|
||||||
"elseif",
|
"elseif",
|
||||||
"else",
|
"else",
|
||||||
|
|
25
package.json
25
package.json
|
@ -18,14 +18,13 @@
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tree-sitter": [
|
"files": [
|
||||||
{
|
"grammar.js",
|
||||||
"scope": "source.cmake",
|
"binding.gyp",
|
||||||
"file-types": [
|
"prebuilds/**",
|
||||||
"cmake",
|
"bindings/node/*",
|
||||||
"CMakeLists.txt"
|
"queries/*",
|
||||||
]
|
"src/**"
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tree-sitter-cli": "^0.21.0",
|
"tree-sitter-cli": "^0.21.0",
|
||||||
|
@ -34,13 +33,5 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "node-gyp-build",
|
"install": "node-gyp-build",
|
||||||
"prebuildify": "prebuildify --napi --strip"
|
"prebuildify": "prebuildify --napi --strip"
|
||||||
},
|
}
|
||||||
"files": [
|
|
||||||
"grammar.js",
|
|
||||||
"binding.gyp",
|
|
||||||
"prebuilds/**",
|
|
||||||
"bindings/node/*",
|
|
||||||
"queries/*",
|
|
||||||
"src/**"
|
|
||||||
]
|
|
||||||
}
|
}
|
1
src/grammar.json
generated
1
src/grammar.json
generated
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
|
||||||
"name": "cmake",
|
"name": "cmake",
|
||||||
"rules": {
|
"rules": {
|
||||||
"source_file": {
|
"source_file": {
|
||||||
|
|
1
src/node-types.json
generated
1
src/node-types.json
generated
|
@ -568,6 +568,7 @@
|
||||||
{
|
{
|
||||||
"type": "source_file",
|
"type": "source_file",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
"root": true,
|
||||||
"fields": {},
|
"fields": {},
|
||||||
"children": {
|
"children": {
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
|
|
13044
src/parser.c
generated
13044
src/parser.c
generated
File diff suppressed because it is too large
Load diff
8
src/tree_sitter/alloc.h
generated
8
src/tree_sitter/alloc.h
generated
|
@ -12,10 +12,10 @@ extern "C" {
|
||||||
// Allow clients to override allocation functions
|
// Allow clients to override allocation functions
|
||||||
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
||||||
|
|
||||||
extern void *(*ts_current_malloc)(size_t);
|
extern void *(*ts_current_malloc)(size_t size);
|
||||||
extern void *(*ts_current_calloc)(size_t, size_t);
|
extern void *(*ts_current_calloc)(size_t count, size_t size);
|
||||||
extern void *(*ts_current_realloc)(void *, size_t);
|
extern void *(*ts_current_realloc)(void *ptr, size_t size);
|
||||||
extern void (*ts_current_free)(void *);
|
extern void (*ts_current_free)(void *ptr);
|
||||||
|
|
||||||
#ifndef ts_malloc
|
#ifndef ts_malloc
|
||||||
#define ts_malloc ts_current_malloc
|
#define ts_malloc ts_current_malloc
|
||||||
|
|
1
src/tree_sitter/parser.h
generated
1
src/tree_sitter/parser.h
generated
|
@ -47,6 +47,7 @@ struct TSLexer {
|
||||||
uint32_t (*get_column)(TSLexer *);
|
uint32_t (*get_column)(TSLexer *);
|
||||||
bool (*is_at_included_range_start)(const TSLexer *);
|
bool (*is_at_included_range_start)(const TSLexer *);
|
||||||
bool (*eof)(const TSLexer *);
|
bool (*eof)(const TSLexer *);
|
||||||
|
void (*log)(const TSLexer *, const char *, ...);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -1,143 +0,0 @@
|
||||||
=======================================
|
|
||||||
Unquoted generator expression [gen_exp]
|
|
||||||
=======================================
|
|
||||||
message($<>)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(source_file
|
|
||||||
(normal_command
|
|
||||||
(identifier)
|
|
||||||
(argument_list
|
|
||||||
(argument
|
|
||||||
(unquoted_argument
|
|
||||||
(gen_exp)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
=====================================
|
|
||||||
Quoted generator expression [gen_exp]
|
|
||||||
=====================================
|
|
||||||
message("$<>")
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(source_file
|
|
||||||
(normal_command
|
|
||||||
(identifier)
|
|
||||||
(argument_list
|
|
||||||
(argument
|
|
||||||
(quoted_argument
|
|
||||||
(quoted_element
|
|
||||||
(gen_exp)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
=====================
|
|
||||||
No argument [gen_exp]
|
|
||||||
=====================
|
|
||||||
message($<ANGLE-R>)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(source_file
|
|
||||||
(normal_command
|
|
||||||
(identifier)
|
|
||||||
(argument_list
|
|
||||||
(argument
|
|
||||||
(unquoted_argument
|
|
||||||
(gen_exp
|
|
||||||
(argument
|
|
||||||
(unquoted_argument)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
============================================
|
|
||||||
No argument with superfluous colon [gen_exp]
|
|
||||||
============================================
|
|
||||||
message($<ANGLE-R:>)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(source_file
|
|
||||||
(normal_command
|
|
||||||
(identifier)
|
|
||||||
(argument_list
|
|
||||||
(argument
|
|
||||||
(unquoted_argument
|
|
||||||
(gen_exp
|
|
||||||
(argument
|
|
||||||
(unquoted_argument)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
======================
|
|
||||||
One argument [gen_exp]
|
|
||||||
======================
|
|
||||||
message($<BOOL:-NOTFOUND>)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(source_file
|
|
||||||
(normal_command
|
|
||||||
(identifier)
|
|
||||||
(argument_list
|
|
||||||
(argument
|
|
||||||
(unquoted_argument
|
|
||||||
(gen_exp
|
|
||||||
(argument
|
|
||||||
(unquoted_argument))
|
|
||||||
(argument
|
|
||||||
(unquoted_argument)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
=======================
|
|
||||||
Two arguments [gen_exp]
|
|
||||||
=======================
|
|
||||||
message($<AND:TRUE,FALSE>)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(source_file
|
|
||||||
(normal_command
|
|
||||||
(identifier)
|
|
||||||
(argument_list
|
|
||||||
(argument
|
|
||||||
(unquoted_argument
|
|
||||||
(gen_exp
|
|
||||||
(argument
|
|
||||||
(unquoted_argument))
|
|
||||||
(argument
|
|
||||||
(unquoted_argument))
|
|
||||||
(argument
|
|
||||||
(unquoted_argument)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
35
tree-sitter.json
Normal file
35
tree-sitter.json
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"grammars": [
|
||||||
|
{
|
||||||
|
"name": "cmake",
|
||||||
|
"camelcase": "Cmake",
|
||||||
|
"scope": "source.cmake",
|
||||||
|
"path": ".",
|
||||||
|
"file-types": [
|
||||||
|
"cmake",
|
||||||
|
"CMakeLists.txt"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"version": "0.5.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"description": "CMake grammar for tree-sitter",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Uy Ha"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"links": {
|
||||||
|
"repository": "https://github.com/tree-sitter/tree-sitter-cmake"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bindings": {
|
||||||
|
"c": true,
|
||||||
|
"go": true,
|
||||||
|
"node": true,
|
||||||
|
"python": true,
|
||||||
|
"rust": true,
|
||||||
|
"swift": true
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue