Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fawdlstty/oml
Open Markup Language!
https://github.com/fawdlstty/oml
Last synced: about 2 months ago
JSON representation
Open Markup Language!
- Host: GitHub
- URL: https://github.com/fawdlstty/oml
- Owner: fawdlstty
- License: mit
- Created: 2024-07-16T14:32:52.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-09-14T16:53:41.000Z (3 months ago)
- Last Synced: 2024-10-31T21:42:59.956Z (about 2 months ago)
- Language: Rust
- Homepage: https://crates.io/crates/oml
- Size: 1.54 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oml
![version](https://img.shields.io/badge/dynamic/toml?url=https%3A%2F%2Fraw.githubusercontent.com%2Ffawdlstty%2Foml%2Fmain%2FCargo.toml&query=package.version&label=version)
![status](https://img.shields.io/github/actions/workflow/status/fawdlstty/oml/rust.yml)English | [简体中文](README.zh_CN.md)
Open Markup Language! A dynamic configuration scripting language that can embed script code in the configuration file to achieve dynamic configuration update.
## Manual
### rust
Install: Run `cargo add oml` in the project directory
```rust
fn main() {
let oml_str = r#"
[hello]
value = 12
name = $"hello {value + 12}"
"#;
let mut eroot = OmlExpr::from_str(oml_str).unwrap();
eroot["hello"]["value"].set_int(30);
let root = eroot.evalute().unwrap();
println!("{}", root["hello"]["name"].as_str()); // hello 42
}
```### C++
Download and compile static libraries (or dynamic libraries)
```shell
git clone [email protected]:fawdlstty/oml.git
cd oml
cargo build --release --lib # debug: cargo build --lib
```The static library (or dynamic library) is generated in the `target/release` directory. Copy it to the C++ project and reference it
```cpp
#include
#include#include "oml/oml.hpp"
#ifdef _MSC_VER
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "ntdll.lib")
#pragma comment(lib, "bcrypt.lib")
#pragma comment(lib, "Userenv.lib")
#pragma comment(lib, "oml.lib")
#endifint main() {
auto oexpr = oml::OmlExpr::from_str(R"(
[hello]
value = 12
name = $"hello {value + 12}"
)");
if (oeroot.index() == 1) {
std::cout << std::get(oeroot) << std::endl;
return 0;
}
auto eroot = std::get(oeroot);
eroot["hello"]["value"].set_int(30);
auto oroot = eroot.evalute();
if (oroot.index() == 1) {
std::cout << std::get(oroot) << std::endl;
return 0;
}
auto root = std::get(oroot);
std::cout << root["hello"]["name"].as_str() << std::endl; // hello 42
return 0;
}
```### C#
Run command:
```sh
dotnet add package oml
```Example:
```csharp
using System;namespace test {
public class Program {
public static void Main () {
string src = """
[hello]
value = 12
name = $"hello {value + 12}"
""";
var eroot = oml.OmlExpr.from_str (src);
eroot ["hello"] ["value"].set_int (30);
var root = eroot.evalute ();
Console.WriteLine (root ["hello"] ["name"].as_str()); // hello 42
Console.ReadKey ();
}
}
}
```### Other features
The value is available when the conditions are met:
```oml
[hello]value = 12
@if value == 12
name = $"hello {value}"
```