symbol-lang 1.0.0

Symbol tables, scopes, and name binding/resolution.
Documentation

Installation

[dependencies]
symbol-lang = "1"

Example

A lexically-scoped symbol table generic over the binding. A name resolves to the nearest enclosing definition; inner scopes shadow.

use symbol_lang::{unresolved_name, SymbolTable};
use intern_lang::Interner;
use diag_lang::Span;

let mut names = Interner::new();
let x = names.intern("x");
let y = names.intern("y");

let mut table: SymbolTable<i32> = SymbolTable::new();
table.define(x, 1);

table.enter_scope();
table.define(x, 2);                       // shadows the outer `x`
assert_eq!(table.lookup(x), Some(&2));
table.exit_scope();
assert_eq!(table.lookup(x), Some(&1));     // outer `x` visible again

// An unresolved reference becomes a diagnostic.
assert!(table.lookup(y).is_none());
let diag = unresolved_name("y", Span::new(10, 11));
assert_eq!(diag.message(), "cannot find `y` in this scope");

Status

This is v1.0.0: the public API is stable and frozen under SemVer. The lexically-scoped SymbolTable and the name-error diagnostics are complete and catalogued in docs/API.md.

Contributing

See dev/DIRECTIVES.md for engineering standards and the definition of done. Before a PR: cargo fmt --all, cargo clippy --all-targets --all-features -- -D warnings, and cargo test --all-features must be clean.