Skip to content

FlowDSL syntax reference

FlowDSL declares a graph as text. FlowDslParser::parse(string $source): array produces the flat graph representation; SchemaImporter::importDsl(string $code): Graph also constructs and validates the graph. A syntactically valid declaration can therefore still fail a reference, presentation or rule check.

This reference uses NAME, INT, STRING and VALUE as notation for token categories, not literal words to type. Examples labelled as fragments belong inside the stated surrounding declaration. For a progressive introduction, see FlowDSL; for entity constraints, see the graph definition schema.

Category Accepted form
Keyword Case-sensitive words such as flow, nodes, meta and when. The TimeDSL body has its own keyword rules.
NAME An unquoted atom or a double-quoted string. Use quotes for whitespace or delimiter characters in graph codes, rule names, map keys or language names.
STRING Double-quoted JSON string, including JSON escapes such as \n, \" and Unicode escapes. Single quotes are not string delimiters.
INT Signed decimal integer, without a leading plus or redundant leading zeros; within the PHP integer range. IDs cannot be quoted or fractional.
Numeric VALUE JSON-style integer or finite floating-point number, including exponent notation. Out-of-range integer literals and nonfinite numbers are rejected.
Other scalar VALUE A quoted string, true, false or null. Bare names are not general string values.
Array VALUE [VALUE, VALUE]; [] is allowed. No trailing comma.
Map VALUE {NAME: VALUE, NAME: VALUE}; {} is allowed. Keys may be quoted; duplicate keys are rejected.
Comments // to end of line and /* ... */ block comments.
Whitespace Spaces and line breaks separate tokens; indentation does not create structure.

The lexer recognises ->, ==, !=, >=, <=, braces, brackets, comma, colon, semicolon, =, < and >. Recognising a token does not make it valid in every production: a single = is not a context comparison operator.

An optional semicolon follows a flow-level declaration, a field inside a node or edge body, or a field inside a meta, label, condition or output object. It is not a universal terminator: do not append it after individual node, edge, terminal or output declarations inside their collection blocks. Nested values use commas. Value parsing rejects a recursive depth greater than 64.

A document contains exactly one flow NAME { ... } and no trailing input. Each flow-level declaration can occur once. Their order is flexible.

Declaration inside flow Flat field / effect Default or restriction
graph_id INT graph_id Omit for null.
lang NAME, NAME allowed_langs Omit for []. At least one name when declared.
default_lang NAME default_lang If omitted, first declared language or null.
default_lang null Explicit null default language Keeps the default unset even when lang exists.
version NAME graph_version Optional. Graph-version compatibility still applies.
dsl_version NAME, schema_version NAME Corresponding model version Optional.
tags [VALUE, ...] Import annotations Each value must be exactly "stable", "draft" or "deprecated".
nodes { ... } Node declarations Required, including exactly one root flag.
edges { ... } Edge declarations Required, even when checking an otherwise incomplete fragment.
terminals { ... } Terminal marking and outputs Optional.
webhooks VALUE Graph subscriptions An array/map value is required syntactically; subscription validation then checks its shape.

description and default_context at flow level are explicitly unsupported. Other unknown flow fields are also errors. Context is supplied by your application when using the engine.

Tags are checked while importing and may produce deprecation warnings. They are not a stored Graph field and are not reconstructed by export.

The node production is node INT [root] [terminal] [{ ... }]. The square brackets here denote optional syntax; do not type them. Each flag may occur once, and their order may be reversed. Graph validation rejects a root that is terminal.

A node body accepts repeated meta NAME { ... } declarations for distinct languages and at most one webhooks VALUE. Node IDs must be unique.

Field inside meta LANGUAGE { ... } Syntax Contract
id INT Optional metadata persistence ID.
title STRING Required. Graph validation requires nonblank text.
subtitle, description STRING or null Optional; default null.
extras Array/map VALUE or null Optional; default null.

Each field can appear once in a metadata block. For example, this node fragment declares an English title and application-specific screen data:

node 1 root {
meta en {
title "Select a result"
extras {"screen": "selection", "ratios": [1.0, 2]}
}
}

The parser adds node_id: 1 and lang: "en" to the metadata row. The decimal 1.0 remains a float; the integer 2 remains an integer.

An edge always has a body, which may be empty:

edge 10: 1 -> 2 {}

The first integer is the edge ID; the next two are the source and destination node IDs. Edge IDs must be unique. Endpoint existence, self-loops and repeated connections are checked by graph validation.

An edge body accepts label, when and at most one webhooks declaration. Labels use:

label en "Confirm" {
description "Confirm the current selection."
extras {"icon": "check"}
}

The body following the label text is optional. Its only fields are description (string/null) and extras (array/map/null). Each edge may have one label per language. The parser supplies the label’s edge_id.

