script-format

Crates.ioscript-format
lib.rsscript-format
version
sourcesrc
created_at2025-01-22 22:13:27.386469
updated_at2025-02-04 20:16:07.433153
descriptionA simple DSL to format data via rhai scripting
homepage
repositoryhttps://github.com/hardliner66/script-format
max_upload_size
id1527187
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Steve Biedermann (hardliner66)

documentation

README

Script Format

I regularly needed to output data in a custom format, which is why I created a DSL based on Rhai.

Demo

cargo run -q -- -s test_format.rhai -i test.json

DSL

The most important part of the DSL is the ++ operator.

The ++ operator takes the values to its left and right and stores them internally. Once the script is done running, all the stored values get concatenated and returned.

This allows for a really nice way to express what should get output:

let some_number = 1;

// will output 'Test 1'
"Test " ++ some_number;

There are also a two more conveniences, namely NL and IND.

  • NL is a constant holding the newline character (\r).
  • IND is a constant holding the indentation string (Default: four spaces).

There are also functions with the same name that take a number and return the value that amount of time. So if you want to indent something by 3 levels, you can just write IND(3).

If your indentation is different than four spaces, you can set the string for a single indentation level with the function SET_INDENT.

Quick Start

In order to use the DSL you need create a FormattingEngine and register all types you want to work with.

After that, you can just call the appropriate format function to format your data.

Commit count: 29

cargo fmt