Links Notation Parser for Rust
Rust implementation of the Links Notation parser using nom parser combinator library.
Installation
Add this to your Cargo.toml:
[]
= { = "." } # For local development
# Or from a registry:
# links-notation = "0.9.0"
From Source
Clone the repository and build:
Build
Build the project:
Build with optimizations:
Test
Run tests:
Run tests with output:
Usage
Basic Parsing
use ;
Working with Links
use LiNo;
// Create links programmatically
let reference = Ref;
let link = Link ;
// Check link types
if link.is_link
if reference.is_ref
Formatting Output
use parse_lino;
let input = "(parent: child1 child2)";
let parsed = parse_lino.unwrap;
// Regular formatting (parenthesized)
println!;
// Alternate formatting (line-based)
println!;
Handling Different Input Formats
use parse_lino;
// Single line format
let single_line = "id: value1 value2";
let parsed = parse_lino?;
// Parenthesized format
let parenthesized = "(id: value1 value2)";
let parsed = parse_lino?;
// Multi-line with indentation
let indented = r#"parent
child1
child2"#;
let parsed = parse_lino?;
// Quoted identifiers and values
let quoted = r#"("quoted id": "value with spaces")"#;
let parsed = parse_lino?;
Syntax Examples
Doublets (2-tuple)
papa (lovesMama: loves mama)
son lovesMama
daughter lovesMama
all (love mama)
Triplets (3-tuple)
papa has car
mama has house
(papa and mama) are happy
N-tuples with References
(linksNotation: links notation)
(This is a linksNotation as well)
(linksNotation supports (unlimited number (of references) in each link))
Indented Structure
parent
child1
child2
grandchild1
grandchild2
API Reference
Enums
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 link
Methods
Methods for LiNo<T>
is_ref() -> bool- Returns true if this is a referenceis_link() -> bool- Returns true if this is a link
Functions
parse_lino(document: &str) -> Result<LiNo<String>, String>
Parses a Links Notation document string and returns the parsed structure or an error.
Formatting
The Display trait is implemented for LiNo<T> where T: ToString:
- Regular format:
format!("{}", lino)- Parenthesized output - Alternate format:
format!("{:#}", lino)- Line-based output
Dependencies
- nom (8.0) - Parser combinator library
Error Handling
The parser returns descriptive error messages for:
- Empty or whitespace-only input
- Malformed syntax
- Unclosed parentheses
- Invalid characters
match parse_lino