#![forbid(unsafe_code)]
#![warn(missing_docs, clippy::pedantic)]
pub mod ast;
mod errors;
mod grammar;
mod lower;
pub mod naming;
mod validate;
use ruprizzle_core::diagnostic::{Diagnostics, SchemaErrors};
use ruprizzle_core::ir::Schema;
pub use ast::Ast;
pub fn parse(file_name: &str, source: &str) -> Result<Schema, Box<SchemaErrors>> {
parse_with_warnings(file_name, source).map(|(schema, _)| schema)
}
pub fn parse_with_warnings(
file_name: &str,
source: &str,
) -> Result<(Schema, Vec<ruprizzle_core::SchemaError>), Box<SchemaErrors>> {
let mut diags = Diagnostics::new();
let ast = match grammar::parse_ast(source) {
Ok(ast) => ast,
Err(err) => {
diags.push(errors::from_pest(&err, source));
diags.into_result(file_name, source)?;
unreachable!("a syntax error is always fatal");
}
};
let schema = lower::lower(&ast, &mut diags);
let warnings = diags.take_warnings();
diags.into_result(file_name, source)?;
Ok((schema, warnings))
}
pub fn parse_ast(file_name: &str, source: &str) -> Result<Ast, Box<SchemaErrors>> {
grammar::parse_ast(source).map_err(|err| {
let mut diags = Diagnostics::new();
diags.push(errors::from_pest(&err, source));
diags
.into_result(file_name, source)
.expect_err("a syntax error is fatal")
})
}