anticipate_core/
lib.rs

1//! Parser and interpreter for the anticipate script automation tool.
2//!
3//! Moved to [anticipate-runner](https://docs.rs/anticipate-runner).
4#![deny(missing_docs)]
5#![forbid(unsafe_code)]
6
7mod error;
8mod interpreter;
9mod parser;
10
11pub use error::Error;
12pub use interpreter::{CinemaOptions, InterpreterOptions, ScriptFile};
13pub use parser::*;
14
15/// Result type for the parser.
16pub type Result<T> = std::result::Result<T, Error>;
17
18use std::{
19    borrow::Cow,
20    path::{Path, PathBuf},
21};
22
23/// Resolve a possibly relative path.
24pub(crate) fn resolve_path(
25    base: impl AsRef<Path>,
26    input: &str,
27) -> Result<Cow<str>> {
28    let path = PathBuf::from(input);
29    if path.is_relative() {
30        if let Some(parent) = base.as_ref().parent() {
31            let new_path = parent.join(input);
32            let path = new_path.canonicalize()?;
33            Ok(Cow::Owned(path.to_string_lossy().as_ref().to_owned()))
34        } else {
35            Ok(Cow::Borrowed(input))
36        }
37    } else {
38        Ok(Cow::Borrowed(input))
39    }
40}