Skip to main content

rune_cfg/
lib.rs

1// Author: Dustin
2// License: MIT
3
4//! # rune-cfg
5//!
6//! A minimal, powerful configuration language with native regex support.
7//!
8//! ## Features
9//!
10//! - **Clean syntax** - Minimal and readable, no complex indentation rules
11//! - **Native regex** - First-class regex support with `r"pattern"` syntax
12//! - **Conditionals** - Simple `if/else` for dynamic configurations
13//! - **Type safety** - Strong typing with comprehensive error messages
14//! - **System integration** - Access environment variables with `$env` and system info with `$sys`
15//! - **Flexible keys** - Automatic `snake_case` and `kebab-case` handling
16//!
17//! ## Quick Example
18//!
19//! ```rune
20//! # config.rune
21//! @author "Your Name"
22//! @description "Application config"
23//!
24//! environment "production"
25//! debug false
26//!
27//! database:
28//!   host if environment = "production" "prod.db.com" else "localhost"
29//!   port 5432
30//!   timeout 30
31//! end
32//!
33//! allowed_ips [
34//!   r"192\.168\.1\.\d+"
35//!   r"10\.0\.0\.\d+"
36//! ]
37//!
38//! server:
39//!   user $env.USER
40//!   home $env.HOME
41//!   hostname $sys.hostname
42//!   cpu_count $sys.cpu_count
43//! end
44//! ```
45//!
46//! ## Usage
47//!
48//! ```no_run
49//! use rune_cfg::RuneConfig;
50//!
51//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
52//! let config = RuneConfig::from_file("config.rune")?;
53//!
54//! let db_host: String = config.get("database.host")?;
55//! let db_port: u16 = config.get("database.port")?;
56//! let debug: bool = config.get("debug")?;
57//!
58//! let allowed_ips = config.get_value("allowed_ips")?;
59//! for ip in &["192.168.1.100", "10.0.0.50", "172.16.0.1"] {
60//!     if allowed_ips.matches(ip) {
61//!         println!("{} is allowed", ip);
62//!     }
63//! }
64//! # Ok(())
65//! # }
66//! ```
67//!
68//! ## Syntax Guide
69//!
70//! ### Basic Values
71//! ```rune
72//! name "value"
73//! port 8080
74//! enabled true
75//! timeout 30.5
76//! nothing null
77//! ```
78//!
79//! ### Objects
80//! ```rune
81//! server:
82//!   host "localhost"
83//!   port 8080
84//! end
85//! ```
86//!
87//! ### Arrays
88//! ```rune
89//! ports [80, 443, 8080]
90//! hosts ["localhost", "example.com"]
91//! ```
92//!
93//! ### Regex Patterns
94//! ```rune
95//! email_pattern r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
96//! ip_pattern r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
97//! ```
98//!
99//! ### Conditionals
100//! ```rune
101//! environment "production"
102//! db_host if environment = "production" "prod.db.com" else "localhost"
103//! workers if sys.cpu_count = "8" 8 else 4
104//! ```
105//!
106//! ### Environment Variables
107//! ```rune
108//! user $env.USER
109//! home $env.HOME
110//! path $env.PATH
111//! ```
112//!
113//! ### System Information
114//! ```rune
115//! os $sys.os
116//! hostname $sys.hostname
117//! cpu_count $sys.cpu_count
118//! memory_total $sys.memory_total
119//! kernel_version $sys.kernel_version
120//! ```
121//!
122//! ### Metadata
123//! ```rune
124//! @author "Your Name"
125//! @version "1.0.0"
126//! @description "Config file"
127//! ```
128//!
129//! ### Imports
130//! ```rune
131//! gather "defaults.rune" as defaults
132//!
133//! server:
134//!   host defaults.server.host
135//!   port defaults.server.port
136//! end
137//! ```
138//!
139//! ## Error Handling
140//!
141//! All errors include line numbers and helpful hints:
142//!
143//! ```text
144//! Error: Invalid regex pattern: unclosed character class
145//!   → Line 15: pattern r"[a-z"
146//! Hint: Check your regex syntax
147//! ```
148
149pub mod ast;
150pub mod error;
151pub mod export;
152pub mod lexer;
153pub mod parser;
154pub mod resolver;
155pub mod utils;
156pub mod config;
157
158pub use ast::{Document, Value};
159pub use error::RuneError;
160pub use config::RuneConfig;