Skip to main content

Crate nautilus_schema

Crate nautilus_schema 

Source
Expand description

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:

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:

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)
    }
}

Re-exports§

pub use analysis::analyze;
pub use analysis::completion;
pub use analysis::completion;
pub use analysis::completion_with_analysis;
pub use analysis::goto_definition;
pub use analysis::goto_definition;
pub use analysis::goto_definition_with_analysis;
pub use analysis::hover;
pub use analysis::hover;
pub use analysis::hover_with_analysis;
pub use analysis::semantic_tokens;
pub use analysis::semantic_tokens;
pub use analysis::AnalysisResult;
pub use analysis::CompletionItem;
pub use analysis::CompletionKind;
pub use analysis::HoverInfo;
pub use analysis::SemanticKind;
pub use analysis::SemanticToken;
pub use ast::ComputedKind;
pub use diagnostic::Diagnostic;
pub use diagnostic::Severity;
pub use formatter::format_schema;
pub use parser::Parser;

Modules§

analysis
Top-level analysis API for .nautilus schema files.
ast
Abstract Syntax Tree (AST) for the nautilus schema language.
bool_expr
Boolean expression parser for @check and @@check constraint attributes.
diagnostic
Diagnostic types for the analysis API.
formatter
Formatter: converts a Schema AST back to canonical .nautilus source text.
ir
Intermediate representation (IR) of a validated schema.
parser
Recursive descent parser for the nautilus schema language.
sql_expr
Lightweight SQL expression parser for @computed and future attribute expressions.
visitor
Visitor pattern for traversing the AST.

Structs§

Lexer
Lexer for tokenizing schema source code.
ParsedSchema
Parsed schema plus any non-fatal parse errors recovered during parsing.
Position
A position in source code (line and column).
Span
A span in source code (byte offsets).
Token
A token in the schema language.
ValidatedSchema
Parsed AST together with the validated IR.

Enums§

SchemaError
Error type for schema operations.
TokenKind
Token kinds for the schema language.

Functions§

parse_schema_source
Parse a schema source string strictly, failing if the parser had to recover.
parse_schema_source_with_recovery
Parse a schema source string and return the AST plus parser recovery errors.
resolve_env_url
Resolve env(VAR_NAME) syntax in a connection URL.
validate_schema
Validates a schema AST and produces a validated IR.
validate_schema_source
Parse and validate a schema source string.

Type Aliases§

Result
Result type alias for schema operations.