Core Language

Quick Start & Rules Checklist

Core file structure, compilation modes, Four-Pillar ordering, identifier rules, statement terminators, and architectural comments.

Every .dhi file is a statically validated compilation unit. Files open with an optional dialect declaration—Dhi provides first-class support for the uml dialect (dialect uml;, covering 14 UML diagram types) alongside dialect-free Generic Diagrams—and contain at most one top-level diagram block (E001).

File Header, Modes & Single Diagram Rule

A .dhi file operates in Diagram Mode when it includes a flow { ... } block (rendering a full diagram), or in Module Mode when it omits flow { ... } and exports pub declarations from schema { ... } for reuse across other files (H005).

Minimal Four-Pillar sequence diagram
dialect uml;

uml::sequence_diagram "OAuth Login" {
  schema {
    lifeline actor @User;
    lifeline service @AuthSvc [label: "Auth Service"];
  }

  flow {
    User -> AuthSvc.login: "POST /login" => "200 OK";
  }

  layout {
    reference tracks: row [gap: 140] {
      lifeline @User;
      lifeline @AuthSvc;
    }
  }
}

The Four-Pillar Structure

  • 1. schema { ... }: Closed-world declarations of all entities, participants, states, ports, and whole-module imports. Must appear before flow, layout, and theme (E114).
  • 2. flow { ... }: Messages, transitions, class relationships, control fragments (alt/else/par/loop), and guarded branches referencing declared @Identifiers.
  • 3. layout { ... }: Declarative kinematic assembly triad (reference, branch, joint), inferred frame layouts, and arrow docking overrides with zero manual X/Y coordinates.
  • 4. theme { ... }: Declarative visual styling rules addressed by selector cascade. In v0.1.0 Early Preview, theme rules parse and validate while canvas rendering adapts directly to your active Light or Dark theme.

Mandatory Syntax & Terminator Rules

  • Mandatory Semicolons (;): Every non-block statement—including schema declarations, flow arrows, let bindings, and theme rules—must end with a semicolon (E004).
  • No Trailing Semicolon on Blocks ({ ... }): Declarations with a block body must terminate on } without a trailing semicolon (E009).
  • Unified // Comment Invariant: Every comment form starts with //. Bare # comments are forbidden (E006) because # is reserved exclusively for compiler attributes like #[owner(...)].

Identifier Rules & System Tokens

RuleRequirementExample / Diagnostic
Allowed CharactersASCII letters (a-z, A-Z), digits (0-9), and underscores (_)AuthSvc, Order_V2
Starting CharacterMust start with an ASCII letter (never a digit or underscore)User1 (not 1User)
No Hyphens or SpacesHyphens (-) are arrow/arithmetic operators and forbidden in IDsAuthSvc (not auth-svc)
Case SensitivityIdentifiers are strictly case-sensitiveAuthSvc != authSvc
Entity @ SigilEntity declarations in schema & layout require @ prefix@AuthSvc (E012 if missing)
System Tokens (*<Id>)Found/lost external endpoints in sequence diagrams use * prefix*ExternalWebhook (E130)

Architectural Comment System

Dhi uses a symmetric, Rust-inspired comment architecture where every comment begins with //. Doc comments desugar into #[doc("...")] attributes, while review and hazard comments surface directly as interactive pins and alerts.

DelimiterKindScopeTooling & Canvas Behavior
// ...Line CommentSingle-LineEphemeral developer note; discarded by compiler
//* ... *//Block CommentMulti-LineSymmetric block comment (E005 if unclosed)
/// ...Doc CommentSingle-LineDesugars into #[doc("...")]; surfaced in hover & inspector
//? ... / //? ... ?//Review Question / BlockSingle / Multi-LineSurfaces interactive discussion pin & card
//! ... / //! ... !//Hazard Alert / BlockSingle / Multi-LineSurfaces warning badge & mitigation card
Doc, review, and hazard comments in practice
/// Primary identity provider for OAuth 2.0 PKCE flows
//! Requires TLS 1.3 and strict redirect_uri matching
lifeline service @AuthSvc [label: "OAuth Server"];

//? Should token TTL be shortened to 5 minutes for high-risk scopes? ?//