#configuration-language #config-parser #cola

bin+lib colap

A lightweight, human-friendly configuration language parser & code generator

5 releases (breaking)

Uses new Rust 2024

0.5.0 Nov 3, 2026
0.4.0 Oct 31, 2026
0.3.0 Oct 30, 2026
0.2.0 Aug 25, 2026
0.1.0 Jul 13, 2025

#1450 in Parser implementations

Download history 2/week @ 2026-08-11 2/week @ 2026-08-25 19/week @ 2026-09-01 111/week @ 2026-09-08 2/week @ 2026-09-15 29/week @ 2026-09-22 266/week @ 2026-09-29 67/week @ 2026-10-06 45/week @ 2026-10-13 70/week @ 2026-10-20 40/week @ 2026-10-27 11/week @ 2026-11-03 122/week @ 2026-11-10 45/week @ 2026-11-17 6/week @ 2026-11-24

188 downloads per month
Used in 2 crates (via chaiss-core)

Apache-2.0

375KB
9K SLoC

Cola-p Logo

πŸ₯€ colap – A Refreshingly Simple Configuration Language Parser & Code Generator


Tired of fighting with your config files? So were we.

cola is a lightweight, human-friendly configuration language designed to avoid YAML’s whitespace traps, JSON’s curly-brace fatigue, and TOML’s dotted-key spaghetti. It’s backed by colap, a Rust parser and code generator that makes working with configurations effortless.

Cola is:

βœ… Readable – Clean nesting with minimal punctuation.
βœ… Writable – No indentation anxiety. No trailing comma drama.
βœ… Composable – Works standalone or embedded in Markdown as fenced cola ... blocks.


πŸš€ Why cola?

YAML: Tabs vs Spaces

Miss one indent, and your app silently loads nonsense.

JSON: Curly Braces Forever

Nested configs turn into a forest of {} and [].

TOML: Dotted-Key Spaghetti

Deep nesting forces verbose dotted keys or confusing table headers.

cola: Refreshingly Simple

  • πŸ†“ Not whitespace sensitive – Tabs? Spaces? Mix them. Cola doesn’t care.
  • βœ… Minimal punctuation – Just : for nesting and ; to end blocks.
  • 🏷️ Infix plural syntax – Explicitly name singular and plural forms for code generators.
  • πŸ“„ Markdown-native – Embed configs directly in documentation.

πŸ“– Example Configuration

Here's a real-world configuration defining multiple LLM providers:

llm plural llms:
    openai:
        api:
            type: "REST",
            key: "some_api_key",
            base_url: "some_base_url"
        ;

        model plural models:
            gpt-4.1:
                name: "gpt-4.1",
                max_input_tokens: 1048576,
                output_price: 8.0,
                supports_vision: true
            ;
            gpt-4o:
                name: "gpt-4o",
                max_input_tokens: 1048576,
                output_price: 8.0,
                supports_vision: true
            ;
        ;
    ;
;

πŸ†š cola vs YAML / JSON / TOML

Feature YAML JSON TOML cola
Whitespace sensitivity 😬 Yes πŸ‘ No πŸ‘ No βœ… No
Curly brace clutter πŸ‘ Minimal 😩 Lots πŸ‘ Minimal βœ… Minimal
Trailing commas allowed ❌ No ❌ No βœ… Yes βœ… Yes
Multi-line strings πŸ€” Hard πŸ˜• Escapes βœ… Easy βœ… Easy
Comments βœ… # ❌ None βœ… # βœ… //, kept by fmt
Collections (arrays/maps) πŸ˜• Indents 😩 [], {} πŸ˜• Mixed βœ… [] lists, infix plural maps
Markdown embedding ❌ Awkward ❌ Awkward ❌ Awkward βœ… First-class

The language is specified in docs/spec/cola.md, a literate document that colap itself checks; a conformance corpus under tests/conformance/ holds the parser, the diagnostics and the highlighter to it. Schemas have their own spec, docs/spec/schema.md.


🎯 Design Philosophy

πŸ”Ή Why Semicolons?

Cola uses ; as a block terminator:

  • Prevents ambiguity at the end of nested blocks.
  • Avoids silent parsing errors from missing indentation (YAML) or commas (JSON).
  • Familiar and clear for both humans and parsers.

πŸ”Ή Why Infix plural?

