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