Add bit operators, defer, list methods, rand, assert and rex test

- Bit operators & | ^ ~ << >> and their op= forms (Go precedence),
  plus hex, binary and octal literals (0xff, 0b1010, 0o755)
- defer stmt / defer { ... }: runs when the block ends, last first,
  also on return, ?, break and continue
- List methods insert, remove, clear, contains, index_of, reverse,
  sort and sort_by (stable merge sort)
- rand module: int(a, b), float(), seed(n)
- assert(cond[, msg]) and `rex test`, which runs each test_ function
  in its own process
- rex.toml marks a project's top folder: imports count from there
- Docs, formatter, LSP completions and editor grammars updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Your NameandClaude Opus 5.5 committed 2026-11-12 23:30:05 +01:00
1 parent 910bde692a
commit 300d767124
28 files changed
+1373 -65

No files matched your search

+21
View File
@@ -287,3 +287,24 @@ fn imports_from_a_folder_above_are_found() {
let hover = out.iter().find(|m| m.get("id") == Some(&Json::Num(2.0))).unwrap();
assert!(format!("{hover:?}").contains("twice"), "{hover:?}");
}
#[test]
fn the_editor_counts_imports_from_the_project_root() {
let dir = std::env::temp_dir().join(format!("rex-lsp-root-{}", std::process::id()));
std::fs::create_dir_all(dir.join("engine")).unwrap();
std::fs::create_dir_all(dir.join("game/app")).unwrap();
std::fs::write(dir.join("rex.toml"), "").unwrap();
std::fs::write(dir.join("engine/engine.rex"), "import engine.util\npub func twice(x: int): int { return util.dbl(x) }\n").unwrap();
std::fs::write(dir.join("engine/util.rex"), "pub func dbl(x: int): int { return x * 2 }\n").unwrap();
let main = format!("file://{}/game/app/main.rex", dir.display());
let module = format!("file://{}/engine/engine.rex", dir.display());
let src = "import engine.engine\nfunc main() {\n print(engine.twice(2))\n}\n";
let mod_src = "import engine.util\npub func twice(x: int): int { return util.dbl(x) }\n";
// both the main file and a module of the project are checked with the same root
let mut msgs = vec![open(&main, src), open(&module, mod_src)];
msgs.extend(exit_messages());
let (out, _) = talk(msgs);
let _ = std::fs::remove_dir_all(&dir);
assert_eq!(out[0].path(&["params", "diagnostics"]), Some(&Json::Arr(vec![])), "{:?}", out[0]);
assert_eq!(out[1].path(&["params", "diagnostics"]), Some(&Json::Arr(vec![])), "{:?}", out[1]);
}