Skip to content

Commit 62f6b69

Browse files
claudehyperpolymath
authored andcommitted
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
1 parent 78f67fc commit 62f6b69

12 files changed

Lines changed: 3633 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 459 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "wokelang"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "A human-centered, consent-driven programming language"
6+
license = "MIT"
7+
repository = "https://github.com/hyperpolymath/wokelang"
8+
9+
[lib]
10+
name = "wokelang"
11+
path = "src/lib.rs"
12+
13+
[[bin]]
14+
name = "woke"
15+
path = "src/main.rs"
16+
17+
[dependencies]
18+
logos = "0.14"
19+
thiserror = "1.0"
20+
miette = { version = "7.0", features = ["fancy"] }
21+
22+
[dev-dependencies]
23+
pretty_assertions = "1.4"
24+
25+
[profile.release]
26+
lto = true
27+
opt-level = "z"
28+
strip = true
29+
30+
[profile.release-wasm]
31+
inherits = "release"
32+
opt-level = "s"

examples/demo.woke

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// WokeLang Demo - showing interpreter capabilities
2+
3+
thanks to {
4+
"You" -> "For trying WokeLang!";
5+
}
6+
7+
to greet(name: String) -> String {
8+
hello "Starting greeting";
9+
remember message = "Hello, " + name + "!";
10+
give back message;
11+
goodbye "Greeting complete";
12+
}
13+
14+
to factorial(n: Int) -> Int {
15+
when n <= 1 {
16+
give back 1;
17+
}
18+
give back n * factorial(n - 1);
19+
}
20+
21+
to fizzbuzz(n: Int) {
22+
repeat n times {
23+
remember i = n;
24+
when i % 15 == 0 {
25+
print("FizzBuzz");
26+
} otherwise {
27+
when i % 3 == 0 {
28+
print("Fizz");
29+
} otherwise {
30+
when i % 5 == 0 {
31+
print("Buzz");
32+
} otherwise {
33+
print(i);
34+
}
35+
}
36+
}
37+
}
38+
}
39+
40+
to main() {
41+
// Basic output
42+
print("Welcome to WokeLang!");
43+
print("");
44+
45+
// Function calls
46+
remember greeting = greet("World");
47+
print(greeting);
48+
print("");
49+
50+
// Arithmetic and loops
51+
print("Counting to 5:");
52+
remember count = 0;
53+
repeat 5 times {
54+
count = count + 1;
55+
print(count);
56+
}
57+
print("");
58+
59+
// Conditionals
60+
remember x = 10;
61+
when x > 5 {
62+
print("x is greater than 5");
63+
} otherwise {
64+
print("x is 5 or less");
65+
}
66+
print("");
67+
68+
// Pattern matching
69+
remember mood = "happy";
70+
decide based on mood {
71+
"happy" -> { print("Celebrating!"); }
72+
"sad" -> { print("Sending comfort..."); }
73+
_ -> { print("Acknowledged."); }
74+
}
75+
print("");
76+
77+
// Recursive function
78+
print("Factorial of 5:");
79+
remember fact = factorial(5);
80+
print(fact);
81+
print("");
82+
83+
// Arrays
84+
remember numbers = [1, 2, 3, 4, 5];
85+
print("Array:");
86+
print(numbers);
87+
print("Length:");
88+
print(len(numbers));
89+
90+
print("");
91+
print("WokeLang demo complete!");
92+
}

examples/hello.woke

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// A simple WokeLang program demonstrating key features
2+
3+
thanks to {
4+
"Rust Community" → "For the amazing language tooling";
5+
"You" → "For trying WokeLang";
6+
}
7+
8+
@enthusiastic
9+
to greet(name: String) → String {
10+
hello "Starting the greeting ritual";
11+
12+
remember message = "Hello, " + name + "!";
13+
14+
give back message;
15+
16+
goodbye "Greeting complete";
17+
}
18+
19+
to main() {
20+
// Consent-based camera access
21+
only if okay "camera_access" {
22+
remember photo = takePhoto();
23+
}
24+
25+
// Safe error handling
26+
attempt safely {
27+
remember result = riskyOperation();
28+
} or reassure "Don't worry, we handled that gracefully";
29+
30+
// Loop with natural language
31+
repeat 3 times {
32+
greet("World");
33+
}
34+
35+
// Pattern matching
36+
decide based on mood {
37+
"happy" → { celebrate(); }
38+
"sad" → { comfort(); }
39+
_ → { acknowledge(); }
40+
}
41+
}
42+
43+
// Worker for background tasks
44+
worker dataProcessor {
45+
remember data = fetchData();
46+
processInBackground(data);
47+
}

0 commit comments

Comments
 (0)