Skip to main content

surrealguard_syntax/ast/
ty.rs

1//! Syntactic type expressions (`TYPE array<string>`, `option<int | string>`).
2//!
3//! These are *syntax*, deliberately independent of `surrealdb_types::Kind` —
4//! conversion to `Kind` is an analysis concern and lives in the workspace
5//! crate. Modeling this structurally closes the long-standing gap where
6//! `array<string>` fields degraded to `UnsupportedSyntax`.
7
8use super::{PartialNode, Spanned};
9
10/// A syntactic type expression, kept independent of `surrealdb_types::Kind`.
11#[derive(Clone, Debug, PartialEq)]
12pub enum TypeExpr {
13    /// `string`, `int`, `record`, ...
14    Name(Spanned<String>),
15    /// `array<string>`, `record<user>`, `set<int, 5>`, ...
16    Parameterized {
17        /// The base type constructor (`array`, `record`, `set`, ...).
18        name: Spanned<String>,
19        /// The type arguments inside `<...>`.
20        args: Vec<Spanned<TypeExpr>>,
21    },
22    /// `int | string`
23    Union(Vec<Spanned<TypeExpr>>),
24    /// `option<...>` sugar and the grammar's optional marker.
25    Optional(Box<Spanned<TypeExpr>>),
26    /// A literal type: `'active'`, `42`, `true` — usually inside unions.
27    Literal(crate::ast::Literal),
28    /// An object type: `{ name: string, age: int }` — each property maps a
29    /// name to its own type expression.
30    Object(Vec<(Spanned<String>, Spanned<TypeExpr>)>),
31    /// Other unmodeled type syntax: explicit, never dropped.
32    Partial(PartialNode),
33}