Author: Tales Marinho Godois
Status: Draft
Date: 2025-04-02
XGSL is a spreadsheet-as-code domain-specific language (DSL) designed to:
- Declaratively define spreadsheets using code.
- Export to Excel, Google Sheets, and LibreOffice with unified syntax.
- Enhance collaboration via version control, templates, and dependency management.
Spreadsheets are powerful but suffer from:
- Fragility: Manual edits break complex formulas.
- Versioning Issues: Git diffs for
.xlsxfiles are unreadable. - Repetition: No reusable templates/styles across teams.
XGSL solves these by treating spreadsheets as code-first artifacts.
// Define a data model
entity Product {
id: int
name: string
price: double
} // Compose entities into a table
@compose(Product, Sales)
@style(theme: corporate)
table ProductReport {
@label("Product ID")
id: Product.id
@label("Revenue") @style(currency)
revenue: Formula(Sales.units * Product.price)
} // Relative references and virtual variables
growth: Formula((.up.revenue - revenue) / .up.revenue) | Annotation | Purpose | Example |
|---|---|---|
@compose |
Merge entities/tables | @compose(Product, Sales) |
@style |
Apply formatting | @style(currency, bold) |
@label |
Customize column header | @label("Total Revenue") |
@import |
Import templates/data | @import("github:user/report-templates") |
// Inherit styles/structure
table Q4Report extends Q3Report.style { ... } - Compiler: Transpiles
.xgslto Excel/Sheets/LibreOffice. - Language Server (LSP): Autocomplete, diagnostics, hover docs.
- Formatter: Auto-format code with
xgsl fmt. - Dependency Management:
@import("github:org/templates@v1.2") // Git-based versioning
- Exporters:
- Excel (
.xlsx), Google Sheets (API), LibreOffice (.ods).
- Excel (
.xgsl File → Parser → AST → Semantic Analyzer → IR → Exporter → .xlsx/.ods
- Parser: PEG-based (using
pestornom). - AST: Represents entities, tables, formulas.
- Semantic Analyzer: Validates types, resolves dependencies.
- IR: Platform-agnostic spreadsheet structure.
- Exporter: Generates platform-specific files.
- Built with
tower-lspfor VS Code/IDE integration. - Features:
- Autocomplete for annotations/entities.
- Real-time error highlighting.
- Type Checks: Ensure formulas resolve to valid types.
- Circular References: Detect loops in formulas (e.g.,
A1 = B1 + A1). - Annotation Conflicts: Warn if
@styleoverrides are ambiguous.
- Syntax:
@import("github:user/templates@v1.0.0") @import("./lib/utils.xgsl")
- Resolver:
- Fetch dependencies via Git.
- Lock versions in
xgsl.lock.
- Parser + AST.
- Excel exporter.
- Basic CLI (
compile,fmt).
- Language Server (autocomplete, diagnostics).
- VS Code extension.
- Google Sheets API integration.
- Dependency resolver.
- Plugins: Custom exporters/formulas.
- Template Viewer: GUI to preview spreadsheets.
- Cloud Sync: Real-time collaboration.
# Install CLI
cargo install xgsl
# Compile to Excel
xgsl compile report.xgsl --target excel - IR: Intermediate Representation.
- LSP: Language Server Protocol.
- GitHub Repo:
https://github.com/talesmgodois/xgsl - License: MIT/Apache 2.0
This RFC is a starting point—feedback and contributions are welcome!