1use std::path::PathBuf;
2
3use logix_vfs::LogixVfs;
4
5use crate::{
6 error::Result,
7 parser::LogixParser,
8 token::{Action, Token},
9 type_trait::{LogixTypeDescriptor, Value},
10 LogixType,
11};
12
13#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub enum Data<T> {
15 ByPath(PathBuf),
16 Inline(T),
17}
18
19impl<T: LogixType> LogixType for Data<T> {
20 fn descriptor() -> &'static LogixTypeDescriptor {
21 T::descriptor()
22 }
23
24 fn default_value() -> Option<Self> {
25 None
26 }
27
28 fn logix_parse<FS: LogixVfs>(p: &mut LogixParser<FS>) -> Result<Value<Self>> {
29 if let Some(ret) = p.forked(|p| match p.next_token()? {
30 (span, Token::Action(Action::Include)) => {
31 let file = crate::action::for_include(span, p)?;
32 Ok(Some(file.map(|f| Data::ByPath(f.0))))
33 }
34 _ => Ok(None),
35 })? {
36 Ok(ret)
37 } else {
38 T::logix_parse(p).map(|Value { span, value }| Value {
39 span,
40 value: Self::Inline(value),
41 })
42 }
43 }
44}