Skip to content

Commit

Permalink
Use a new version of the forked syntect (#968)
Browse files Browse the repository at this point in the history
This fork doesn't panic on non compiling regexes.

Fix #967

The reason the fork is needed is that syntect panics when a regex from a syntax can't compile, which happens with sublime syntaxes when the engine isn't onig but fancy-regex.

The default regex engine of syntect is onig, but this unmaintained engine isn't pure-rust and isn't compatible with gcc 15, which limits compatibility for broot. So, right now, this fork is useful to prevent crashes.

The ideal solution would be either to have syntect completely handle regex compiling errors without panic (which looks easily doable but requires some work and may not appear as the best behavior for some other crates using syntect) and|or to have fancy-regex support all the regex features that are required by sublime syntaxes.

See also:
* fancy-regex/fancy-regex#74
* sharkdp/bat#3156 
* #956
* trishume/syntect#508
  • Loading branch information
Canop authored Jan 1, 2025
1 parent 5f8a639 commit e516208
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
28 changes: 11 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "broot"
version = "1.44.3"
version = "1.44.4-dev"
authors = ["dystroy <denys.seguret@gmail.com>"]
repository = "https://github.com/Canop/broot"
homepage = "https://dystroy.org/broot"
Expand Down Expand Up @@ -57,7 +57,7 @@ serde = { version = "1.0", features = ["derive"] }
smallvec = "1.11" # version 2 is still alpha
splitty = "1.0.2"
strict = "0.1.4"
syntect = { package = "syntect-no-panic", version = "4.6.1", default-features = false, features = ["default-fancy"] } # see issues #485 and #956
syntect = { package = "syntect-5-no-panic", version = "5.2", default-features = false, features = ["default-fancy"] } # see issues #485, #956, #967
tempfile = "3.2"
termimad = "0.31"
terminal-clipboard = { version = "0.4.1", optional = true }
Expand Down Expand Up @@ -118,8 +118,7 @@ harness = false
# lfs-core = { path = "../lfs-core" }
# minimad = { path = "../minimad" }
# secular = { path = "../secular", features=["normalization"] }
# syntect = { path = "../syntect" }
# syntect-no-panic = { path = "../syntect" }
# syntect-5-no-panic = { path = "../syntect" }
# termimad = { path = "../termimad" }
# terminal-clipboard = { path = "../terminal-clipboard" }
# terminal-light = { path = "../terminal-light" }
Expand Down
2 changes: 1 addition & 1 deletion resources/syntect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ The [bat](https://github.com/sharkdp/bat) project maintains with care an importa

It's the best public list I found, so I've included the resulting syntax set here as `syntaxes.bin`.

You may replace this file with your own, building it with Syntect's [`syntect::dumps::dump_to_file`](https://docs.rs/syntect/4.6.0/syntect/dumps/fn.dump_to_file.html) function.
You may replace this file with your own, building it with Syntect's [`syntect::dumps::dump_to_uncompressed_file`](https://docs.rs/syntect/latest/syntect/dumps/fn.dump_to_uncompressed_file.html) function.
Binary file modified resources/syntect/syntaxes.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions src/syntactic/syntactic_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ impl SyntacticView {
// Those chars are removed on printing
let name_match = pattern.search_string(&line);
let regions = if let Some(highlighter) = highlighter.as_mut() {
highlighter
.highlight(&line, &SYNTAXER.syntax_set)
highlighter
.highlight_line(&line, &SYNTAXER.syntax_set)
.map_err(|e| ProgramError::SyntectCrashed { details: e.to_string() })?
.iter()
.map(Region::from_syntect)
Expand Down
5 changes: 4 additions & 1 deletion src/syntactic/syntaxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ pub struct Syntaxer {
impl Default for Syntaxer {
fn default() -> Self {
Self {
syntax_set: time!(Debug, syntect::dumps::from_binary(SYNTAXES)),
syntax_set: time!(
Debug,
syntect::dumps::from_uncompressed_data(SYNTAXES).unwrap()
),
theme_set: ThemeSet::load_defaults(),
}
}
Expand Down

0 comments on commit e516208

Please sign in to comment.