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 fmt;
53pub mod interpreter;
54pub mod ir;
55pub mod lexer;
56pub mod lint;
57pub mod lower;
58pub mod optimize;
59pub mod parser;
60pub mod plurality;
61pub mod span;
62pub mod stdlib;
63pub mod tome;
64pub mod tree_sitter_support;
65pub mod typeck;
66
67#[cfg(feature = "jit")]
68pub mod codegen;
69
70#[cfg(feature = "llvm")]
71pub mod llvm_codegen;
72
73#[cfg(feature = "wasm")]
74pub mod wasm;
75
76#[cfg(feature = "protocol-core")]
77pub mod protocol;
78
79#[cfg(feature = "lsp")]
80pub mod lsp;
81
82pub use ast::*;
83pub use diagnostic::{Diagnostic, DiagnosticBuilder, Diagnostics, FixSuggestion, Severity};
84pub use interpreter::{Evidence, Function, Interpreter, RuntimeError, Value};
85pub use ir::{IrDumpOptions, IrEvidence, IrFunction, IrModule, IrOperation, IrType};
86pub use lexer::{Lexer, Token};
87pub use lint::{
88    apply_fixes,
89    collect_sigil_files_filtered,
90    config_with_overrides,
91    explain_lint,
92    filter_ignored,
93    find_baseline,
94    find_cache,
95    generate_ci_annotations,
96    generate_html_report,
97    generate_pre_commit_hook,
98    generate_sarif,
99    generate_sarif_for_directory,
100    lint_and_fix,
101    lint_changed_files,
102    lint_changed_since,
103    lint_directory,
104    lint_directory_filtered,
105    lint_directory_incremental,
106    lint_directory_parallel,
107    lint_file,
108    lint_files,
109    lint_for_lsp,
110    lint_source,
111    lint_source_with_config,
112    lint_source_with_overrides,
113    lint_with_baseline,
114    lint_with_custom_rules,
115    list_lints,
116    parse_suppressions,
117    save_html_report,
118    watch_directory,
119    // Phase 7: Baseline support, CLI overrides, caching
120    Baseline,
121    BaselineEntry,
122    BaselineLintResult,
123    BaselineSummary,
124    CacheEntry,
125    CacheStats,
126    CachedDiagnostic,
127    CiFormat,
128    CliOverrides,
129    CustomPattern,
130    // Phase 10: Custom rules
131    CustomRule,
132    CustomRuleChecker,
133    CustomRuleMatch,
134    CustomRulesFile,
135    DirectoryLintResult,
136    FixResult,
137    // Phase 9: Git integration
138    GitIntegration,
139    // Phase 11: Ignore patterns
140    IgnorePatterns,
141    IncrementalLintResult,
142    LintCache,
143    LintCategory,
144    LintConfig,
145    LintConfigFile,
146    LintId,
147    LintLevel,
148    // Phase 12: HTML reports and trend tracking
149    LintReport,
150    LintSettings,
151    LintStats,
152    Linter,
153    LspCodeAction,
154    LspDiagnostic,
155    LspLintResult,
156    LspRelatedInfo,
157    LspServerState,
158    // Phase 8: LSP support
159    LspSeverity,
160    LspTextEdit,
161    SarifReport,
162    // Phase 6: Suppressions, SARIF, Stats, Explain
163    Suppression,
164    TrendData,
165    TrendDirection,
166    TrendSummary,
167    WatchConfig,
168    WatchResult,
169    CACHE_FILE,
170    PRE_COMMIT_HOOK,
171};
172pub use lower::lower_source_file;
173pub use optimize::{optimize, OptLevel, OptStats, Optimizer};
174pub use parser::Parser;
175pub use span::Span;
176pub use stdlib::register_stdlib;
177pub use typeck::{EvidenceLevel, Type, TypeChecker, TypeError};
178
179#[cfg(feature = "jit")]
180pub use codegen::JitCompiler;
181
182#[cfg(feature = "llvm")]
183pub use llvm_codegen::llvm::{CompileMode, LlvmCompiler};
184
185#[cfg(feature = "wasm")]
186pub use wasm::WasmCompiler;