model plural models:
    gpt-4:
        name: "gpt-4"
    ;
    gpt-4o:
        name: "gpt-4o"
    ;
;
  • Makes singular and plural forms explicit in configuration.
  • Eliminates brittle β€œadd an s” heuristics in code generation.
  • Supports irregular plurals (e.g. person plural people).
  • Improves clarity: developers instantly know single vs multiple semantics.

πŸ”’ Numbers and time

Numbers are kept exactly as written

A number literal (8, 8.0, 1_048_576, 1.5e-3, 123456789012345678901234567890) becomes ConfigValue::Number, which holds the literal's exact decimal: no size limit, no rounding, no respelling beyond dropping digit separators. 0.1 is a tenth, 1.10 keeps its trailing zero, and a thirty-digit integer survives check and fmt untouched. Equality and order are numeric (1.10 == 1.1 == 11e-1), the literal's kind (integer or float) is kept from its spelling, and the machine type is the reader's choice:

View For
as_i64() an integral value that fits 64 bits, None otherwise
as_f64() the nearest double
decimal() the sign, the significand digits and the power of ten: what an arbitrary-precision consumer needs to rebuild the value without loss
text() the canonical literal

The decimal() view exists for consumers that never go through a float. claimr, the constraint logic language in the same workspace, keeps every number as an exact rational; a cola record feeds it digits Γ— 10^exponent and gets 37/2 for 18.5, not the nearest double. Schema types name the machine type for generated code: integer (i64), float and number (f64), and decimal, which keeps the exact Number in the generated struct. The design is recorded in docs/design/2026-10-31-exact-numbers.md.

Two kinds of time, never one type

cola has no date literal; a schema types a string field, and colap check --schema checks the text:

Schema type Holds Example
instant transaction time: an RFC 3339 date-time with Z or an offset, a real moment "2026-10-30T14:05:00Z"
date valid time at year, month or day precision "1914", "1914-08", "1914-08-04"
datetime civil date and time with no offset, optionally with an IANA zone in brackets "2026-10-30T09:00[Europe/Zurich]"
edtf EDTF levels 0 and 1: uncertain, approximate, unspecified digits, seasons, intervals "1914?", "191X", "1914/1918", "1914/.."

An instant says when something was recorded; the other three say when a fact held in the world, at the precision the source gives, and a knowledge graph's temporal predicates work on those intervals. A value with an offset is an instant and one without is civil, so a datetime holding …Z is a finding. The workspace's naming rule is checked too: a field ending in _utc must be an instant, an instant should end in _utc, and an instant in a _utc field written with an offset other than Z is warned about; utc_suffix: false on the schema switches the rule off. Canonical form never rewrites a temporal value: an offset stays as the source wrote it. Generated code reads all four as String; typed values behind a feature flag are a possible later step. The reasoning is in docs/incubation/2026-10-30-temporal-values.md and the forms in docs/spec/schema.md, section 4.


πŸ”§ Features

