Stof

Stof format (application/stof).

Stof language is implemented as a Stof format, just like the others (JSON, YAML, TOML, etc.). This makes it available to use with Std.parse(..) also!

Check out Custom Embedded and Imports for more information.

import "./data"

#[main]
fn main() {
    assert_eq(self.message, "hello, world");
    assert_eq(self.person.name, "Bob Smith");
    assert_eq(self.person.age, 42);
    
    const stof = r#"
        parsed: true

        fn say_hi(name: str) -> str {
            `Hi, ${name}`
        }
    "#;
    const container = new {};
    parse(stof, container, "stof"); // parse just like any other format

    assert(container.parsed);
    assert_eq(container.say_hi("John Snow"), "Hi, John Snow");
    drop(container); // can remove from the doc when you're done
}

Challenge: what if drop(this) is called within a function? The "this" references the current function as a "fn" pointer, so it would work just fine, removing the currently executing function from the document (surprisingly helpful in some cases).

In Stof, everything is data and can be manipulated as such, including the currently running environment.

Last updated

Was this helpful?