dbml_rs/lib.rs
1#![forbid(unsafe_code)]
2#![forbid(clippy::all)]
3#![no_std]
4
5use ast::SchemaBlock;
6use pest::error::Error as ParseError;
7
8extern crate derive_more;
9
10#[macro_use]
11extern crate pest_derive;
12
13#[macro_use]
14extern crate alloc;
15
16pub(crate) mod analyzer;
17pub mod ast;
18pub(crate) mod parser;
19#[cfg(not(feature = "utils"))]
20pub(crate) mod utils;
21#[cfg(feature = "utils")]
22pub mod utils;
23
24use analyzer::*;
25pub use parser::parse as parse_dbml_unchecked;
26
27/// Default database schema if not specified in a DBML file.
28pub const DEFAULT_SCHEMA: &str = "public";
29
30/// Parses the given text input and performs a semantics check.
31///
32/// # Arguments
33///
34/// * `input` - A reference to a string containing the text content to be parsed.
35///
36/// # Returns
37///
38/// Returns a `Result` where:
39/// - If parsing and semantic analysis are successful, it contains the resulting `analyzer::SemanticSchemaBlock`.
40/// - If an error occurs during parsing or analysis, it contains a `ParseError` indicating the specific issue.
41///
42/// # Examples
43///
44/// ```rs
45/// use your_crate_name::{parse_dbml, ParseError};
46///
47/// let content = "example content";
48/// match parse_dbml(content) {
49/// Ok(sem_ast) => {
50/// // Successfully parsed and analyzed content.
51/// // Work with the semantic analysis result (sem_ast) here.
52/// }
53/// Err(parse_error) => {
54/// // Handle the parsing error.
55/// eprintln!("Parsing error: {:?}", parse_error);
56/// }
57/// }
58/// ```
59pub fn parse_dbml(input: &str) -> Result<SchemaBlock, ParseError<parser::Rule>> {
60 let ast = parse_dbml_unchecked(input)?;
61
62 analyze(&ast).map(|_| ast)
63}