ron_schema/ron/mod.rs
1/*************************
2 * Author: Bradley Hunter
3 */
4
5use crate::{Span, Spanned};
6/// RON data parser — converts `.ron` source text into a spanned [`RonValue`] tree.
7pub mod parser;
8
9/// A parsed RON data value, preserving bare identifiers for enum validation.
10#[derive(Debug, Clone, PartialEq)]
11pub enum RonValue {
12 /// A quoted string (e.g., `"Ashborn Hound"`).
13 String(String),
14 /// A whole number (e.g., `42`, `-1`).
15 Integer(i64),
16 /// A floating-point number (e.g., `3.14`, `1.0`).
17 Float(f64),
18 /// A boolean (`true` or `false`).
19 Bool(bool),
20 /// `Some(value)` or `None`. The inner value carries its own span for precise error reporting.
21 Option(Option<Box<Spanned<RonValue>>>),
22 /// A bare identifier (e.g., `Creature`, `Sentinels`). Preserved for enum variant validation.
23 Identifier(String),
24 /// An enum variant with associated data (e.g., `Damage(5)`).
25 EnumVariant(String, Box<Spanned<RonValue>>),
26 /// A list of values (e.g., `[Creature, Trap]`). Each element carries its own span.
27 List(Vec<Spanned<RonValue>>),
28 /// A map of key-value pairs (e.g., `{ "str": 5, "dex": 3 }`). Each key and value carries its own span.
29 Map(Vec<(Spanned<RonValue>, Spanned<RonValue>)>),
30 /// A positional tuple (e.g., `(1.0, 2.5)`). Each element carries its own span.
31 Tuple(Vec<Spanned<RonValue>>),
32 /// A struct with named fields (e.g., `(name: "foo", age: 5)`).
33 Struct(RonStruct),
34}
35
36/// A parsed RON struct containing ordered field name-value pairs.
37#[derive(Debug, Clone, PartialEq)]
38pub struct RonStruct {
39 /// Field name-value pairs in declaration order. Both names and values carry spans.
40 pub fields: Vec<(Spanned<String>, Spanned<RonValue>)>,
41 /// Source location of the closing `)`, used as the anchor for missing field errors.
42 pub close_span: Span,
43}