Parser

  • Parses standalone .cola files and Markdown files with embedded cola blocks
  • Finds cola blocks with CommonMark's fence rules, so any other fenced block (mermaid, toml, a bare ```) is skipped and any prose is allowed
  • Produces structured configuration models whose source locations point into the original file
  • Reports errors as path:line:col: message
  • Values: strings with escapes and """ block strings, numbers with digit separators and exponents kept exactly as written (no size limit, no rounding; machine types are the reader's choice), booleans, bare symbols (basis: parsed), lists (tags: [a, "b", 3]) and references (@claims/cl-1) that colap check resolves
  • // comments inside cola blocks, kept in the model and written back in place by colap fmt
  • Schemas, written in cola: colap check --schema S.md FILE... reports missing and unknown members, wrong kinds, values outside closed sets, bounds and patterns, references to the wrong place, and malformed instants and dates (docs/spec/schema.md)
  • Reads large files in linear time: a 10k-entry ledger (5 MB) in about 0.4 s; cargo bench --bench scale guards it

Code Generator

  • Generates idiomatic Rust structs and collections (HashMap) from cola models
  • Handles plural entities clearly
  • Renames Rust keywords (e.g., type to type_)
  • Provides constructors and accessor methods for easy integration

πŸ“¦ Installation

Add colap to your Rust project:

[dependencies]
colap = { version = "0.5", default-features = false }

With the default features off you get the library: the fence scanner, the parser, the model, check, fmt, the highlighter and schemas, with rustemo, regex and chrono as its only dependencies. Two features add the rest, and both are on by default so that cargo install colap and a plain colap = "0.5" are unchanged:

Feature Adds Dependencies
generator colap::generator, the Rust code generator handlebars, heck, serde_json, anyhow
cli the colap binary (implies generator) clap, env_logger, log

A crate generated by colap generate depends on the library alone.

The parser is silent in your debug and test builds. rustemo's parse trace, which exists in debug builds only, prints when RUSTEMO_TRACE is set in the environment; colap --trace is the same switch for the CLI.


πŸ“‚ Codebase Structure

The colap codebase is organized into the following modules:

  • lib.rs: The entry points β€” parse_file, parse_str, parse_literate_str and parse_cola_str
  • literate: The markdown layer β€” a CommonMark-style fence scanner that hands only the bodies of ```cola blocks to the parser
  • error: The error type, with file-accurate locations
  • parser: Handles parsing of Cola syntax using rustemo
    • cola.rs: Generated parser code
    • cola_actions.rs: Parser actions
  • highlight: A line lexer for editors, sharing the scanner's fence rules
  • model: Contains the configuration model definitions
    • config_model.rs: Core configuration model and node types
    • model_builder.rs: Builds config model from parsed AST
    • source_location.rs: Source location tracking
  • generator: Code generation for Rust structs
    • generator_impl.rs: Main code generator implementation
    • templates/: Handlebars templates for code generation
  • grammar: Contains the rustemo grammar definition
    • cola.rustemo: Grammar rules for the Cola language

🚩 Usage

Command Line Interface

USAGE:
    colap check [--format <text|cola>] [--schema <SCHEMA>] <FILE>...
    colap generate [--schema <SCHEMA>] [--colap-path <DIR>] [-o DIR] [-n NAME] [-m crate|module] [INPUT]
    colap fmt [--check] <FILE>...
    colap generate [OPTIONS] <input>
    colap [OPTIONS] <input>              # the same as `generate`

OPTIONS (generate):
    -m, --mode <MODE>              Generation mode: 'crate' or 'module' (default: crate)
    -n, --crate-name <NAME>        Name of the generated library crate (default: input-file-stem-config)
    -o, --output <DIR>             Base output directory (default: generated)

OPTIONS (all commands):
        --trace                    Print the parser's debug trace (debug builds only)
    -h, --help                     Print help information
    -V, --version                  Print version information

Exit codes are lint-style: 0 when every file is clean (warnings allowed), 1 when any error was found, 2 for a usage error.

Examples

Checking files

Validate literate files without generating anything:

colap check docs/*.md

Every finding is one line, path:line:col: severity: message, with the location in the original file. All errors in a file are reported, not just the first: a block that does not parse does not hide the next one, and every duplicate is listed with both locations.

ledger.md:12:8: error: Expected one of BooleanFalse, BooleanTrue, Semicolon, Identifier, Number, QuotedStringDouble, QuotedStringSingle.
ledger.md:21:5: error: duplicate entry `cl-1` in `claim`; first at 18:5
notes.md: warning: no cola blocks in this file
notes.md:3:1: warning: unclosed cola fence runs to the end of the file
config.md:5:5: warning: empty entity `llm/api`

--format cola prints the same findings as a cola block β€” a finding plural findings collection with severity, path, line, column and message fields β€” so a report can be fed back to colap or embedded in a literate document.

The same checks run before every generate, which prints the findings to stderr and exits 1 on errors.

Validating against a schema

A schema is a cola document that mirrors the shape of the documents it describes:

schema:
    entity plural entities:
        llm:
            plural: llms,
            field plural fields:
                name: type: string, required: true;
                max_input_tokens: type: integer, min: 1;
                basis: type: symbol, one_of: [mirrored, parsed, derived];
                recorded_at_utc: type: instant, required: true;
            ;
        ;
    ;
;
colap check --schema registry.schema.md registry.md
# registry.md:5:5: error: missing required field `recorded_at_utc` in `llm/gpt-4.1`
# registry.md:6:9: error: field `max_input_tokens` in `llm/gpt-4.1` must be an integer, got "many"

Types: string, integer, float, number, decimal, boolean, symbol, reference (with to), instant, date, datetime, edtf, any, each optionally a list; constraints required, one_of, min, max, pattern; unknown: error | warn | allow per entity; key_pattern on collections; like to reuse a declaration. The dialect's own schema ships in the crate and checks every schema first.

Formatting files

Rewrite the cola blocks of literate files into the canonical layout, in place; everything outside the fences stays byte for byte as it was, and a collection split over several blocks stays split:

colap fmt docs/*.md
colap fmt --check docs/*.md    # writes nothing; exits 1 if a block is not canonical

The canonical layout is a pure function of the model, so formatting is idempotent and files regenerated by tools come out byte-deterministic:

  • four spaces of indentation per level;
  • an entity with no children whose one-line form fits in 80 columns is written on one line (database: url: "";); otherwise one field per line, no trailing comma, and the closing ; on its own line;
  • fields before child entities, both in source order;
  • floats always carry a decimal point (8.0), strings are double-quoted unless their text contains a double quote.

A file with errors is not formatted; fmt prints the findings and exits 1. The same writer is available as ConfigModel::to_cola().

The order guarantee. The model keeps fields and entries in source order, across reopened blocks, and the generated plural wrappers iterate in that order (keys(), values(), iter()), so appended entries show up at the end of a diff.

Basic Crate Generation (Default)

Generate a complete Rust crate from a cola file:

colap path/to/myconfig.cola

This will:

  1. Parse myconfig.cola
  2. Generate code in the directory generated/myconfig-config/
  3. Create a complete library crate with:
    • Cargo.toml with dependencies
    • src/lib.rs with generated structs
    • tests/integration.rs with integration tests
    • README.md with usage documentation

Module Generation

Generate a single Rust module file for embedding in your project:

colap path/to/myconfig.cola --mode module -o src -n config_parser

This will:

  1. Parse myconfig.cola
  2. Generate a single file src/config_parser.rs
  3. Include inline unit tests within the module
  4. Ready to be imported with mod config_parser; in your project

Generating from a schema

With a schema, types come from declarations rather than from the sample's literals: a field that is not required is an Option, a symbol with one_of is an enum, a decimal is colap's exact Number, and the generated Root::load validates a file against the embedded schema before building it:

colap generate --schema registry.schema.md registry.md -o generated
use registry_config::{Root, LlmBasis};

let root = Root::load("registry.md").expect("a document matching the schema");
let gpt = root.llms.get("gpt-4.1").unwrap();
assert_eq!(gpt.basis, Some(LlmBasis::Parsed));

The document is optional; when given it is validated first and loaded by the crate's integration test. --colap-path <DIR> makes the generated crate depend on a checkout instead of the published colap. The type mapping is in docs/spec/schema.md, section 7.

Custom crate name and output directory

colap path/to/myconfig.cola --crate-name my-custom-config --output custom/output/dir

This will:

  1. Parse myconfig.cola
  2. Generate code in the directory custom/output/dir/my-custom-config/
  3. Create a library crate with generated structs in custom/output/dir/my-custom-config/lib.rs

Code Generation Details

The code generator produces:

  1. Rust structs for each entity type in the configuration
  2. Collection structs (using HashMap) for plural entities
  3. Accessor methods to retrieve fields and collections
  4. Constructors for each entity type
  5. Integration tests for validating parsing functionality

Generated Code Structure

For a configuration file with entities like Root, Llm, and Model, the generator produces:

// Root entity struct
pub struct Root {
    llm: Llm,
    // other fields...
}

// Singular entity
pub struct Llm {
    provider: String,
    models: Models,  // plural entity reference
    // other fields...
}

// Plural entity (collection)
pub struct Models {
    entries: HashMap<String, Model>,
}

// Entity in a collection
pub struct Model {
    name: String,
    context_window: i64,
    // other fields...
}

Type Handling

The generator maps Cola types to Rust types as follows:

Cola Type Rust Type
String, Symbol, Reference String
Number of integer kind (8) i64, when the value fits
Number of float kind (8.0, 1e3) f64, the nearest double
Schema type decimal colap::config_model::Number, the exact value
Schema types instant, date, datetime, edtf String, checked by the schema
Boolean bool
List Vec<T> of the elements' type, Vec<ConfigValue> when empty or mixed
Entity Custom struct
Optional Entity Option<CustomStruct>

Default Crate Name

If the --crate-name option is not provided, the crate name is derived from the input file:

  1. Take the file stem (filename without extension)
  2. Replace underscores with hyphens
  3. Convert to lowercase
  4. Append -config suffix

For example:

  • my_config.cola β†’ my-config-config
  • API_Model.md β†’ api-model-config

Using the Generated Code

Loading and Parsing a Configuration File

The generated code includes integration tests that demonstrate how to parse configuration files:

use my_config::Root;  // Generated crate name

// Load and parse a configuration file: markdown with ```cola fences,
// or a bare .cola file. Errors read `path:line:col: message`.
fn parse_config_file(path: &str) -> Root {
    let parsed = colap::parse_file(path).expect("Failed to parse configuration");
    for warning in &parsed.warnings {
        eprintln!("warning: {warning}");
    }
    Root::from_model(&parsed.model)
}

// Usage example
let config = parse_config_file("path/to/config.md");

The library exposes the same entry points for text already in memory: parse_literate_str for markdown, parse_cola_str for bare cola, and parse_str, which treats text as literate when it contains a cola fence and as bare cola otherwise. Consumers do not need a rustemo dependency.

Accessing Configuration Values

The generated code provides accessor methods for retrieving values:

// Get the LLM configuration
let llm = config.llm();

// Access a singular entity's properties
let provider = llm.provider();  // Returns a &String

// Access a collection (plural entity)
let models = llm.models();

// Get a specific model from the collection
if let Some(gpt4) = models.get("gpt-4.1") {
    let context_window = gpt4.context_window();  // Returns an i64
    println!("GPT-4.1 context window: {}", context_window);
}

// Iterate through all models
for (name, model) in models.iter() {
    println!("Model: {}, Context: {}", name, model.context_window());
}

Optional Fields

Optional fields are represented as Option<T> types:

// Optional field access with safe pattern matching
if let Some(api) = llm.api() {
    if let Some(key) = api.key() {
        println!("API Key: {}", key);
    }
}

// Using map() for clean optional chaining
let api_type = llm.api().and_then(|api| api.type_()).unwrap_or("No API type specified");

πŸ“„ Embedded Markdown Support

Colap parses configurations directly from Markdown. Any fenced block whose language is cola is parsed, supporting documentation-driven development. The rest of the document is prose and is never looked at: headings, tables, blockquotes, HTML, lines starting with inline code or a bare #, and fenced blocks in any other language are all fine.

Fences follow CommonMark:

  • an opening fence is three or more backticks or tildes, indented by at most three spaces, followed by an info string whose first word is the language (```cola, ~~~cola, ```cola title="LLM providers");
  • the closing fence uses the same character and is at least as long, so a four-backtick block can quote a three-backtick cola example without it being parsed;
  • a fence that is never closed runs to the end of the file and is reported as a warning naming its opening line.

Files named .md or .markdown are always read as literate documents; any other file is read as literate when it contains a cola fence and as bare cola otherwise.

The full rules are in the spec, section 2.

πŸ” Reopening and duplicates

A name directly under a plural header is a key: it identifies an entry. Every other entity name is a slot: it names a place in the configuration. The rules follow that line.

  • Slots may be reopened. The same declaration at the same path continues the same entity, so a collection can be written in batches with prose between them, and a section can be split by narrative:

    claim plural claims:
        cl-1: subject: "a";
    ;
    

    Some prose, then more entries of the same collection:

    claim plural claims:
        cl-2: subject: "b";
    ;
    

    Reopening a slot with a different declaration β€” another plural name, or singular where it was plural β€” is an error.

  • Keys are defined once. A second cl-1 under claims, in the same block or a later one, is an error. That also means a key cannot be reopened to batch a nested collection under it: entries of llm/openai/models are written in one block.

  • Fields are set once, and an entity has one namespace: a name is a field or an entity, never both, and model plural models reserves both model and models in its parent.

Every duplicate is reported, not just the first, with both locations:

ledger.md:21:5: duplicate entry `cl-1` in `claim`; first at 18:5

The design record docs/design/2026-10-29-duplicate-key-semantics.md has the reasoning, and the spec, section 5, the rules in full.


πŸ“œ License

This project is licensed under the Apache License 2.0.

Copyright 2025-2026 Hans Van Wesenbeeck (hvw@aivolution.ch)

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you shall be licensed under the Apache License 2.0, without any additional terms or conditions (Section 5 of the license).


Dependencies

~7–10MB
~177K SLoC