From 74812ced1b0bec57f010bb240f35742fdcf1d20a Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Wed, 14 Feb 2024 15:07:13 -0500 Subject: [PATCH] chore: deprecate C++ scanners C++ has been a headache to deal with throughout the ecosystem and for several downstream projects. It is difficult to get working with WASM, and induces potential issues with compilation on Windows. It has been proven that writing scanners in C is a much better alternative, and is the recommended way to write scanners now. C++ support will likely be removed in 0.21.0 --- cli/loader/src/lib.rs | 7 +++++++ docs/section-3-creating-parsers.md | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index 319a8cc1..48e95262 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -524,7 +524,12 @@ impl Loader { command.arg("/O2"); } command.arg(parser_path); + if let Some(scanner_path) = scanner_path.as_ref() { + if scanner_path.extension() != Some("c".as_ref()) { + 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(scanner_path); } command @@ -560,6 +565,7 @@ impl Loader { if scanner_path.extension() == Some("c".as_ref()) { command.arg("-xc").arg("-std=c99").arg(scanner_path); } else { + 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(scanner_path); } } @@ -750,6 +756,7 @@ impl Loader { .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); diff --git a/docs/section-3-creating-parsers.md b/docs/section-3-creating-parsers.md index ffe9181e..2642f23c 100644 --- a/docs/section-3-creating-parsers.md +++ b/docs/section-3-creating-parsers.md @@ -649,7 +649,11 @@ 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** -> While it is 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. +> +> 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. 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.