Skip to main content

shape_runtime/metadata/
keywords.rs

1//! Language keywords metadata
2
3use super::types::{KeywordCategory, KeywordInfo};
4
5/// Get all language keywords
6pub fn keywords() -> Vec<KeywordInfo> {
7    vec![
8        // Declarations
9        KeywordInfo {
10            keyword: "let".to_string(),
11            description: "Declare a mutable variable.\n\n`let x = 42`\n`let name: string = \"hello\"`".to_string(),
12            category: KeywordCategory::Declaration,
13        },
14        KeywordInfo {
15            keyword: "var".to_string(),
16            description: "Declare a mutable variable.\n\n`var count = 0`".to_string(),
17            category: KeywordCategory::Declaration,
18        },
19        KeywordInfo {
20            keyword: "const".to_string(),
21            description: "Declare an immutable constant.\n\n`const PI = 3.14159`".to_string(),
22            category: KeywordCategory::Declaration,
23        },
24        KeywordInfo {
25            keyword: "fn".to_string(),
26            description: "Define a named function.\n\n`fn add(x: number, y: number) -> number { return x + y }`\n\n`function` is still accepted as a legacy alias.".to_string(),
27            category: KeywordCategory::Declaration,
28        },
29        KeywordInfo {
30            keyword: "function".to_string(),
31            description: "Legacy alias for `fn`.\n\n`function add(x: number, y: number) -> number { return x + y }`".to_string(),
32            category: KeywordCategory::Declaration,
33        },
34        // Control Flow
35        KeywordInfo {
36            keyword: "if".to_string(),
37            description: "Conditional branching.\n\n`if x > 10 { \"big\" } else { \"small\" }`".to_string(),
38            category: KeywordCategory::ControlFlow,
39        },
40        KeywordInfo {
41            keyword: "else".to_string(),
42            description: "Else clause for if statement.\n\n`if cond { a } else { b }`".to_string(),
43            category: KeywordCategory::ControlFlow,
44        },
45        KeywordInfo {
46            keyword: "while".to_string(),
47            description: "Loop while condition is true.\n\n`while x > 0 { x = x - 1 }`".to_string(),
48            category: KeywordCategory::ControlFlow,
49        },
50        KeywordInfo {
51            keyword: "for".to_string(),
52            description: "Loop over a range or iterable.\n\n`for x in 0..10 { print(x) }`\n`for (let i = 0; i < 10; i++) { }`".to_string(),
53            category: KeywordCategory::ControlFlow,
54        },
55        KeywordInfo {
56            keyword: "return".to_string(),
57            description: "Return a value from a function.\n\n`return x + y`".to_string(),
58            category: KeywordCategory::ControlFlow,
59        },
60        KeywordInfo {
61            keyword: "break".to_string(),
62            description: "Break out of a loop.\n\n`while true { if done { break } }`".to_string(),
63            category: KeywordCategory::ControlFlow,
64        },
65        KeywordInfo {
66            keyword: "continue".to_string(),
67            description: "Continue to next loop iteration.\n\n`for x in items { if skip(x) { continue } }`".to_string(),
68            category: KeywordCategory::ControlFlow,
69        },
70        KeywordInfo {
71            keyword: "match".to_string(),
72            description: "Pattern match on a value.\n\n`match color { Color::Red => \"red\", _ => \"other\" }`".to_string(),
73            category: KeywordCategory::ControlFlow,
74        },
75        KeywordInfo {
76            keyword: "try".to_string(),
77            description: "Handle errors with try-catch.\n\n`try { risky() } catch (e) { fallback() }`".to_string(),
78            category: KeywordCategory::ControlFlow,
79        },
80        // Query Keywords
81        KeywordInfo {
82            keyword: "find".to_string(),
83            description: "Find patterns in data.\n\n`find hammer in data[0:100]`".to_string(),
84            category: KeywordCategory::Query,
85        },
86        KeywordInfo {
87            keyword: "scan".to_string(),
88            description: "Scan for conditions in data.\n\n`scan data for condition`".to_string(),
89            category: KeywordCategory::Query,
90        },
91        KeywordInfo {
92            keyword: "analyze".to_string(),
93            description: "Analyze data.\n\n`analyze data with strategy`".to_string(),
94            category: KeywordCategory::Query,
95        },
96        KeywordInfo {
97            keyword: "simulate".to_string(),
98            description: "Run a simulation.\n\n`simulate strategy on data`".to_string(),
99            category: KeywordCategory::Query,
100        },
101        KeywordInfo {
102            keyword: "all".to_string(),
103            description: "All matches quantifier.\n\n`find all hammer in data`".to_string(),
104            category: KeywordCategory::Query,
105        },
106        // Module System
107        KeywordInfo {
108            keyword: "import".to_string(),
109            description:
110                "Import a namespace module.\n\n`import duckdb`\n`import ml as inference`\n`use duckdb`"
111                    .to_string(),
112            category: KeywordCategory::Module,
113        },
114        KeywordInfo {
115            keyword: "use".to_string(),
116            description: "Import named items from a module.\n\n`from std::finance use { sma, rsi }`".to_string(),
117            category: KeywordCategory::Module,
118        },
119        KeywordInfo {
120            keyword: "pub".to_string(),
121            description: "Make a definition publicly visible.\n\n`pub fn helper() { }`".to_string(),
122            category: KeywordCategory::Module,
123        },
124        KeywordInfo {
125            keyword: "from".to_string(),
126            description: "Specify module source for import.\n\n`from std::module use { name }`".to_string(),
127            category: KeywordCategory::Module,
128        },
129        KeywordInfo {
130            keyword: "module".to_string(),
131            description: "Reserved keyword (file = module).".to_string(),
132            category: KeywordCategory::Module,
133        },
134        KeywordInfo {
135            keyword: "as".to_string(),
136            description: "Alias for import/pub.\n\n`from mod use { longName as short }`".to_string(),
137            category: KeywordCategory::Module,
138        },
139        KeywordInfo {
140            keyword: "default".to_string(),
141            description: "Reserved keyword.".to_string(),
142            category: KeywordCategory::Module,
143        },
144        // Type System
145        KeywordInfo {
146            keyword: "type".to_string(),
147            description: "Define a struct type or type alias.\n\n`type Point { x: number, y: number }`\n`type ID = string`".to_string(),
148            category: KeywordCategory::Type,
149        },
150        KeywordInfo {
151            keyword: "interface".to_string(),
152            description: "Define a structural type contract.\n\n`interface Printable { format(): string }`".to_string(),
153            category: KeywordCategory::Type,
154        },
155        KeywordInfo {
156            keyword: "enum".to_string(),
157            description: "Define an enum with variants.\n\n`enum Color { Red, Green, Blue(number) }`".to_string(),
158            category: KeywordCategory::Type,
159        },
160        KeywordInfo {
161            keyword: "extend".to_string(),
162            description: "Add methods to an existing type.\n\n`extend Table<Row> { method count() { ... } }`".to_string(),
163            category: KeywordCategory::Type,
164        },
165        KeywordInfo {
166            keyword: "stream".to_string(),
167            description: "Define a real-time data stream.\n\n`stream Feed { config { provider: \"ws\" }, on_event(e) { } }`".to_string(),
168            category: KeywordCategory::Other,
169        },
170        // Literals
171        KeywordInfo {
172            keyword: "true".to_string(),
173            description: "Boolean true value.".to_string(),
174            category: KeywordCategory::Literal,
175        },
176        KeywordInfo {
177            keyword: "false".to_string(),
178            description: "Boolean false value.".to_string(),
179            category: KeywordCategory::Literal,
180        },
181        KeywordInfo {
182            keyword: "None".to_string(),
183            description: "Empty Option value.".to_string(),
184            category: KeywordCategory::Literal,
185        },
186        KeywordInfo {
187            keyword: "Some".to_string(),
188            description: "Option constructor with a value.".to_string(),
189            category: KeywordCategory::Literal,
190        },
191        // Operators
192        KeywordInfo {
193            keyword: "and".to_string(),
194            description: "Logical AND operator.\n\n`if a and b { }`".to_string(),
195            category: KeywordCategory::Operator,
196        },
197        KeywordInfo {
198            keyword: "or".to_string(),
199            description: "Logical OR operator.\n\n`if a or b { }`".to_string(),
200            category: KeywordCategory::Operator,
201        },
202        KeywordInfo {
203            keyword: "not".to_string(),
204            description: "Logical NOT operator.\n\n`if not done { }`".to_string(),
205            category: KeywordCategory::Operator,
206        },
207        KeywordInfo {
208            keyword: "in".to_string(),
209            description: "Membership test operator.\n\n`if x in [1, 2, 3] { }`".to_string(),
210            category: KeywordCategory::Operator,
211        },
212        // Temporal
213        KeywordInfo {
214            keyword: "on".to_string(),
215            description: "Timeframe context switch.\n\n`on(1h) { sma(20) }`".to_string(),
216            category: KeywordCategory::Temporal,
217        },
218        // Other
219        // "pattern" and "strategy" are user-defined annotation names, not language keywords
220        KeywordInfo {
221            keyword: "method".to_string(),
222            description: "Define a method on a type.\n\n`method name(params) { body }`".to_string(),
223            category: KeywordCategory::Other,
224        },
225        KeywordInfo {
226            keyword: "when".to_string(),
227            description: "Conditional method clause.\n\n`when condition { action }`".to_string(),
228            category: KeywordCategory::Other,
229        },
230        KeywordInfo {
231            keyword: "this".to_string(),
232            description: "Reference to current context.\n\n`this.field`".to_string(),
233            category: KeywordCategory::Other,
234        },
235        KeywordInfo {
236            keyword: "comptime".to_string(),
237            description: "Declare a compile-time constant field on a struct type.\n\nComptime fields are baked at compile time and have zero runtime cost.\nThey cannot be set in struct literals.\n\n`type Currency { comptime symbol: string = \"$\", amount: number }`\n\nUse type aliases to override: `type EUR = Currency { symbol: \"\\u{20ac}\" }`".to_string(),
238            category: KeywordCategory::Type,
239        },
240        // Async
241        KeywordInfo {
242            keyword: "await".to_string(),
243            description: "Await an asynchronous expression or join concurrent branches.\n\n`let result = await fetch(\"url\")`\n`let (a, b) = await join all { task_a(), task_b() }`".to_string(),
244            category: KeywordCategory::ControlFlow,
245        },
246        KeywordInfo {
247            keyword: "join".to_string(),
248            description: "Join concurrent branches with a strategy.\n\nUsed after `await` to run multiple async expressions concurrently.\n\n`await join all { a(), b() }`\n`await join race { fast(), slow() }`".to_string(),
249            category: KeywordCategory::ControlFlow,
250        },
251        KeywordInfo {
252            keyword: "race".to_string(),
253            description: "Join strategy: return the first branch to complete, cancel the rest.\n\n`await join race { fetch(\"a\"), fetch(\"b\") }`".to_string(),
254            category: KeywordCategory::ControlFlow,
255        },
256        KeywordInfo {
257            keyword: "any".to_string(),
258            description: "Join strategy: return the first branch to succeed (non-error), cancel the rest.\n\n`await join any { fetch(\"a\"), fetch(\"b\") }`".to_string(),
259            category: KeywordCategory::ControlFlow,
260        },
261        KeywordInfo {
262            keyword: "settle".to_string(),
263            description: "Join strategy: wait for all branches, preserving individual success/error results.\n\n`await join settle { task_a(), task_b() }`".to_string(),
264            category: KeywordCategory::ControlFlow,
265        },
266        KeywordInfo {
267            keyword: "async".to_string(),
268            description: "Mark a function as asynchronous.\n\n`async fn fetch_data(url: string) { await http.get(url) }`".to_string(),
269            category: KeywordCategory::Declaration,
270        },
271    ]
272}