Alap Expression Parser — Rust
Alap is a JavaScript library that turns links into dynamic menus with multiple curated targets. This is the server-side Rust port of the expression parser, enabling expression resolution in Rust servers without a Node.js sidecar.
What's included
alapcrate — Recursive descent parser for the Alap expression grammar, macro expansion, regex search, config merging, URL sanitization, regex validation
What's NOT included
This is the server-side subset of alap/core. It covers expression parsing, config merging, URL sanitization, and regex validation — everything a server needs to resolve cherry-pick and query requests.
Browser-side concerns (DOM rendering, menu positioning, event handling) are handled by the JavaScript client and are not ported here.
Supported expression syntax
item1, item2 # item IDs (comma-separated)
.coffee # tag query
.nyc + .bridge # AND (intersection)
.nyc | .sf # OR (union)
.nyc - .tourist # WITHOUT (subtraction)
(.nyc | .sf) + .open # parenthesized grouping
@favorites # macro expansion
/mypattern/ # regex search (by pattern key)
/mypattern/lu # regex with field options
Usage
use ;
let config: Config = from_str.unwrap;
// Low-level: get matching IDs
let mut parser = new;
let ids = parser.query; // ["item1", "item2"]
let ids = parser.query; // ["item1"]
// Resolve: expression → full link objects (URLs sanitized)
let results = resolve;
// Cherry-pick: expression → HashMap<id, Link> (URLs sanitized)
let subset = cherry_pick;
// Merge multiple configs
let merged = merge_configs;
// URL sanitization (standalone)
let safe = sanitize_url; // "about:blank"
Installation
Add to your Cargo.toml:
[]
= "0.1"
Tests
35 tests across 8 tiers: operands, commas, operators, chaining, macros, parentheses, edge cases, and URL sanitization.
Example Server
- axum-sqlite — Rust + Axum + rusqlite, all 7 endpoints