Skip to content

Commit a5a09e0

Browse files
Claude/wokelang ebnf grammar qoe vv (#8)
* Implement WokeLang interpreter in Rust Complete implementation of WokeLang with: Lexer (src/lexer/): - Token definitions for all keywords, operators, literals - Uses logos for fast tokenization - Handles comments, strings with escapes, numbers Parser (src/parser/): - Recursive descent parser - Full expression parsing with correct precedence - All statement types: remember, when/otherwise, repeat, attempt safely - Pattern matching with decide based on - Emote tags, consent blocks, gratitude declarations AST (src/ast/): - Complete type definitions for all language constructs - Spanned nodes for error reporting Interpreter (src/interpreter/): - Tree-walking interpreter - Scoped environments for variables - Built-in functions: print, len, toString, toInt - Consent system with interactive prompts - Pattern matching evaluation - All operators (arithmetic, comparison, logical) CLI (src/main.rs): - woke <file.woke> - run program - woke --tokenize <file> - show tokens - woke --parse <file> - show AST Examples: - examples/hello.woke - feature showcase - examples/demo.woke - runnable demo * Add REPL, WASM compilation, and Zig FFI REPL (src/repl.rs): - Interactive command-line interface with rustyline - Commands: :help, :quit, :clear, :reset, :load, :ast - Expression evaluation with automatic result printing - Start with `woke` or `woke --repl` WASM Compilation (src/codegen/): - Compile WokeLang to WebAssembly binary format - Uses wasm-encoder for proper WASM generation - Supports functions, expressions, loops, conditionals - Pattern matching compilation - CLI: `woke -c input.woke` outputs input.wasm Zig FFI (src/ffi/, zig/, include/): - C-compatible API for embedding WokeLang - Interpreter lifecycle: woke_interpreter_new/free - Code execution: woke_exec, woke_eval - Value operations: type checking, conversion, creation - Static library (libwokelang.a) and shared library (.so) - C header (include/wokelang.h) - Zig bindings (zig/wokelang.zig) with idiomatic wrapper - Example Zig program and build.zig Other: - examples/math.woke - math functions for WASM demo - Cargo.toml updated for cdylib/staticlib targets * Add comprehensive documentation and wiki Includes: - Project roadmap (ROADMAP.md) with version timeline through v1.0 - Wiki home page with table of contents - Getting Started guides: Installation, Hello World, Basic Syntax, REPL - Language Guide: Functions, Control Flow, Error Handling, Variables/Types - Core Concepts: Consent System, Gratitude, Emote Tags - Reference: CLI, Built-in Functions, Keywords, Operators, Language Spec - Internals: Architecture, Lexer, Parser, Interpreter, WASM, FFI - Tutorial: Building a CLI app * Implement Phase 2 Language Completeness features - Add Result types (Okay/Oops) with pattern matching support - Implement error propagation operator (?) for Result types - Add pattern matching destructuring with guard clauses - Implement module system with use/share keywords - Add new builtins: isOkay, isOops, getOkay, getOops - Update WASM compiler and FFI for new AST variants - Add example programs for Result types and modules * Add static type inference with Hindley-Milner style checker - Implement TypeChecker module with type inference - Support for basic types: Int, Float, String, Bool, Unit - Support for compound types: Array, Result, Maybe, Function - Implement unification algorithm for type constraints - Add built-in function type handling - Include comprehensive test suite for type checking * Implement Phase 3 Worker System with message passing - Add async worker module with thread-based execution - Implement WorkerHandle, WorkerContext, WorkerPool - Add message passing: WorkerMessage enum with Value, Stop, Ping, etc. - Add cancellation tokens for task control - New lexer tokens: send, receive, channel, await, cancel, from - New AST nodes: SendMessage, ReceiveMessage, AwaitWorker, CancelWorker - Update parser for new worker syntax - Update interpreter with worker statement handling - Update WASM codegen and typechecker for new statements - Add worker tests (4 new tests) - Add workers.woke example demonstrating worker system - Update ROADMAP.md with Phase 2 completion status * Implement Phase 3 Security: capability-based security and persistent consent storage - Add CapabilityRegistry with support for FileRead, FileWrite, Execute, Network, Environment, Process, SystemInfo, Crypto, Clipboard, Notify capabilities - Implement wildcard capability matching (e.g., file:read:* grants all file reads) - Add audit logging for all capability requests, grants, denials, and revocations - Create ConsentStore for persistent storage of consent decisions - Support consent durations: Session, Day, Week, Forever, Once - Add security.woke example demonstrating superpower declarations --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 57339c9 commit a5a09e0

5 files changed

Lines changed: 1380 additions & 0 deletions

File tree

examples/security.woke

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Example: Capability-based Security (Superpowers) in WokeLang
2+
// Demonstrates permission requests and consent-driven operations
3+
4+
thanks to {
5+
"WokeLang" → "For security-first design";
6+
}
7+
8+
// Define a superpower for file operations
9+
superpower fileAccess {
10+
print("Requesting file access permission...");
11+
// In a real implementation, this would trigger a consent dialog
12+
}
13+
14+
// Define a superpower for network access
15+
superpower networkAccess {
16+
print("Requesting network access permission...");
17+
}
18+
19+
// Sensitive function that requires file read permission
20+
to readConfig() {
21+
only if okay "file:read:/etc/config" {
22+
print("Reading configuration file...");
23+
// File reading would happen here
24+
give back "config data";
25+
}
26+
give back "no permission";
27+
}
28+
29+
// Sensitive function that requires network access
30+
to fetchData(url: String) {
31+
only if okay "network:http" {
32+
print("Fetching data from: " + url);
33+
// Network fetch would happen here
34+
give back "fetched data";
35+
}
36+
give back "no permission";
37+
}
38+
39+
// Safe function with explicit consent block
40+
to processData() {
41+
print("Processing data safely...");
42+
43+
// Only execute sensitive operations with explicit consent
44+
only if okay "data:write" {
45+
print("Writing processed results...");
46+
}
47+
}
48+
49+
to main() {
50+
hello "Security & Superpowers Demo";
51+
52+
print("=== Consent-based Operations ===");
53+
print("");
54+
55+
// Try to read config (requires permission)
56+
print("1. Attempting to read config:");
57+
remember config = readConfig();
58+
print(" Result: " + config);
59+
60+
print("");
61+
62+
// Try to fetch data (requires permission)
63+
print("2. Attempting network fetch:");
64+
remember data = fetchData("https://api.example.com");
65+
print(" Result: " + data);
66+
67+
print("");
68+
69+
// Process data with consent blocks
70+
print("3. Processing with consent blocks:");
71+
processData();
72+
73+
print("");
74+
print("=== Superpower Declarations ===");
75+
76+
// Declare superpower usage
77+
superpower fileAccess;
78+
superpower networkAccess;
79+
80+
goodbye "Security demo complete!";
81+
}

examples/workers.woke

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Example: Worker System in WokeLang
2+
// Demonstrates workers, message passing, and async operations
3+
4+
thanks to {
5+
"WokeLang" → "For concurrency support";
6+
}
7+
8+
// Define a background worker
9+
worker counter {
10+
remember i = 0;
11+
repeat 5 times {
12+
i = i + 1;
13+
print("Counter: " + toString(i));
14+
}
15+
}
16+
17+
// Define a worker that processes data
18+
worker processor {
19+
print("Processor started");
20+
// In a full implementation, this would receive messages
21+
print("Processor completed");
22+
}
23+
24+
to main() {
25+
hello "Testing Worker System";
26+
27+
print("=== Spawning Workers ===");
28+
29+
// Spawn a worker (currently runs synchronously)
30+
spawn worker counter;
31+
32+
print("");
33+
print("=== Message Passing ===");
34+
35+
// Send a message to a worker (placeholder for now)
36+
send 42 to processor;
37+
send "hello" to processor;
38+
39+
// Receive from a worker (placeholder for now)
40+
receive from processor;
41+
42+
print("");
43+
print("=== Worker Control ===");
44+
45+
// Spawn another worker
46+
spawn worker processor;
47+
48+
// Await worker completion
49+
await processor;
50+
51+
// Cancel a worker if needed
52+
// cancel processor;
53+
54+
goodbye "Workers demonstration complete!";
55+
}

0 commit comments

Comments
 (0)