1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
mod impl_trait;

pub use crate::{
    error::{ParseError, Result, Wanted, Warn},
    parser::LogixParser,
    span::SourceSpan,
    token::{Brace, Delim, Literal, StrTag, StrTagSuffix, Token},
    Map, Str,
};
pub use logix_vfs::LogixVfs;

pub struct Value<T> {
    pub value: T,
    pub span: SourceSpan,
}

impl<T> Value<T> {
    pub fn map<R>(self, f: impl FnOnce(T) -> R) -> Value<R> {
        Value {
            span: self.span,
            value: f(self.value),
        }
    }

    pub fn join_with_span(mut self, span: SourceSpan) -> Self {
        self.span = self.span.join(&span);
        self
    }
}

pub enum LogixValueDescriptor {
    /// A native type that can be specified by a literal
    Native,
    /// Describes a tuple of various types
    Tuple {
        members: Vec<&'static LogixTypeDescriptor>,
    },
    /// Describes the named members of a struct
    Struct {
        members: Vec<(&'static str, &'static LogixTypeDescriptor)>,
    },
    /// Describes the variants of an enum
    Enum { variants: Vec<LogixTypeDescriptor> },
}

pub struct LogixTypeDescriptor {
    pub name: &'static str,
    pub doc: &'static str,
    pub value: LogixValueDescriptor,
}

pub trait LogixType: Sized {
    fn descriptor() -> &'static LogixTypeDescriptor;
    fn default_value() -> Option<Self>;
    fn logix_parse<FS: LogixVfs>(p: &mut LogixParser<FS>) -> Result<Value<Self>>;
}