Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve resilience of the parser #6

Merged
merged 14 commits into from
Nov 26, 2024
10 changes: 5 additions & 5 deletions crates/org-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "org-rust"
version = "0.1.16"
version = "0.1.17"
description = "CLI tool for converting Org-Mode documents to other formats"
keywords = ["org-mode", "parser"]
categories = ["command-line-utilities"]
Expand All @@ -18,8 +18,8 @@ rust-version.workspace = true
clap = { version = "4.3.11", features = ["derive"] }
lazy_format = "2.0.0"
regex = "1.9.5"
org-exporter = { version = "0.1.6", path = "../org-exporter", package = "org-rust-exporter" }
org-parser = { version = "0.1.4", path = "../org-parser", package = "org-rust-parser" }
org-exporter = { version = "0.1.8", path = "../org-exporter", package = "org-rust-exporter" }
org-parser = { version = "0.1.5", path = "../org-parser", package = "org-rust-parser" }
serde = { version = "1.0.196", features=["derive"]}
toml = "0.8.8"
anyhow = "1.0.82"
Expand All @@ -30,8 +30,8 @@ clap = { version = "4.3.11", features=["derive"]}
clap_complete = "4.3.2"
clap_mangen = "0.2.14"
serde = { version = "1.0.196", features=["derive"]}
org-exporter = { version = "0.1.2", path = "../org-exporter", package = "org-rust-exporter" }
org-parser = { version = "0.1.2", path = "../org-parser", package = "org-rust-parser" }
org-exporter = { version = "0.1.8", path = "../org-exporter", package = "org-rust-exporter" }
org-parser = { version = "0.1.5", path = "../org-parser", package = "org-rust-parser" }


# [[bin]]
Expand Down
2 changes: 1 addition & 1 deletion crates/org-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Backend {
parsed: &org_parser::Parser,
buf: &mut String,
conf: ConfigOptions
) -> Result<(), core::fmt::Error> {
) -> Result<(), Vec<org_exporter::ExportError>> {
match self {
Backend::Html => org_exporter::Html::export_tree(parsed, buf, conf),
Backend::Org => org_exporter::Org::export_tree(parsed, buf, conf),
Expand Down
9 changes: 8 additions & 1 deletion crates/org-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ fn run() -> anyhow::Result<()> {
}

let conf = ConfigOptions::new(Some(file_path.to_path_buf()));
backend.export(&parser_output, &mut exported_content, conf)?;
if let Err(err_vec) = backend.export(&parser_output, &mut exported_content, conf) {
let mut build_str = String::new();
for e in err_vec {
build_str.push_str(&e.to_string());
build_str.push_str("\n");
}
Err(CliError::new().with_cause(&build_str))?
}

// handle a template (if needed)
if let Some(template_path) = parser_output.keywords.get("template_path") {
Expand Down
12 changes: 6 additions & 6 deletions crates/org-cli/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ impl<'a, 'template> Template<'a, 'template> {
}
}

#[cfg(test)]
mod tests {
use super::*;
// #[cfg(test)]
// mod tests {
// use super::*;

#[test]
fn bad_template() {}
}
// #[test]
// fn bad_template() {}
// }
2 changes: 1 addition & 1 deletion crates/org-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::types::CliError;
// a fs::canonicalize that doesnt care for existince. used for error handling
// yanked straight from:
// https://github.com/rust-lang/cargo/blob/fede83ccf973457de319ba6fa0e36ead454d2e20/src/cargo/util/paths.rs#L61
pub fn normalize_path(path: &Path) -> PathBuf {
pub fn _normalize_path(path: &Path) -> PathBuf {
let mut components = path.components().peekable();
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
components.next();
Expand Down
5 changes: 3 additions & 2 deletions crates/org-exporter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "org-rust-exporter"
version = "0.1.7"
version = "0.1.8"
description = "exporter for org mode documents parsed with `org-rust-parser`"

homepage.workspace = true
Expand All @@ -14,8 +14,9 @@ rust-version.workspace = true
[dependencies]
latex2mathml = "0.2.3"
memchr = "2.5.0"
org-parser = { version = "0.1.3", path = "../org-parser", package = "org-rust-parser" }
org-parser = { version = "0.1.5", path = "../org-parser", package = "org-rust-parser" }
phf = {version = "0.11.1", features = ["macros"]}
thiserror = "1.0.63"

[dev-dependencies]
pretty_assertions = "1.3.0"
Loading