| Crates.io | platform-lino |
| lib.rs | platform-lino |
| version | 0.6.0 |
| created_at | 2025-08-09 02:34:48.481694+00 |
| updated_at | 2025-08-31 16:57:01.681592+00 |
| description | Rust implementation of the Lino protocol parser |
| homepage | |
| repository | https://github.com/linksplatform/Protocols.Lino |
| max_upload_size | |
| id | 1787509 |
| size | 62,061 |
Rust implementation of the Lino protocol parser using nom parser combinator library.
Add this to your Cargo.toml:
[dependencies]
lino = { path = "." } # For local development
# Or from a registry:
# lino = "0.0.1"
Clone the repository and build:
git clone https://github.com/linksplatform/Protocols.Lino.git
cd Protocols.Lino/rust
cargo build
Build the project:
cargo build
Build with optimizations:
cargo build --release
Run tests:
cargo test
Run tests with output:
cargo test -- --nocapture
use lino::{parse_lino, LiNo};
fn main() {
// Parse Lino format string
let input = r#"papa (lovesMama: loves mama)
son lovesMama
daughter lovesMama
all (love mama)"#;
match parse_lino(input) {
Ok(parsed) => {
println!("Parsed: {}", parsed);
// Access the structure
if let LiNo::Link { values, .. } = parsed {
for link in values {
println!("Link: {}", link);
}
}
}
Err(e) => eprintln!("Parse error: {}", e),
}
}
use lino::LiNo;
// Create links programmatically
let reference = LiNo::Ref("some_value".to_string());
let link = LiNo::Link {
id: Some("parent".to_string()),
values: vec![
LiNo::Ref("child1".to_string()),
LiNo::Ref("child2".to_string()),
],
};
// Check link types
if link.is_link() {
println!("This is a link");
}
if reference.is_ref() {
println!("This is a reference");
}
use lino::parse_lino;
let input = "(parent: child1 child2)";
let parsed = parse_lino(input).unwrap();
// Regular formatting (parenthesized)
println!("Regular: {}", parsed);
// Alternate formatting (line-based)
println!("Alternate: {:#}", parsed);
use lino::parse_lino;
// Single line format
let single_line = "id: value1 value2";
let parsed = parse_lino(single_line)?;
// Parenthesized format
let parenthesized = "(id: value1 value2)";
let parsed = parse_lino(parenthesized)?;
// Multi-line with indentation
let indented = r#"parent
child1
child2"#;
let parsed = parse_lino(indented)?;
// Quoted identifiers and values
let quoted = r#"("quoted id": "value with spaces")"#;
let parsed = parse_lino(quoted)?;
papa (lovesMama: loves mama)
son lovesMama
daughter lovesMama
all (love mama)
papa has car
mama has house
(papa and mama) are happy
(linksNotation: links notation)
(This is a linksNotation as well)
(linksNotation supports (unlimited number (of references) in each link))
parent
child1
child2
grandchild1
grandchild2
LiNo<T>Represents either a Link or a Reference:
Link { id: Option<T>, values: Vec<Self> } - A link with optional ID and child valuesRef(T) - A reference to another linkLiNo<T>is_ref() -> bool - Returns true if this is a referenceis_link() -> bool - Returns true if this is a linkparse_lino(document: &str) -> Result<LiNo<String>, String>Parses a Lino document string and returns the parsed structure or an error.
The Display trait is implemented for LiNo<T> where T: ToString:
format!("{}", lino) - Parenthesized outputformat!("{:#}", lino) - Line-based outputThe parser returns descriptive error messages for:
match parse_lino("(invalid") {
Ok(parsed) => println!("Parsed: {}", parsed),
Err(error) => eprintln!("Error: {}", error),
}