use crate::LINE_END;
use regex::{Regex, RegexSet};
use std::sync::LazyLock;
pub const ITEM: &str = "\\item";
pub const ENV_BEGIN: &str = "\\begin{";
pub const ENV_END: &str = "\\end{";
pub const EXTENSIONS: [&str; 4] = ["tex", "bib", "sty", "cls"];
pub const VERBS: [&str; 3] = ["\\verb|", "\\verb+", "\\mintinline"];
const SPLITTING: [&str; 6] = [
r"\\begin\{",
r"\\end\{",
r"\\item(?:$|[^a-zA-Z])",
r"\\(?:sub){0,2}section\*?\{",
r"\\chapter\*?\{",
r"\\part\*?\{",
];
pub const TABLES_BEGIN: [&str; 1] = ["\\begin{tabular}"];
pub const TABLES_END: [&str; 1] = ["\\end{tabular}"];
static SPLITTING_STRING: LazyLock<String> =
LazyLock::new(|| ["(", SPLITTING.join("|").as_str(), ")"].concat());
pub static RE_NEWLINES: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(&format!(r"{LINE_END}{LINE_END}({LINE_END})+")).unwrap()
});
pub static RE_TRAIL: LazyLock<Regex> =
LazyLock::new(|| Regex::new(&format!(r" +{LINE_END}")).unwrap());
pub static RE_SPLITTING: LazyLock<RegexSet> =
LazyLock::new(|| RegexSet::new(SPLITTING).unwrap());
pub static RE_SPLITTING_SHARED_LINE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
[r"(:?\S.*?)", "(:?", SPLITTING_STRING.as_str(), ".*)"]
.concat()
.as_str(),
)
.unwrap()
});
pub static RE_SPLITTING_SHARED_LINE_CAPTURE: LazyLock<Regex> =
LazyLock::new(|| {
Regex::new(
[
r"(?P<prev>\S.*?)",
"(?P<env>",
SPLITTING_STRING.as_str(),
".*)",
]
.concat()
.as_str(),
)
.unwrap()
});