nautilus-orm-schema 0.1.3

Schema parsing and validation for Nautilus ORM
Documentation
//! Nautilus Schema Parser and Validator
//!
//! This crate provides end-to-end processing of `.nautilus` schema files.
//!
//! # Pipeline
//!
//! Processing a schema runs in four stages:
//! - **Lexer** — converts source text into typed tokens with span tracking.
//! - **Parser** — builds a syntax [`ast::Schema`] via recursive descent.
//! - **Validator** — performs multi-pass semantic validation and emits a fully
//!   resolved [`ir::SchemaIr`].
//! - **Formatter** — renders an AST back to canonical source text.
//!
//! # Quick Start
//!
//! The [`analyze`] function runs the full pipeline in one call and collects all
//! diagnostics:
//!
//! ```ignore
//! use nautilus_schema::analyze;
//!
//! let result = analyze(source);
//! for diag in &result.diagnostics {
//!     eprintln!("{:?} — {}", diag.severity, diag.message);
//! }
//! if let Some(ir) = &result.ir {
//!     println!("{} models validated", ir.models.len());
//! }
//! ```
//!
//! # Visitor Pattern
//!
//! The [`visitor`] module provides a trait-based visitor for flexible AST traversal:
//!
//! ```ignore
//! use nautilus_schema::{visitor::{Visitor, walk_model}, ast::*, Result};
//!
//! struct ModelCounter { count: usize }
//!
//! impl Visitor for ModelCounter {
//!     fn visit_model(&mut self, model: &ModelDecl) -> Result<()> {
//!         self.count += 1;
//!         walk_model(self, model)
//!     }
//! }
//! ```

#![warn(missing_docs)]
#![forbid(unsafe_code)]

pub mod analysis;
pub mod ast;
pub mod bool_expr;
pub mod diagnostic;
mod error;
pub mod formatter;
pub mod ir;
mod lexer;
pub mod parser;
mod span;
pub mod sql_expr;
mod token;
mod validator;
pub mod visitor;

pub use analysis::{
    analyze, completion, goto_definition, hover, semantic_tokens, AnalysisResult, CompletionItem,
    CompletionKind, HoverInfo, SemanticKind, SemanticToken,
};
pub use ast::ComputedKind;
pub use diagnostic::{Diagnostic, Severity};
pub use error::{Result, SchemaError};
pub use formatter::format_schema;
pub use lexer::Lexer;
pub use parser::Parser;
pub use span::{Position, Span};
pub use token::{Token, TokenKind};
pub use validator::validate_schema;

/// Resolve `env(VAR_NAME)` syntax in a connection URL.
///
/// If `raw` matches the pattern `env(...)`, the value of the named
/// environment variable is returned.  Otherwise `raw` is returned as-is.
pub fn resolve_env_url(raw: &str) -> std::result::Result<String, String> {
    if raw.starts_with("env(") && raw.ends_with(')') {
        let var = &raw[4..raw.len() - 1];
        std::env::var(var).map_err(|_| format!("environment variable '{}' is not set", var))
    } else {
        Ok(raw.to_string())
    }
}