1use alloc::string::{
2 String,
3 ToString,
4};
5use core::str::FromStr;
6
7use super::SpanRange;
8
9#[derive(Debug, Clone)]
11pub struct Literal {
12 pub span_range: SpanRange,
14 pub raw: String,
16 pub value: Value,
18}
19
20#[derive(Debug, Clone, Default)]
22pub struct Ident {
23 pub span_range: SpanRange,
25 pub raw: String,
27 pub to_string: String,
29}
30
31#[derive(Debug, Clone, Default)]
33pub struct Attribute {
34 pub span_range: SpanRange,
36 pub key: Ident,
38 pub value: Option<Literal>,
40}
41
42#[derive(Debug, Clone)]
44pub struct Property {
45 pub span_range: SpanRange,
47 pub key: Ident,
49 pub value: Literal,
51}
52
53#[derive(Debug, PartialEq, Eq, Clone)]
55pub enum Nullable {
56 NotNull,
57 Null,
58}
59
60#[derive(Debug, PartialEq, Clone)]
62pub enum Value {
63 Enum(String),
64 String(String),
65 Integer(i64),
66 Decimal(f64),
67 Bool(bool),
68 HexColor(String),
69 Expr(String),
70 Null,
71}
72
73impl FromStr for Value {
74 type Err = ();
75
76 fn from_str(s: &str) -> Result<Self, Self::Err> {
77 match s {
78 "true" => Ok(Value::Bool(true)),
79 "false" => Ok(Value::Bool(false)),
80 "null" => Ok(Value::Null),
81 _ => Err(()),
82 }
83 }
84}
85
86impl ToString for Value {
87 fn to_string(&self) -> String {
88 match self {
89 Self::Enum(v) => v.clone(),
90 Self::String(v) => v.clone(),
91 Self::Integer(v) => format!("{v}"),
92 Self::Decimal(v) => format!("{v}"),
93 Self::Bool(v) => format!("{v}"),
94 Self::HexColor(v) => v.clone(),
95 Self::Expr(v) => v.clone(),
96 Self::Null => "null".to_string(),
97 }
98 }
99}
100
101#[derive(Debug, Clone)]
103pub struct NoteBlock {
104 pub span_range: SpanRange,
106 pub value: Literal,
108}