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 /// A list of values (e.g., `[Creature, Trap]`). Each element carries its own span.
25 List(Vec<Spanned<RonValue>>),
26 /// A map of key-value pairs (e.g., `{ "str": 5, "dex": 3 }`). Each key and value carries its own span.
27 Map(Vec<(Spanned<RonValue>, Spanned<RonValue>)>),
28 /// A positional tuple (e.g., `(1.0, 2.5)`). Each element carries its own span.
29 Tuple(Vec<Spanned<RonValue>>),
30 /// A struct with named fields (e.g., `(name: "foo", age: 5)`).
31 Struct(RonStruct),
32}
33
34/// A parsed RON struct containing ordered field name-value pairs.
35#[derive(Debug, Clone, PartialEq)]
36pub struct RonStruct {
37 /// Field name-value pairs in declaration order. Both names and values carry spans.
38 pub fields: Vec<(Spanned<String>, Spanned<RonValue>)>,
39 /// Source location of the closing `)`, used as the anchor for missing field errors.
40 pub close_span: Span,
41}