sigil_parser/
lib.rs

1//! Sigil Parser Library
2//!
3//! A polysynthetic programming language with evidentiality types.
4//!
5//! This crate provides:
6//! - Lexer and parser for Sigil source code
7//! - Tree-walking interpreter for development/debugging
8//! - JIT compiler using Cranelift for native performance
9//! - Comprehensive optimization passes (O0-O3)
10//! - Rich diagnostic reporting with colored output
11//! - AI-facing IR for tooling and agent integration
12
13use std::sync::atomic::{AtomicBool, Ordering};
14
15/// Global verbose flag for debug output control.
16/// Set via `set_verbose(true)` or `--verbose` CLI flag.
17static VERBOSE: AtomicBool = AtomicBool::new(false);
18
19/// Enable or disable verbose debug output.
20pub fn set_verbose(enabled: bool) {
21    VERBOSE.store(enabled, Ordering::SeqCst);
22}
23
24/// Check if verbose mode is enabled.
25pub fn is_verbose() -> bool {
26    VERBOSE.load(Ordering::SeqCst)
27}
28
29/// Print debug message only when verbose mode is enabled.
30#[macro_export]
31macro_rules! sigil_debug {
32    ($($arg:tt)*) => {
33        if $crate::is_verbose() {
34            eprintln!($($arg)*);
35        }
36    };
37}
38
39/// Print warning message only when verbose mode is enabled.
40#[macro_export]
41macro_rules! sigil_warn {
42    ($($arg:tt)*) => {
43        if $crate::is_verbose() {
44            eprintln!($($arg)*);
45        }
46    };
47}
48
49pub mod ast;
50pub mod diagnostic;
51pub mod ffi;
52pub mod interpreter;
53pub mod ir;
54pub mod lexer;
55pub mod lint;
56pub mod lower;
57pub mod optimize;
58pub mod parser;
59pub mod plurality;
60pub mod span;
61pub mod stdlib;
62pub mod tree_sitter_support;
63pub mod typeck;
64
65#[cfg(feature = "jit")]
66pub mod codegen;
67
68#[cfg(feature = "llvm")]
69pub mod llvm_codegen;
70
71#[cfg(feature = "wasm")]
72pub mod wasm;
73
74#[cfg(feature = "protocol-core")]
75pub mod protocol;
76
77pub use ast::*;
78pub use diagnostic::{Diagnostic, DiagnosticBuilder, Diagnostics, FixSuggestion, Severity};
79pub use interpreter::{Evidence, Function, Interpreter, RuntimeError, Value};
80pub use ir::{IrDumpOptions, IrEvidence, IrFunction, IrModule, IrOperation, IrType};
81pub use lexer::{Lexer, Token};
82pub use lint::{
83    apply_fixes,
84    collect_sigil_files_filtered,
85    config_with_overrides,
86    explain_lint,
87    filter_ignored,
88    find_baseline,
89    find_cache,
90    generate_ci_annotations,
91    generate_html_report,
92    generate_pre_commit_hook,
93    generate_sarif,
94    generate_sarif_for_directory,
95    lint_and_fix,
96    lint_changed_files,
97    lint_changed_since,
98    lint_directory,
99    lint_directory_filtered,
100    lint_directory_incremental,
101    lint_directory_parallel,
102    lint_file,
103    lint_files,
104    lint_for_lsp,
105    lint_source,
106    lint_source_with_config,
107    lint_source_with_overrides,
108    lint_with_baseline,
109    lint_with_custom_rules,
110    list_lints,
111    parse_suppressions,
112    save_html_report,
113    watch_directory,
114    // Phase 7: Baseline support, CLI overrides, caching
115    Baseline,
116    BaselineEntry,
117    BaselineLintResult,
118    BaselineSummary,
119    CacheEntry,
120    CacheStats,
121    CachedDiagnostic,
122    CiFormat,
123    CliOverrides,
124    CustomPattern,
125    // Phase 10: Custom rules
126    CustomRule,
127    CustomRuleChecker,
128    CustomRuleMatch,
129    CustomRulesFile,
130    DirectoryLintResult,
131    FixResult,
132    // Phase 9: Git integration
133    GitIntegration,
134    // Phase 11: Ignore patterns
135    IgnorePatterns,
136    IncrementalLintResult,
137    LintCache,
138    LintCategory,
139    LintConfig,
140    LintConfigFile,
141    LintId,
142    LintLevel,
143    // Phase 12: HTML reports and trend tracking
144    LintReport,
145    LintSettings,
146    LintStats,
147    Linter,
148    LspCodeAction,
149    LspDiagnostic,
150    LspLintResult,
151    LspRelatedInfo,
152    LspServerState,
153    // Phase 8: LSP support
154    LspSeverity,
155    LspTextEdit,
156    SarifReport,
157    // Phase 6: Suppressions, SARIF, Stats, Explain
158    Suppression,
159    TrendData,
160    TrendDirection,
161    TrendSummary,
162    WatchConfig,
163    WatchResult,
164    CACHE_FILE,
165    PRE_COMMIT_HOOK,
166};
167pub use lower::lower_source_file;
168pub use optimize::{optimize, OptLevel, OptStats, Optimizer};
169pub use parser::Parser;
170pub use span::Span;
171pub use stdlib::register_stdlib;
172pub use typeck::{EvidenceLevel, Type, TypeChecker, TypeError};
173
174#[cfg(feature = "jit")]
175pub use codegen::JitCompiler;
176
177#[cfg(feature = "llvm")]
178pub use llvm_codegen::llvm::{CompileMode, LlvmCompiler};
179
180#[cfg(feature = "wasm")]
181pub use wasm::WasmCompiler;