DEV Community

CrabPascal
CrabPascal

Posted on • Edited on

Introducing CrabPascal — Pascal with Rust Claws 🦀 | Apresentando o CrabPascal

Bilingual post · Post bilíngue

Jump to: English · Português


English {#english}

Introducing CrabPascal

CrabPascal is an open-source Pascal compiler and runtime written in Rust. It targets developers who work with Delphi and Free Pascal and want a modern toolchain: fast feedback, a real CLI, VS Code / Cursor integration, and enough language parity to run real-world examples — without installing a full Delphi IDE.

Current version: v2.22.0.

Why another Pascal compiler?

Delphi and FPC are mature, but they can feel heavy for quick experiments, CI pipelines, or teaching. CrabPascal focuses on:

  • Fast compile-check loop — crab-pascal check with real line/column diagnostics
  • Run without codegen — interpreter/runtime for rapid iteration
  • Optional native build — build-exe emits C and compiles with gcc/clang
  • Modern RTL shims — System.*, generics collections, classes, exceptions (in progress by sprint)
  • Zero Delphi license — MIT, Rust toolchain only

Hello, world

program HelloWorld;
begin
  WriteLn('Hello from CrabPascal!');
end.
Enter fullscreen mode Exit fullscreen mode
crab-pascal run HelloWorld.dpr
crab-pascal check HelloWorld.dpr
Enter fullscreen mode Exit fullscreen mode

REST API in Pascal (Horse)

CrabPascal ships examples using Horse, a popular Delphi HTTP framework:

program SimpleAPI;
uses Horse, System.JSON;

begin
  THorse.Get('/ping',
    procedure(Req: THorseRequest; Res: THorseResponse; Next: TNextProc)
    var J: TJSONObject;
    begin
      J := TJSONObject.Create;
      J.AddPair('message', 'pong');
      Res.Send(J.ToJSON);
    end);

  THorse.Listen(9000);
end.
Enter fullscreen mode Exit fullscreen mode

Run it, then curl http://localhost:9000/ping — real HTTP, real JSON.

Tooling

Command Purpose
check Lex + parse + semantic analysis
run Execute via internal runtime
build-exe Generate C + native binary
preproc Handle {$IFDEF} directives

There is also a VS Code / Cursor extension (crabpascal.crabpascal) with problem matchers, tasks, and optional auto-install of the compiler binary on Windows.

Project status (2026)

CrabPascal is actively developed in versioned sprints (roughly one release per sprint). Recent focus areas:

  • Real diagnostic spans
  • System.* namespaces and RTL coverage
  • OOP: classes, properties, exceptions
  • Delphi-style strings and Unicode
  • Generics (TList<T>, TDictionary<K,V>)
  • Parser hardening and honest build-exe parity with run

It is not a drop-in replacement for Delphi yet — but it is already useful for learning, prototyping, and running curated examples from the repo.

Get involved

More deep-dive articles coming soon: generics, the runtime model, and how we approach Delphi compatibility sprint by sprint.


Português {#portugus}

Apresentando o CrabPascal

O CrabPascal é um compilador e runtime Pascal open source escrito em Rust. Ele mira quem trabalha com Delphi e Free Pascal e quer uma toolchain moderna: feedback rápido, CLI de verdade, integração com VS Code / Cursor e paridade suficiente para rodar exemplos reais — sem instalar um IDE Delphi completo.

Versão atual: v2.22.0.

Por que outro compilador Pascal?

Delphi e FPC são maduros, mas podem ser pesados para experimentos rápidos, pipelines de CI ou ensino. O CrabPascal foca em:

  • Loop rápido de verificação — crab-pascal check com diagnósticos reais (linha/coluna)
  • Executar sem codegen — interpretador/runtime para iterar rápido
  • Build nativo opcional — build-exe gera C e compila com gcc/clang
  • RTL moderno — shims System.*, generics collections, classes, exceptions (evoluindo por sprint)
  • Sem licença Delphi — MIT, só precisa do toolchain Rust

Hello, world

program HelloWorld;
begin
  WriteLn('Hello from CrabPascal!');
end.
Enter fullscreen mode Exit fullscreen mode
crab-pascal run HelloWorld.dpr
crab-pascal check HelloWorld.dpr
Enter fullscreen mode Exit fullscreen mode

API REST em Pascal (Horse)

O CrabPascal inclui exemplos com Horse, framework HTTP popular no ecossistema Delphi:

program SimpleAPI;
uses Horse, System.JSON;

begin
  THorse.Get('/ping',
    procedure(Req: THorseRequest; Res: THorseResponse; Next: TNextProc)
    var J: TJSONObject;
    begin
      J := TJSONObject.Create;
      J.AddPair('message', 'pong');
      Res.Send(J.ToJSON);
    end);

  THorse.Listen(9000);
end.
Enter fullscreen mode Exit fullscreen mode

Execute e teste com curl http://localhost:9000/ping — HTTP e JSON de verdade.

Ferramentas

Comando Função
check Lex + parse + análise semântica
run Executa via runtime interno
build-exe Gera C + binário nativo
preproc Trata diretivas {$IFDEF}

Há também extensão para VS Code / Cursor (crabpascal.crabpascal) com problem matcher, tasks e auto-instalação opcional do binário no Windows.

Status do projeto (2026)

O CrabPascal evolui em sprints versionadas (cerca de uma release por sprint). Focos recentes:

  • Spans reais nos diagnósticos
  • Namespaces System.* e cobertura da RTL
  • OOP: classes, properties, exceptions
  • Strings estilo Delphi e Unicode
  • Generics (TList<T>, TDictionary<K,V>)
  • Parser mais robusto e paridade honesta entre run e build-exe

Ainda não substitui o Delphi por completo — mas já serve para aprender, prototipar e rodar os exemplos curados do repositório.

Participe

Em breve: artigos sobre generics, modelo de runtime e como abordamos compatibilidade com Delphi sprint a sprint.


Published on dev.to/@crabpascal · Código em CrabPascal

Top comments (0)