Convert emacs wrapper to tokio's Command.

This commit is contained in:
Tom Alexander
2023-08-17 03:34:49 -04:00
parent 0d2a13739a
commit 65aba3c993
5 changed files with 24 additions and 8 deletions

View File

@@ -1,8 +1,10 @@
#![feature(exit_status_error)]
use axum::{http::StatusCode, routing::post, Json, Router};
use parse::emacs_parse_org_document;
use serde::Serialize;
use tower_http::services::{ServeDir, ServeFile};
mod owner_tree;
mod parse;
#[tokio::main]
@@ -16,9 +18,10 @@ async fn main() {
axum::serve(listener, app).await.unwrap();
}
async fn parse_org_mode(body: String) -> (StatusCode, Json<OwnerTree>) {
async fn parse_org_mode(body: String) -> Result<(StatusCode, Json<OwnerTree>), (StatusCode, String)> {
let ast = emacs_parse_org_document(&body).await.map_err(|e| (StatusCode::BAD_REQUEST, e.to_string()))?;
let ret = OwnerTree { input_source: body };
(StatusCode::OK, Json(ret))
Ok((StatusCode::OK, Json(ret)))
}
#[derive(Serialize)]

1
src/owner_tree.rs Normal file
View File

@@ -0,0 +1 @@

View File

@@ -1,6 +1,8 @@
use std::process::Command;
use tokio::process::Command;
pub fn emacs_parse_org_document<C>(file_contents: C) -> Result<String, Box<dyn std::error::Error>>
pub async fn emacs_parse_org_document<C>(
file_contents: C,
) -> Result<String, Box<dyn std::error::Error>>
where
C: AsRef<str>,
{
@@ -22,10 +24,10 @@ where
.arg("--batch")
.arg("--eval")
.arg(elisp_script);
let out = proc.output()?;
let out = proc.output().await?;
out.status.exit_ok()?;
let org_sexp = out.stderr;
Ok(String::from_utf8(org_sexp)?)
Ok(String::from_utf8(out.stderr)?)
}
fn escape_elisp_string<C>(file_contents: C) -> String