use crate::lexer::Segment;
use crate::value::HoconValue;
use indexmap::IndexMap;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
#[doc(hidden)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IncludeKey {
Path(PathBuf),
#[cfg(feature = "include-package")]
Package { identifier: String, file: String },
}
pub struct InternalResolveOptions {
pub env: HashMap<String, String>,
pub base_dir: Option<PathBuf>,
pub include_stack: Vec<IncludeKey>,
#[cfg(feature = "include-package")]
pub package_registry: std::sync::Arc<std::collections::HashMap<(String, String), String>>,
pub use_system_environment: bool,
pub allow_unresolved: bool,
}
impl InternalResolveOptions {
pub fn new(env: HashMap<String, String>) -> Self {
InternalResolveOptions {
env,
base_dir: None,
include_stack: Vec::new(),
#[cfg(feature = "include-package")]
package_registry: std::sync::Arc::new(std::collections::HashMap::new()),
use_system_environment: true,
allow_unresolved: false,
}
}
pub fn with_base_dir(mut self, base_dir: PathBuf) -> Self {
self.base_dir = Some(base_dir);
self
}
pub fn with_base_dir_opt(mut self, base_dir: Option<PathBuf>) -> Self {
self.base_dir = base_dir;
self
}
pub fn with_allow_unresolved(mut self, b: bool) -> Self {
self.allow_unresolved = b;
self
}
pub fn with_use_system_environment(mut self, b: bool) -> Self {
self.use_system_environment = b;
self
}
}
#[allow(dead_code)]
pub type ResolveOptions = InternalResolveOptions;
#[derive(Debug, Clone)]
pub enum ResolverValue {
Resolved(HoconValue),
Subst(SubstPlaceholder),
Concat(ConcatPlaceholder),
Obj(ResObj),
UnresolvedArray(Vec<ResolverValue>),
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct SubstPlaceholder {
pub segments: Vec<Segment>,
pub optional: bool,
pub(crate) known_absent: bool,
pub list_suffix: bool,
pub line: usize,
pub col: usize,
pub prefix_len: usize,
}
#[derive(Debug, Clone)]
pub struct ConcatPlaceholder {
pub nodes: Vec<ResolverValue>,
pub separator_flags: Vec<bool>,
pub line: usize,
pub col: usize,
}
#[derive(Debug, Clone, Default)]
pub struct ResObj {
pub fields: IndexMap<String, ResolverValue>,
pub prior_values: IndexMap<String, ResolverValue>,
pub reset_keys: HashSet<String>,
}
impl ResObj {
pub fn new() -> Self {
Self::default()
}
}