Expand description
Lemon — the strategy DSL for the citrus backtesting engine.
Lemon is a small text language for writing trading strategies. A strategy
such as close > sma(close, 2) is lowered into a JSON Expr tree — the
serializable strategy AST (spec::Expr) — which the yuzu engine walks
against price/fundamental data to produce a position matrix. The same JSON
runs identically in-browser (WASM) and in the native batch runner.
This crate does no math itself: it is a surface syntax over the Expr
AST. parse turns text into the JSON tree; format() renders a tree
back into canonical, re-indented text (a “gofmt for lemon”). All numeric
semantics live in the engine crate.
§Layout
spec— the serializableExprAST (JSON, tagged by"op").services— editor language services (diagnostics, hover, completions), pure functions of(source, position)that back both the WASM boundary and thelemon-lsplanguage server.dsl(private) — the text syntax:lex(tokenizer),parse(text → JSON),ops(surface-name ⇄ op-tag vocabulary),print(JSON → text).
§Example
let tree = lemon::parse("close > sma(close, 2)").unwrap();
assert_eq!(tree["op"], "Gt");
// `format` renders a tree back to canonical DSL text.
let text = lemon::format(&tree);
assert_eq!(text, "(close > sma(close, 2))");A ParseError carries a 1-based line/col and prints as
line:col: message.
§Syntax reference
The author-facing language reference (lexical rules, operators and
precedence, the let/call grammar, and the complete op table) lives in
docs/lemon.md in the repository.
Re-exports§
pub use spec::Expr;
Modules§
- meta
- Machine-readable op vocabulary: the catalog of callable ops (canonical names,
aliases, tags, ordered field specs, defaults, descriptions) plus the binary
operators. This is the single source of truth the schema generator
(
cargo run -p lemon-lang --example gen-schema) reads to emitschema/op-catalog.jsonandschema/lemon-spec.schema.json. - services
- Editor language services for the Lemon DSL — pure, I/O-free, editor-agnostic.
- spec
Expr: the serializable strategy AST. A JSON tree (tagged by"op") that the website and the batch runner both emit; the engine’s evaluator walks it against a data context to produce a position matrix.
Structs§
- Analysis
- A parse plus the source facts the linter needs: where every bare-identifier
data-series reference sits, and which
letbindings were never used. - Lint
- One lint warning, at a 1-based source position.
- Parse
Error - A parse failure with a 1-based source position.
Functions§
- format
- lint
- Lint
src. Parse errors surface asErr; a clean parse yields warnings (possibly none).known_series = Noneskips the unknown-series check (unused-letis always checked); pass the engine’s series list to enable it. Repeated references to the same unknown name warn once. - parse
- Lower DSL text to a JSON
Exprtree. - parse_
analyzed - Like
parse, returning theAnalysisside-channel as well.