Skip to main content

xlog_logic/
lib.rs

1//! Datalog frontend for XLOG
2#![warn(missing_docs)]
3//!
4//! This crate provides the parsing, analysis, and compilation pipeline
5//! for XLOG Datalog programs.
6//!
7//! # Main Entry Point
8//!
9//! The primary way to use this crate is through the [`Compiler`] struct:
10//!
11//! ```ignore
12//! use xlog_logic::Compiler;
13//!
14//! let mut compiler = Compiler::new();
15//! let plan = compiler.compile(r#"
16//!     edge(1, 2).
17//!     edge(2, 3).
18//!     reach(X, Y) :- edge(X, Y).
19//!     reach(X, Z) :- reach(X, Y), edge(Y, Z).
20//! "#)?;
21//! ```
22//!
23//! # Modules
24//!
25//! - [`parser`] - Pest-based parser for XLOG syntax
26//! - [`ast`] - Abstract Syntax Tree types
27//! - [`mod@stratify`] - Stratification analysis for negation/aggregation
28//! - [`lower`] - Lowering from AST to Relational IR
29//! - [`mod@compile`] - Full compilation pipeline
30
31pub mod arithmetic_eval;
32pub mod ast;
33pub mod compile;
34pub mod compiler_config;
35pub mod diagnostics;
36pub mod eir;
37pub mod epistemic;
38pub mod expand;
39mod fact_fast_path;
40pub mod function;
41pub mod ground_term_encoding;
42pub mod hypergraph;
43pub mod incremental_parse;
44pub mod list_normalize;
45pub mod lower;
46pub mod magic_sets;
47pub mod meta_normalize;
48pub mod module;
49pub mod module_diagnostics;
50pub mod optimizer;
51pub mod parser;
52pub mod promote;
53pub mod proof_trace;
54pub mod resolver;
55pub mod stratify;
56pub mod wcoj_var_ordering;
57
58// Re-export main types
59pub use arithmetic_eval::{
60    compare_arithmetic_values, evaluate_arithmetic_expression, ArithmeticValue,
61};
62pub use ast::{
63    AnnotatedDisjunction, Atom, BodyLiteral, Constraint, Directives, EpistemicLiteral,
64    EpistemicMode, EpistemicOp, Evidence, MagicSetsMode, ProbCache, ProbEngine, ProbFact,
65    ProbMethod, ProbQuery, Program, Query, Rule, Term, Univ,
66};
67pub use compile::{compile, Compiler};
68pub use diagnostics::{
69    build_query_proof_traces, build_rule_provenance, format_atom, format_constraint_body,
70    format_term, generated_function_variable_sources, query_proof_traces, rule_provenance,
71    source_diagnostics, source_format_normalized_alternative, QueryProofTrace, RuleProvenance,
72    RuleSourceKind,
73};
74pub use eir::build_eir;
75pub use expand::{expand_program_functions, expand_program_functions_owned};
76pub use incremental_parse::{
77    IncrementalParseResult, ParseCacheStats, ParserSession, StatementSpan, StatementUnit,
78};
79pub use list_normalize::{normalize_list_builtins, normalize_list_builtins_owned};
80pub use lower::Lowerer;
81pub use magic_sets::{
82    rewrite_magic_sets, rewrite_magic_sets_owned, MagicSetReport, MagicSetRewrite, MagicSetStatus,
83};
84pub use meta_normalize::{normalize_meta_builtins, normalize_meta_builtins_owned};
85pub use module_diagnostics::{
86    diagnose_module_boundaries, CandidateSourceKind, ModuleBoundaryInput, ModuleBoundaryReport,
87    ModuleDeclaration, ModuleDeclarationKind, ModuleManifest, ModuleRole, ModuleViolation,
88    ModuleViolationKind,
89};
90pub use optimizer::{Optimizer, OptimizerConfig, PlanCost};
91pub use parser::{parse_program, parse_statement};
92pub use proof_trace::{DifferentiableProofTraceMap, ProofTrace, ProofTraceSpec};
93pub use stratify::{find_sccs_for_lowering, stratify, DependencyGraph, Stratum};