Tanguv0.35.0
.data.tan.schema.tan#shtml#css#svg#sql
Raw Markdown

Data, UI & SQL DSLs

Unify data manifests, validation schemas, SHTML templates, scoped stylesheets, SVG graphics, and parameterized SQL in one AST.

Tangu extends uniform s-expression syntax across configuration manifests, schemas, HTML templates, CSS stylesheets, inline vector graphics, and parameterized SQL queries. Every dialect parses into a single AST representation with full editor, formatter, and lint support.

Structured data (.data.tan) #

Use .data.tan for application configuration, package manifests (manifest.data.tan), localization catalogs, and static structured datasets. Data files restrict syntax to pure literals—maps, keyword symbols, arrays, strings, numbers, and booleans—with zero arbitrary code execution.

{
    :name "billing-api"
    :version "1.4.0"
    :server {
        :host "0.0.0.0"
        :port 8080
    }
    :features [:metrics :rate-limit :structured-logs]
}

Keys are commonly written as keyword symbols (:port 8080) or strings ("Content-Type"). When a key name matches a bound symbol or field shorthand, _ value expands cleanly inside maps.

Schema validation (.schema.tan) #

Define reusable data contracts with Struct and field constraint metadata (#{...}), then verify .data.tan files directly from the CLI or validate runtime inputs with /validation:

#pub
(def Service-Config (Struct
    #String #{:min-len 2 :max-len 64} name
    #Int #{:min 1 :max 65535} (#Int port 8080)
    #String #{:one-of ["dev" "staging" "prod"]} (#String env "dev")
))

Verify data files against a schema or generate conformant sample manifests from the CLI:

tangu schema check config.schema.tan manifest.data.tan
tangu schema sample config.schema.tan

HTML & SHTML templates (#shtml, #html) #

The #shtml (structured HTML) and #html reader tags construct native HTML node trees inside Tangu functions without external string-template engines. Text nodes are HTML-escaped by default; wrap trusted pre-rendered fragments in [:!raw ...] only when emitting sanitized HTML or SVG markup.

(use {parse-component-params} /web/app)

#pub
(def <status-card> (Func [...params]
    (let [attrs content] (parse-component-params params))
    (let title (some-or attrs:title "Service"))
    (let badge (some-or attrs:badge "ok"))

    #shtml [:article.tech-card {:data-state badge}
        [:header.flex.items-center.justify-between.gap-2
            [:h3.type-title-m title]
            [:span.mod-tag badge]
        ]
        (unless (is-empty? content)
            [:div.mt-2 content]
        )
    ]
))

Template rules and best practices:

  • Class shorthand: Chain utility classes directly on element tags ([:div.flex.items-center.gap-2]). Avoid decimal numbers in dot-shorthand (for example, prefer .gap-2 or {:class "..."}).
  • Comprehensions: Use (for->seq [item items] [:li item]) to project arrays directly inside element bodies without intermediate string buffers.
  • Formatting: Format #html and #shtml structures with /repr/html (format-html), or pass complete documents directly to respond-html in /web/app.

Scoped stylesheets (#css) #

Write stylesheets using #css s-expression vectors combining CSS selectors, property maps, nested selectors (&:hover, @media blocks), and design tokens. Compile #css data directly through /repr/css (format-css), which supersedes the legacy /dialect/css-expr module.

(use {format-css} /repr/css)

(let sheet #css [
    [":root" {
        :--surface "#fbfcfe"
        :--ink "#0f172a"
    }]
    [".tech-card" {
        :background-color "var(--surface)"
        :color "var(--ink)"
        :border "1px solid currentColor"
        :padding "20px"
    }
        ["&:hover" {:transform "translateY(-1px)"}]
    ]
    ["@media (min-width: 840px)" {}
        [".tech-card" {:padding "24px"}]
    ]
])

(let css-text (format-css sheet))

Inline vector graphics (#svg) #

Author theme-aware diagrams, icons, and illustrations with #svg. Because attributes are standard key-value maps, you can drive stroke, fill, and label typography from CSS custom properties (var(--color-primary)) so inline SVGs automatically switch between light and dark themes.

#pub
(def <brand-mark> (Func ()
    #svg [:svg {:xmlns "http://www.w3.org/2000/svg" :width "24" :height "24" :viewBox "0 0 24 24" :aria-hidden "true"}
        [:rect {:x "2" :y "2" :width "20" :height "20" :fill "none" :stroke "var(--color-primary)" :stroke-width "2"}]
        [:circle {:cx "12" :cy "12" :r "4" :fill "var(--color-primary)"}]
    ]
))

Parameterized SQL (#sql) #

Tag SQL queries with #sql and bind parameters as positional arguments to /postgres/client or /sqlite/client rather than interpolating user input into query strings.

(use {await} /coro)
(use {query-one-strong} /postgres/client)

#pub
(def insert-event (Func [pool #String kind #String payload]
    (await (query-one-strong
        pool
        #sql "INSERT INTO events (kind, payload) VALUES ($1, $2) RETURNING id, created_at"
        kind
        payload
    ))
))

Static analyzers validate balanced #sql strings and preserve syntax highlighting inside editors and documentation blocks.