Conditions: full form and actual shorthand

Section titled “Conditions: full form and actual shorthand”

Each when adds conditions to the containing edge. Conditions are combined with AND in their declared order; there is no general or production.

Form inside an edge Produced condition
when condition NAME { params VALUE version STRING } rule: NAME, with the given parameter array/map and optional version. The params field defaults to []; version can be omitted or null.
when context_value NAME OP VALUE context_value with key, operator and value.
when context_value NAME exists context_value with operator: "exists" and value: null.
when context_value NAME not_exists Same shape with operator: "not_exists".
when visited_node INT visited_node with nodeId: INT; the normal required-visit default applies.
when rule STRING custom_rule with handler: STRING. Registration and execution dependencies still apply.
when time { ... } One or more canonical temporal conditions compiled from TimeDSL.

Context shorthand accepts exactly ==, !=, >, <, >=, <=, in, not_in, exists and not_exists. The operator must be unquoted. Existence operators take no operand; the others require a typed VALUE.

For example, the following fragment requires one of two service levels:

when context_value tier in ["standard", "priority"]

It creates {"rule":"context_value","params":{"key":"tier","operator":"in","value":["standard","priority"]}}. The runtime membership comparison is strict about types.

Use the full form for contains, not_contains, selected_edge, negative history flags and other parameter combinations. There is no shorthand when selected_edge 11 or when context_value name contains "x". This valid fragment expresses the latter:

when condition context_value {
params {"key": "name", "operator": "contains", "value": "x"}
version "1.0.0"
}

The full form retains its rule name; it does not apply the nested schema’s RuleFactory aliases. Use evaluator names from Built-in rules and condition parameters. A registered extension can use its own rule name through the full form, subject to the loader’s registration/validation configuration.

Inside terminals, write terminal INT { output NAME { ... } ... }. The node must also be declared in nodes. A terminal block marks that node terminal, even if its node declaration omitted the flag. Each node may have only one terminal block; it can contain zero or several outputs.

Field inside output TYPE { ... } Syntax and meaning
lang Optional language NAME. Omit for a language-neutral output; unquoted null here is a name, not a null literal.
url, content, label, open_behavior Optional STRING or null, subject to the selected output type’s validation.
value Optional STRING alias: becomes url for url/redirect, or content for content.

value is ambiguous for mixed and custom types, so it is rejected there. Do not supply both value and its target field. Output fields cannot repeat, and unknown fields are rejected even when the output type is registered.

A terminal fragment with separate display content and a link is:

terminal 2 {
output content { lang en value "Confirmed." }
output url { lang en url "https://example.org/confirmation" label "Open" }
}

These declarations produce data for your application to display. They do not open the URL. The payload reference describes the emitted output fields and language selection.

The complete reference.flowdsl exercises graph configuration, bilingual metadata and labels, three condition forms, a temporal condition, a webhook subscription and terminal outputs. Its root 1 offers confirmation at terminal 2 or information at terminal 3. Importing the subscription configures data only; it does not make a delivery.

For an existing Composer project, these are the relevant operations. $source is the complete FlowDSL string and $graph is the returned graph:

use ExecKernel\Infrastructure\Importer\SchemaImporter;
use ExecKernel\Infrastructure\Importer\FlowDsl\FlowDslExporter;
$graph = (new SchemaImporter(strict: true))->importDsl($source);
$canonical = (new FlowDslExporter())->export($graph);

The exported string preserves represented graph data and meaningful list order. It writes conditions in full form, emits an explicit default_lang, and does not preserve comments, original whitespace, shorthand spelling or import-only tags. Reimporting the complete fixture’s export gives the same portable graph definition.

Failure Diagnostic
Invalid token, string escape, missing punctuation or trailing input ImporterParseException, EK-LOADER-004, with format: "flowdsl", reason, line and column
Duplicate declaration, node/edge ID, metadata language or label language Parser reason such as duplicate_declaration, duplicate_node or duplicate_edge
Unsupported field unsupported_graph_field, unknown_flow_field, unknown_field or the node/edge-specific reason
Unsupported shorthand rule_block_required or invalid_context_operator
No root or multiple roots MissingRootException or MultipleRootsException
Temporal syntax inside when time A TimeDSL diagnostic; see the temporal error table
Valid syntax with invalid graph references or parameters Graph validation, after parsing; see Graph validation and diagnostics

Changing ready == true to ready = true in the downloadable file yields reason invalid_context_operator, line 31, column 32. The position belongs to that exact file; edits change it. expected may be null or name the token/field the parser expected. Keep these coordinates with the diagnostic rather than treating every EK-LOADER-004 as malformed JSON.