A plain-text DSL for authoring professional documents that compiles to .docx.
LDOC is designed for legal and structured document authoring β numbered clauses, exhibits, headers/footers, tables, cross-references β without fighting a word processor. Write in a clean directive-based syntax, compile to fully-formatted DOCX.
- Directive-based syntax β structured, readable, and unambiguous
- Compiles to DOCX/OOXML β real Word-compatible output with styles, numbering, and sections
- Lua expressions β computed values and templates via embedded Lua (
$(...)and@lua{...}) - LSP server β completions, diagnostics, and go-to-definition for editor integration
- Includes β split large documents across files with
@include - Language-quality diagnostics β precise error locations with recovery
LDOC uses three core constructs:
Paragraph blocks β [...] for text content:
[This is a paragraph. It can contain inline @style(bold: true){directives} and $(lua_expressions).]
Directives β @name(args){ body } for structure and formatting:
@document(title: "Service Agreement", author: "Ari")
@style(p: { use: "Heading1" })[Section 1. Definitions]
[The following terms apply throughout this agreement.]
List markers β @- for bullets, @# for numbered lists:
@#[Party A shall provide the services described herein.]
@#[Party B shall remit payment within 30 days of invoice.]
# Install dependencies
bun install
# Create a new document
bun run ldoc init
# Compile to DOCX
bun run ldoc compile document.ldoc
# Compile with explicit output path
bun run ldoc compile agreement.ldoc -o output/agreement.docx
# Validate syntax
bun run ldoc validate document.ldoc
# Inspect the parse tree
bun run ldoc parse document.ldoc --json@document(
title: "Software Services Agreement",
author: "Acme Corp",
)
@def(
effective_date: "March 1, 2026",
)
@style(p: { use: "Heading1" })[1. Services]
[This Agreement is entered into as of $(effective_date).]
@style(p: { use: "Heading2" })[1.1 Scope of Work]
[Provider agrees to deliver the following:]
@#[Design and development of the application described in Exhibit A.]
@#[Monthly maintenance and support for a period of twelve (12) months.]
@#[Delivery of all source code upon project completion.]
src/
βββ parse/ # Lexer + parser β CST
βββ bind/ # Binder, resolver, validator
βββ evaluate/ # Directive evaluator + Lua runtime
β βββ directives/ # 20+ built-in directives
βββ emit/docx/ # DOCX/OOXML emitter
βββ lsp/ # LSP server (completions, diagnostics, navigation)
βββ pipeline/ # End-to-end compile pipeline
βββ cli/ # CLI entrypoint
LDOC ships a Language Server Protocol server for editor integration:
bun run src/lsp/server.ts --stdioSupports:
- Completion for directives and arguments
- Diagnostics with precise source locations
- Go-to-definition for
@defvariables and includes - Hover documentation
Core compiler and DOCX emitter are complete. A decompiler (DOCX β LDOC) is planned but not yet implemented.