ling/entry.rs
1use crate::parser::ast::{Expr, Item};
2
3/// Entry-point binding names recognised across Ling's supported human languages.
4/// Shared by the tree-walker and the MIR backends so every execution path agrees
5/// on which top-level binding starts the program.
6pub const ENTRY_NAMES: &[&str] = &[
7 "start",
8 "main",
9 "启",
10 "เริ่ม",
11 "시작",
12 "начать",
13 "начало",
14 "inicio",
15 "comenzar",
16 "début",
17 "commencer",
18 "démarrer",
19 "anfang",
20 "starten",
21 "início",
22 "शुरू",
23 "ابدأ",
24 "شروع", // Persian "start" — also used natively in Urdu
25 "התחל", // Hebrew "start"
26];
27
28/// Resolve the entry binding among top-level items: a bind named after a known
29/// entry keyword, otherwise the first bind whose value is a `do { }` block.
30/// Mirrors the tree-walker's `find_entry`.
31pub fn entry_name(items: &[Item]) -> Option<String> {
32 for key in ENTRY_NAMES {
33 if items
34 .iter()
35 .any(|i| matches!(i, Item::Bind(n, _) if n == key))
36 {
37 return Some((*key).to_string());
38 }
39 }
40 items.iter().find_map(|i| match i {
41 Item::Bind(n, Expr::Do(_)) => Some(n.clone()),
42 _ => None,
43 })
44}