Compare commits
1 commit
master
...
tree-sitte
Author | SHA1 | Date | |
---|---|---|---|
|
2a50b3b0ce |
|
@ -15,6 +15,9 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
|
|||
path = "bindings/rust/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter-language = "0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
tree-sitter = ">=0.22"
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
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
|
||||
=============
|
||||
|
@ -22,8 +22,10 @@ Parsed syntax
|
|||
- Unquoted arguments
|
||||
- Parentheses
|
||||
|
||||
- Variable references
|
||||
- Variable refences
|
||||
|
||||
- Environment and cache 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 mut c_config = cc::Build::new();
|
||||
c_config.std("c11").include(src_dir);
|
||||
c_config.include(&src_dir);
|
||||
c_config
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable")
|
||||
|
@ -17,5 +17,6 @@ fn main() {
|
|||
c_config.file(&scanner_path);
|
||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||
|
||||
c_config.compile("tree-sitter-cmake");
|
||||
c_config.compile("parser");
|
||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
||||
}
|
||||
|
|
32
bindings/rust/lib.rs
generated
32
bindings/rust/lib.rs
generated
|
@ -4,12 +4,10 @@
|
|||
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
||||
//!
|
||||
//! ```
|
||||
//! let code = r#"
|
||||
//! "#;
|
||||
//! let code = "";
|
||||
//! 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.into()).expect("Error loading cmake grammar");
|
||||
//! let tree = parser.parse(code, None).unwrap();
|
||||
//! assert!(!tree.root_node().has_error());
|
||||
//! ```
|
||||
//!
|
||||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
|
@ -17,30 +15,28 @@
|
|||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
||||
//! [tree-sitter]: https://tree-sitter.github.io/
|
||||
|
||||
use tree_sitter::Language;
|
||||
use tree_sitter_language::LanguageFn;
|
||||
|
||||
extern "C" {
|
||||
fn tree_sitter_cmake() -> Language;
|
||||
fn tree_sitter_cmake() -> *const ();
|
||||
}
|
||||
|
||||
/// Get the tree-sitter [Language][] for this grammar.
|
||||
/// The tree-sitter [`LanguageFn`][LanguageFn] for this grammar.
|
||||
///
|
||||
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
pub fn language() -> Language {
|
||||
unsafe { tree_sitter_cmake() }
|
||||
}
|
||||
/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
|
||||
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_cmake) };
|
||||
|
||||
/// 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
|
||||
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
||||
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
|
||||
|
||||
// Uncomment these to include any queries that this grammar contains
|
||||
|
||||
// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
|
||||
// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
|
||||
// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
|
||||
// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
|
||||
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
||||
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
|
||||
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
|
||||
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -48,7 +44,7 @@ mod tests {
|
|||
fn test_can_load_grammar() {
|
||||
let mut parser = tree_sitter::Parser::new();
|
||||
parser
|
||||
.set_language(&super::language())
|
||||
.expect("Error loading cmake grammar");
|
||||
.set_language(&super::LANGUAGE.into())
|
||||
.expect("Error loading cmake language");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const commands = [
|
||||
commands = [
|
||||
"if",
|
||||
"elseif",
|
||||
"else",
|
||||
|
|
27
package.json
27
package.json
|
@ -18,13 +18,14 @@
|
|||
"optional": true
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"grammar.js",
|
||||
"binding.gyp",
|
||||
"prebuilds/**",
|
||||
"bindings/node/*",
|
||||
"queries/*",
|
||||
"src/**"
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.cmake",
|
||||
"file-types": [
|
||||
"cmake",
|
||||
"CMakeLists.txt"
|
||||
]
|
||||
}
|
||||
],
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.21.0",
|
||||
|
@ -33,5 +34,13 @@
|
|||
"scripts": {
|
||||
"install": "node-gyp-build",
|
||||
"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,5 +1,4 @@
|
|||
{
|
||||
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
|
||||
"name": "cmake",
|
||||
"rules": {
|
||||
"source_file": {
|
||||
|
|
1
src/node-types.json
generated
1
src/node-types.json
generated
|
@ -568,7 +568,6 @@
|
|||
{
|
||||
"type": "source_file",
|
||||
"named": true,
|
||||
"root": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
|
|
12592
src/parser.c
generated
12592
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
|
||||
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
||||
|
||||
extern void *(*ts_current_malloc)(size_t size);
|
||||
extern void *(*ts_current_calloc)(size_t count, size_t size);
|
||||
extern void *(*ts_current_realloc)(void *ptr, size_t size);
|
||||
extern void (*ts_current_free)(void *ptr);
|
||||
extern void *(*ts_current_malloc)(size_t);
|
||||
extern void *(*ts_current_calloc)(size_t, size_t);
|
||||
extern void *(*ts_current_realloc)(void *, size_t);
|
||||
extern void (*ts_current_free)(void *);
|
||||
|
||||
#ifndef ts_malloc
|
||||
#define ts_malloc ts_current_malloc
|
||||
|
|
1
src/tree_sitter/parser.h
generated
1
src/tree_sitter/parser.h
generated
|
@ -47,7 +47,6 @@ struct TSLexer {
|
|||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
void (*log)(const TSLexer *, const char *, ...);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
|
143
test/corpus/gen_exp.txt
Normal file
143
test/corpus/gen_exp.txt
Normal file
|
@ -0,0 +1,143 @@
|
|||
=======================================
|
||||
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)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
|
@ -1,35 +0,0 @@
|
|||
{
|
||||
"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