Compare commits

...

5 commits

Author SHA1 Message Date
Amaan Qureshi e409ae33f0
fix: generate with strict mode (#30) 2024-10-14 03:37:52 +03:00
Uy Ha f2569dd1fc chore: generate with tree-sitter 0.24.2 2024-10-07 08:54:29 +00:00
Uy Ha 5c493f3722 chore: remove tests for generator expression
These are remnants from the previous version that has parsing for generator expression.
Refer to a414a4c to see why it is removed.
2024-10-07 08:54:04 +00:00
Access 69d7a8b0f7
chore: update rust bindings (#27) 2024-06-20 12:32:15 +07:00
Uy Ha 4864abb95a doc: update README 2024-06-05 08:48:32 +00:00
12 changed files with 6590 additions and 6705 deletions

View file

@ -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

View file

@ -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
View file

@ -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");
} }
} }

View file

@ -1,4 +1,4 @@
commands = [ const commands = [
"if", "if",
"elseif", "elseif",
"else", "else",

View file

@ -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
View file

@ -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
View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -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 {

View file

@ -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
View 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
}
}