Skip to content

Commit

Permalink
chore: deprecate C++ scanners
Browse files Browse the repository at this point in the history
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
  • Loading branch information
amaanq committed Feb 14, 2024
1 parent d80d101 commit 68bc7c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cli/loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion docs/section-3-creating-parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 68bc7c1

Please sign in to comment.