Add documentation infrastructure for RTL symbols

Introduces `RtlDocEntry` and `RtlRegistration` structs to store and
manage documentation for native functions and constants. The
`Environment` struct is updated to include a registry for these
documentation entries.

The `register_native_fn` and `register_constant` methods now return an
`RtlRegistration` builder, allowing for optional chaining of `.doc()`,
`.description()`, and `.examples()` methods before the registration is
finalized when the builder is dropped.

Macros `rtl_fn!` and `rtl_const!` are introduced to simplify the
registration process with documentation.

The MCP server is extended with `get_rtl_docs` and `get_symbol_doc`
tools to expose this documentation externally.

Specific RTL functions and constants (e.g., `+`, `-`, `*`, `/`, `NaN`,
`true`, `false`, `date`, `now`, math functions, `series`, `push`, `len`,
`create-random-ohlc`, `create-ticker`, `pipe`) have been updated to
include their respective documentation using the new infrastructure.

The `Signature` and `StaticType` types have gained `to_doc_string`
methods for generating human-readable documentation strings.
This commit is contained in:
2026-03-25 15:02:19 +01:00
parent 446bdcd42d
commit b436e09840
9 changed files with 400 additions and 69 deletions
+13 -3
View File
@@ -56,7 +56,12 @@ pub fn register(env: &Environment) {
_ => panic!("series expects a lookback_limit and a type keyword (:float, :int...) or a schema record (e.g., {{:price :float}})"),
}
},
);
).doc("Creates a new series (ring buffer) with a defined layout and lookback limit.")
.description("First arg is the lookback limit (int), second is either a type keyword (:float, :int, :bool, :text, :datetime) or a schema record ({:field :type}).")
.examples(&[
"(series 100 :float)",
"(series 200 {:price :float :volume :int})",
]);
// (push series value) -> Void
env.register_native_fn(
@@ -78,7 +83,11 @@ pub fn register(env: &Environment) {
}
panic!("push expects a series as the first argument")
},
);
).doc("Pushes a new value into a series. After push, index 0 returns this value.")
.examples(&[
"(push my-ticks {:price 10.5 :volume 100})",
"(push prices 42.0)",
]);
// (len series) -> Int
env.register_native_fn(
@@ -94,5 +103,6 @@ pub fn register(env: &Environment) {
}
Value::Int(0)
},
);
).doc("Returns the current number of items stored in a series.")
.examples(&["(len my-ticks)"]);
}