| Crates.io | rslnp |
| lib.rs | rslnp |
| version | 0.3.1 |
| created_at | 2021-05-17 14:04:50.31776+00 |
| updated_at | 2026-01-10 21:48:41.153486+00 |
| description | A configurable parser for scopes list notation (SLN) |
| homepage | https://gitlab.com/porky11/rslnp |
| repository | https://gitlab.com/porky11/rslnp |
| max_upload_size | |
| id | 398599 |
| size | 35,357 |
This is a configurable parser for Scopes List Notation (SLN), written in Rust.
SLN was invented for the Scopes programming language, so also take a look at it.
It parses input using the token parser, which is an intermediate representation for code structure. In short, every value is either a symbol (represented as a string) or a parser (parsing other tokens).
SLN is a simple representation suitable for both code and data. It is indentation-based (similar to Python) and directly maps to a list representation (like Lisp). It also supports brackets for nesting, which is most useful for single-line expressions. You can use brackets to opt out of indentation entirely, treating SLN as a pure s-expression parser, or mix both styles.
This notation offers several advantages:
First, create a parser. Use the default Parser::new() for minimal features or Parser::scopes() for full SLN support (matching the Scopes language syntax). Then, parse any iterable of characters (from a string or file content) into a token parser.
Here's a basic example:
use std::fs;
use rslnp::{Error, Parser};
fn main() -> Result<(), Error> {
// Create a parser configured for SLN
let parser = Parser::scopes();
// Parse a string
let input = r#"
# A comment
hello-world # Single symbol
list item1 item2 # List of items
# Multiline string
""""
This is a multiline string.
It preserves newlines and removes the indentation.
"#;
let mut token_parser = parser.parse(input.chars())?;
// Handle tokens using the token parser
Ok(())
}
Strings are parsed into lists. If prefixed (configurable), they become a list with a prefix symbol (like "string") followed by the content symbol. Otherwise, it's a single content symbol.
For full details, see the API documentation.
The parser is highly configurable via builder methods. Key options include:
indent(u8). Set to 0 to disable indentation-based nesting.unpack_single(bool) to interpret lines with a single element as lists (or not).allow_multi_indent(bool).with_brackets(left: char, right: char, prefix: Option<&str>) or disable with without_brackets().with_strings(delimiter: char, prefix: Option<&str>) or disable with without_strings().with_comments(char) or disable with without_comments().with_separator(char) or disable with without_separator().with_symbol_character(char) or disable with without_symbol_character().Example configuration:
let custom_parser = Parser::new()
.indent(2) // 2 spaces per level
.unpack_single(false)
.with_brackets('[', ']', Some("array"))
.with_strings('\'', None) // Single-quoted strings without prefix
.with_comments(';'); // Semicolon comments