From 9301d38b773bbb25bcb9d12236cc1bddaa9aea20 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sat, 7 Sep 2024 19:37:27 -0400 Subject: [PATCH] feat!: remove C++ support for external scanners --- cli/loader/src/lib.rs | 27 ++++----------------------- docs/section-3-creating-parsers.md | 13 +++---------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index 610d0602..7f3c3384 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -609,15 +609,10 @@ impl Loader { .host(BUILD_HOST) .debug(self.debug_build) .file(&config.parser_path) - .includes(&config.header_paths); + .includes(&config.header_paths) + .std("c11"); if let Some(scanner_path) = config.scanner_path.as_ref() { - if scanner_path.extension() != Some("c".as_ref()) { - cc_config.cpp(true); - eprintln!("Warning: Using a C++ scanner is now deprecated. Please migrate your scanner code to C, as C++ support will be removed in the near future."); - } else { - cc_config.std("c11"); - } cc_config.file(scanner_path); } @@ -882,14 +877,6 @@ impl Loader { ]); if let Some(scanner_filename) = scanner_filename { - if scanner_filename - .extension() - .and_then(|ext| ext.to_str()) - .map_or(false, |ext| ["cc", "cpp"].contains(&ext)) - { - eprintln!("Warning: Using a C++ scanner is now deprecated. Please migrate your scanner code to C, as C++ support will be removed in the near future."); - command.arg("-xc++"); - } command.arg(scanner_filename); } @@ -1204,14 +1191,8 @@ impl Loader { #[must_use] pub fn get_scanner_path(&self, src_path: &Path) -> Option { - let mut path = src_path.join("scanner.c"); - for extension in ["c", "cc", "cpp"] { - path.set_extension(extension); - if path.exists() { - return Some(path); - } - } - None + let path = src_path.join("scanner.c"); + path.exists().then_some(path) } } diff --git a/docs/section-3-creating-parsers.md b/docs/section-3-creating-parsers.md index ca4c65cf..e0681732 100644 --- a/docs/section-3-creating-parsers.md +++ b/docs/section-3-creating-parsers.md @@ -14,7 +14,7 @@ Developing Tree-sitter grammars can have a difficult learning curve, but once yo In order to develop a Tree-sitter parser, there are two dependencies that you need to install: * **Node.js** - Tree-sitter grammars are written in JavaScript, and Tree-sitter uses [Node.js][node.js] to interpret JavaScript files. It requires the `node` command to be in one of the directories in your [`PATH`][path-env]. You'll need Node.js version 6.0 or greater. -* **A C Compiler** - Tree-sitter creates parsers that are written in C. In order to run and test these parsers with the `tree-sitter parse` or `tree-sitter test` commands, you must have a C/C++ compiler installed. Tree-sitter will try to look for these compilers in the standard places for each platform. +* **A C Compiler** - Tree-sitter creates parsers that are written in C. In order to run and test these parsers with the `tree-sitter parse` or `tree-sitter test` commands, you must have a C compiler installed. Tree-sitter will try to look for these compilers in the standard places for each platform. ### Installation @@ -766,14 +766,7 @@ grammar({ }); ``` -Then, add another C or C++ source file to your project. Currently, its path must be `src/scanner.c` or `src/scanner.cc` for the CLI to recognize it. Be sure to add this file to the `sources` section of your `binding.gyp` file so that it will be included when your project is compiled by Node.js and uncomment the appropriate block in your `bindings/rust/build.rs` file so that it will be included in your Rust crate. - -> **Note** -> -> C++ scanners are now deprecated and will be removed in the near future. -> While it is currently possible to write an external scanner in C++, it can be difficult -> to get working cross-platform and introduces extra requirements; therefore it -> is *greatly* preferred to use C. +Then, add another C source file to your project. Currently, its path must be `src/scanner.c` for the CLI to recognize it. Be sure to add this file to the `sources` section of your `binding.gyp` file so that it will be included when your project is compiled by Node.js and uncomment the appropriate block in your `bindings/rust/build.rs` file so that it will be included in your Rust crate. In this new source file, define an [`enum`][enum] type containing the names of all of your external tokens. The ordering of this enum must match the order in your grammar's `externals` array; the actual names do not matter. @@ -789,7 +782,7 @@ enum TokenType { } ``` -Finally, you must define five functions with specific names, based on your language's name and five actions: *create*, *destroy*, *serialize*, *deserialize*, and *scan*. These functions must all use [C linkage][c-linkage], so if you're writing the scanner in C++, you need to declare them with the `extern "C"` qualifier. +Finally, you must define five functions with specific names, based on your language's name and five actions: *create*, *destroy*, *serialize*, *deserialize*, and *scan*. #### Create