Expand description
§toon-lsp
A Language Server Protocol (LSP) implementation for TOON (Token-Oriented Object Notation).
TOON is a compact, human-readable encoding of the JSON data model designed for LLM prompts. This crate provides:
- AST with source positions - Full abstract syntax tree with span information
- Parser - TOON parser that produces positioned AST nodes
- LSP Server - Complete language server with diagnostics, symbols, and more
§Architecture
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Scanner │ ──▶ │ Parser │ ──▶ │ AST │
│ (Lexer) │ │ │ │ (with Spans)│
└─────────────┘ └─────────────┘ └─────────────┘
│
▼
┌─────────────┐
│ LSP Server │
│ (tower-lsp) │
└─────────────┘§Usage
use toon_lsp::{parse, AstNode};
let source = "user:\n name: Alice\n age: 30";
let ast = parse(source).expect("valid TOON");
// Every AST node carries source positions (Span)
let AstNode::Document { children, span } = &ast else { return };
assert_eq!(span.start.line, 0); // 0-indexed
// Walk objects via entries
for node in children {
if let AstNode::Object { entries, .. } = node {
assert_eq!(entries[0].key, "user");
}
}Error recovery for IDEs: parse succeeds even with syntax errors:
use toon_lsp::parse_with_errors;
let source = "config:\n debug: true\n port: 8080";
let (ast, errors) = parse_with_errors(source);
// Partial AST available for IDE features even with errors
assert!(ast.is_some());
// Errors carry spans for diagnostic rendering
for err in &errors {
let _ = (err.span.start.line, err.kind.clone());
}Re-exports§
pub use ast::AstNode;pub use ast::NumberValue;pub use ast::ObjectEntry;pub use ast::Position;pub use ast::Span;pub use parser::ParseError;pub use parser::ParseErrorKind;pub use parser::parse;pub use parser::parse_with_errors;pub use resolve::ResolveError;pub use resolve::ResolvedRef;
Modules§
- ast
- Abstract Syntax Tree types for TOON with source position tracking.
- cli
- Command-line interface for TOON operations.
- lsp
- Language Server Protocol implementation for TOON.
- parser
- TOON parser that produces AST with source positions.
- resolve
- Reference resolution for TOON (
${path}and${env:VAR}). - toon
- In-house TOON codec: spec-conformant encode/decode and shared emitter core.