Skip to content

Commit b07ce5f

Browse files
author
devsamikhan
committed
feat(language): add functional pipelines, comptime, async/await, context managers, native regex, formatter, linter & fuzzy diagnostics
1 parent ea434ec commit b07ce5f

14 files changed

Lines changed: 2080 additions & 11 deletions
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// ==============================================================================
2+
// AETHER Language Showcase: Functional Pipelines, Comptime, Async/Await & Task,
3+
// Context Managers & LIFO Defer, Native Regex, Diagnostics, Formatter & Linter
4+
// ==============================================================================
5+
6+
print("=== 1. Functional Collection Pipeline Methods ===")
7+
let raw_scores = [45, 92, 78, 92, 60, 88, 100, 45]
8+
let top_bonus_total = raw_scores.unique().sort().filter(|s| s >= 80).map(|s| s + 5).reduce(0, |acc, s| acc + s)
9+
print("Top bonus total:", top_bonus_total)
10+
11+
print("\n=== 2. Compile-Time Execution (comptime) & Macros ===")
12+
macro cube(n) {
13+
n * n * n
14+
}
15+
let FIB_TABLE = comptime {
16+
let mut seq = [0, 1]
17+
for i in 2..=8 {
18+
seq.push(seq[i - 1] + seq[i - 2])
19+
}
20+
seq
21+
}
22+
print("Precomputed FIB_TABLE at compile time:", FIB_TABLE)
23+
print("macro cube(4):", cube(4))
24+
25+
print("\n=== 3. Async / Await & Structured Task Concurrency ===")
26+
async fn compute_metric(n) {
27+
return n * n + 10
28+
}
29+
let t1 = Task.spawn(compute_metric, 6)
30+
let t2 = Task.spawn(compute_metric, 9)
31+
let results = Task.all([t1, t2])
32+
print("Task.all results:", results)
33+
34+
print("\n=== 4. Deterministic Resource Management (with ... as ... & LIFO defer) ===")
35+
let events = []
36+
class Session {
37+
fn __init__(self, id) {
38+
self.id = id
39+
}
40+
fn __enter__(self) {
41+
events.push("open:" + self.id)
42+
return self
43+
}
44+
fn __exit__(self) {
45+
events.push("close:" + self.id)
46+
}
47+
}
48+
49+
fn process_request() {
50+
defer events.push("cleanup:outer")
51+
defer events.push("cleanup:inner")
52+
with Session("sess-01") as s {
53+
events.push("query:" + s.id)
54+
}
55+
return "done"
56+
}
57+
let _ = process_request()
58+
print("Lifecycle trace:", events.join(" -> "))
59+
60+
print("\n=== 5. Native Zero-Dependency Regex Engine ===")
61+
let log_line = "2026-10-23 [ERROR] User #4091 failed login from 10.0.0.12"
62+
print("Regex is_match:", Regex.is_match("^2026-[0-9]{2}-[0-9]{2}", log_line))
63+
print("Regex find:", Regex.find("#[0-9]+", log_line))
64+
print("Regex replace_all:", Regex.replace_all("[0-9]+", log_line, "X"))
65+
66+
print("\n=== 6. Built-in Code Formatter, Linter & Fuzzy Diagnostics ===")
67+
let sample_code = "fn demo(a){\nlet unused_var = 42\nreturn a+1\n}\n"
68+
print("Linter warnings:", Linter.lint(sample_code))
69+
print("Fuzzy suggestion for 'prnt':", Diagnostics.suggest("prnt", ["print", "println", "len"]))

‎src/lsp.rs‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,30 @@ impl AetherLanguageServer {
3636
pub fn analyze(&self, source: &str) -> Vec<LspDiagnostic> {
3737
let mut diagnostics = Vec::new();
3838

39-
// 1. Syntax Parsing Pass
39+
// 1. Syntax Parsing Pass + Semantic Type & Security Checks
4040
match crate::syntax::parse(source) {
41-
Ok(_) => {
42-
// Syntax valid - can perform semantic and contract checks
41+
Ok(program) => {
42+
// Static Type & Trait Completeness Check
43+
let mut checker = crate::types::checker::TypeChecker::new();
44+
if let Err(type_errs) = checker.check_program(&program) {
45+
for msg in type_errs {
46+
diagnostics.push(LspDiagnostic {
47+
line: 0,
48+
col: 0,
49+
message: format!("Type error: {}", msg),
50+
severity: 2, // Warning
51+
});
52+
}
53+
}
54+
// Static Security Taint & Vulnerability Check
55+
for finding in crate::vm::security::scan_program_security(&program) {
56+
diagnostics.push(LspDiagnostic {
57+
line: finding.line.saturating_sub(1),
58+
col: 0,
59+
message: format!("[{}] {}: {}", finding.severity, finding.category, finding.message),
60+
severity: 2,
61+
});
62+
}
4363
}
4464
Err((err_msg, span)) => {
4565
diagnostics.push(LspDiagnostic {

‎src/syntax/ast.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ pub enum Statement {
130130
stmt: Box<Statement>,
131131
span: Span,
132132
},
133+
With {
134+
resource: Expr,
135+
alias: Option<String>,
136+
body: Block,
137+
span: Span,
138+
},
133139
Expr(Expr),
134140
}
135141

@@ -186,6 +192,7 @@ impl Statement {
186192
Statement::ImplDef { span, .. } => *span,
187193
Statement::TypeAlias { span, .. } => *span,
188194
Statement::Decorated { span, .. } => *span,
195+
Statement::With { span, .. } => *span,
189196
Statement::Expr(expr) => expr.span(),
190197
}
191198
}
@@ -276,6 +283,8 @@ pub enum Expr {
276283
step: Option<Box<Expr>>,
277284
span: Span,
278285
},
286+
Await(Box<Expr>, Span),
287+
Comptime(Block, Span),
279288
}
280289

281290
#[derive(Debug, Clone, PartialEq)]
@@ -336,6 +345,8 @@ impl Expr {
336345
Expr::OptionalIndex(_, _, s) => *s,
337346
Expr::Try(_, s) => *s,
338347
Expr::Slice { span, .. } => *span,
348+
Expr::Await(_, s) => *s,
349+
Expr::Comptime(_, s) => *s,
339350
}
340351
}
341352
}

0 commit comments

Comments
 (0)