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 typeck;
63pub mod tree_sitter_support;
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    lint_file, lint_source, lint_source_with_config, lint_directory, lint_directory_parallel,
84    lint_and_fix, apply_fixes, watch_directory,
85    LintConfig, LintConfigFile, LintSettings, LintId, LintLevel, LintCategory, Linter,
86    DirectoryLintResult, FixResult, WatchConfig, WatchResult,
87    // Phase 6: Suppressions, SARIF, Stats, Explain
88    Suppression, parse_suppressions, LintStats,
89    SarifReport, generate_sarif, generate_sarif_for_directory,
90    explain_lint, list_lints,
91    // Phase 7: Baseline support, CLI overrides, caching
92    Baseline, BaselineEntry, BaselineSummary, BaselineLintResult,
93    find_baseline, lint_with_baseline,
94    CliOverrides, config_with_overrides, lint_source_with_overrides,
95    LintCache, CacheEntry, CachedDiagnostic, CacheStats, IncrementalLintResult,
96    find_cache, lint_directory_incremental, CACHE_FILE,
97    // Phase 8: LSP support
98    LspSeverity, LspDiagnostic, LspRelatedInfo, LspCodeAction, LspTextEdit,
99    LspLintResult, LspServerState, lint_for_lsp,
100    // Phase 9: Git integration
101    GitIntegration, lint_changed_files, lint_changed_since, lint_files,
102    generate_pre_commit_hook, PRE_COMMIT_HOOK,
103    // Phase 10: Custom rules
104    CustomRule, CustomPattern, CustomRulesFile, CustomRuleMatch, CustomRuleChecker,
105    lint_with_custom_rules,
106    // Phase 11: Ignore patterns
107    IgnorePatterns, filter_ignored, collect_sigil_files_filtered, lint_directory_filtered,
108    // Phase 12: HTML reports and trend tracking
109    LintReport, TrendData, TrendDirection, TrendSummary,
110    generate_html_report, save_html_report, CiFormat, generate_ci_annotations,
111};
112pub use lower::lower_source_file;
113pub use optimize::{optimize, OptLevel, OptStats, Optimizer};
114pub use parser::Parser;
115pub use span::Span;
116pub use stdlib::register_stdlib;
117pub use typeck::{EvidenceLevel, Type, TypeChecker, TypeError};
118
119#[cfg(feature = "jit")]
120pub use codegen::JitCompiler;
121
122#[cfg(feature = "llvm")]
123pub use llvm_codegen::llvm::{CompileMode, LlvmCompiler};
124
125#[cfg(feature = "wasm")]
126pub use wasm::WasmCompiler;