1#![allow(clippy::result_large_err)]
2
3use runmat_lexer::tokenize_detailed;
4
5#[cfg(all(test, target_arch = "wasm32"))]
6wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
7
8mod error;
9mod execution;
10mod fusion;
11mod profiling;
12mod session;
13mod source_pool;
14mod telemetry;
15mod value_metadata;
16mod workspace;
17
18pub use error::{runtime_error_telemetry_failure_info, RunError};
19pub use execution::*;
20pub use fusion::*;
21pub use runmat_parser::CompatMode;
22pub use session::RunMatSession;
23pub use telemetry::{
24 TelemetryFailureInfo, TelemetryHost, TelemetryPlatformInfo, TelemetryRunConfig,
25 TelemetryRunFinish, TelemetryRunGuard, TelemetrySink,
26};
27pub use value_metadata::{
28 approximate_size_bytes, matlab_class_name, numeric_dtype_label, preview_numeric_values,
29 value_shape,
30};
31pub use workspace::*;
32
33#[cfg(test)]
34mod tests;
35
36pub fn format_tokens(input: &str) -> String {
39 tokenize_detailed(input)
40 .into_iter()
41 .map(|t| format!("{:?}", t.token))
42 .collect::<Vec<_>>()
43 .join(" ")
44}
45
46pub async fn execute_and_format(input: &str) -> String {
48 match RunMatSession::new() {
49 Ok(mut engine) => match engine.execute(input).await {
50 Ok(result) => {
51 if let Some(error) = result.error {
52 format!("Error: {error}")
53 } else if let Some(value) = result.value {
54 format!("{value:?}")
55 } else {
56 "".to_string()
57 }
58 }
59 Err(e) => format!("Error: {e}"),
60 },
61 Err(e) => format!("Engine Error: {e}"),
62 }
63}