ferriorm_parser/lib.rs
1//! Schema parser for `.ferriorm` files.
2//!
3//! This crate turns a `.ferriorm` schema string into a fully validated
4//! [`ferriorm_core::schema::Schema`] IR. It operates in two phases:
5//!
6//! 1. **Parsing** ([`parser`]) -- a PEG grammar (defined in `grammar.pest`)
7//! tokenizes the input and builds a raw [`ferriorm_core::ast::SchemaFile`].
8//! 2. **Validation** ([`validator`]) -- resolves types, checks constraints,
9//! and produces the canonical [`ferriorm_core::schema::Schema`] consumed by
10//! codegen and the migration engine.
11//!
12//! For convenience, [`parse_and_validate`] combines both steps.
13//!
14//! # Related crates
15//!
16//! - `ferriorm_core` -- domain types produced by this crate.
17//! - `ferriorm_codegen` -- consumes the `Schema` IR to generate Rust code.
18//! - `ferriorm_migrate` -- consumes the `Schema` IR to produce migrations.
19
20pub mod error;
21pub mod parser;
22pub mod validator;
23
24pub use parser::parse;
25pub use validator::validate;
26
27/// Parse and validate a schema file in one step.
28pub fn parse_and_validate(
29 source: &str,
30) -> Result<ferriorm_core::schema::Schema, error::ParseError> {
31 let ast = parse(source)?;
32 validate(&ast).map_err(|e| error::ParseError::Validation(e.to_string()))
33}