Open Andrew15-5 opened 1 month ago
Thanks for reporting. Interestingly, it is trying to compile the regex pattern when it loads the yaml file at https://github.com/trishume/syntect/blob/master/src/parsing/yaml_load.rs#L473. But, that spurious trailing slash is unfortunately being eaten in the line above. I think it can be fixed like:
diff --git a/src/parsing/syntax_definition.rs b/src/parsing/syntax_definition.rs
index d73c3e7..2bdee51 100644
--- a/src/parsing/syntax_definition.rs
+++ b/src/parsing/syntax_definition.rs
@@ -241,6 +241,9 @@ where
last_was_escape = c == '\\' && !last_was_escape;
}
+ if last_was_escape {
+ reg_str.push('\\')
+ }
reg_str
}
But, that spurious trailing slash is unfortunately being eaten in the line above.
Indeed, removing the substitute_backrefs_in_regex()
gives:
error: failed to parse syntax file `a.sublime-syntax` (Error while compiling regex '\': Parsing error at position 0: Backslash without following character)
┌─ a.typ:1:19
│
1 │ #set raw(syntaxes: "a.sublime-syntax")
│ ^^^^^^^^^^^^^^^^^^
Or applying the patch gives the same error (duh).
Hello, I discovered a panic in Typst: https://github.com/typst/typst/issues/4421. I was able to recreate the panic and the use case of the library in Typst:
https://github.com/trishume/syntect/blob/d023aaa509d9e5058d55f9aa787c88f9a74bb180/src/parsing/regex.rs#L70
There should be some way to get
Result::Err
from some function call to be able to show in stderr what exactly went wrong. This error is generally "invalid regex" or more specifically "invalid regex: backslash doesn't escape anything".I was able to remove panic by validating the regex before searching:
https://github.com/trishume/syntect/blob/d023aaa509d9e5058d55f9aa787c88f9a74bb180/src/parsing/regex.rs#L64-L65
But this wouldn't give away any
Error
. I also don't see any way to useRegex::try_compile()
directly in Typst/MRA code, therefore some other way of validating all regexes in a.sublime-syntax
file should be added.