Library

Complex Examples

Written by dbalabs | Mar 10, 2026 7:39:22 PM

This page brings the grammar rules together into complete examples. Each example shows how the notation, tokenization rules, repetition model, and binding semantics work together in real command shapes.

Good examples do more than compile. They make the intended authoring contract obvious to future maintainers.

Simple command

PING ;

This is the smallest complete command shape: one keyword phrase followed by a literal delimiter.

Optional clause with a parameter

CREATE USER username [ PASSWORD password ] ;
CREATE USER john ;
CREATE USER john PASSWORD secret ;
  • username is always required.
  • PASSWORD password is optional as one unit.
  • If the clause is absent, no password capture exists.

Required branching

PROCESS { FILE file_path | DIRECTORY dir_path } ;
PROCESS FILE 'report.pdf' ;
PROCESS DIRECTORY '/srv/archive' ;

The required group forces one declared branch to succeed. The order of branches matters if two branches could compete on a shared prefix.

Canonical repetition

GRANT ACCESS TO target_user ... ;
GRANT ACCESS TO alice bob charlie ;

This is the canonical one-or-more repetition form. Each captured user is produced in encounter order.

Repeated alternatives inside a required group

BLOCK TRAFFIC FROM { IP ip_address | SUBNET subnet_mask } ... ;
BLOCK TRAFFIC FROM IP 10.0.0.1 SUBNET 255.255.255.0 ;

Each repetition must match one whole branch of the required group. The group does not partially match one branch and then switch in the middle of the same occurrence.

Repeated optional group

GENERATE REPORT [ WITH metric_name ] ... ;
GENERATE REPORT ;
GENERATE REPORT WITH cpu WITH ram ;

Because the repeated unit is optional, the effective cardinality is zero or more. This is valid, but it should be used carefully and tested thoroughly.

Macro-based runtime vocabulary

EXECUTE ${available_tasks} ON target_name ;
EXECUTE full backup ON db01 ;
EXECUTE 'COMPLEX.TASK' ON db01 ;

The grammar stays stable while the allowed task values come from the macro registry at runtime.

Literal delimiter example

SET DATE day . month . year ;
SET DATE 07 . 03 . 2026 ;

The dots are literal punctuation, not repetition markers.

Enterprise-style example

PROVISION USER username [ WITH AGE user_age ] { AS ACTIVE | AS SUSPENDED } [ FORCE ] ;
PROVISION USER maria AS ACTIVE ;
PROVISION USER maria WITH AGE 34 AS SUSPENDED FORCE ;
  • username is mandatory.
  • WITH AGE user_age is an optional context-bearing clause.
  • One status branch is required.
  • FORCE is an optional clause flag.

Why these examples matter

Together, these examples cover the dominant grammar patterns used in production DSLs: minimal commands, optional clauses, branch selection, controlled repetition, runtime-driven vocabulary, and exact clause binding.

See also