OcaltQL Syntax & EMIT

OcaltQL is designed to read like English and execute like a machine. Statements are built from verbs, subjects, and prepositions. The rules are minimal by design.

EMIT

EMIT is the output verb. Whatever follows it is written directly to the response. It is the equivalent of echo in PHP or print in Python.

Example
EMIT "Hello World"
Emitting a Variable
STRING "Hello World" SET ?msg
AFTER EMIT ?msg

How Values Are Written

EMIT writes a value in its output form. A string is written as it is and a number as its digits. An object is written as a JSON object. An array is written as its members separated by a comma and a space, each member in its own output form, with no surrounding brackets. That reads well for a list of words, but it is not JSON: an array of two objects is written as two JSON objects side by side, which no JSON parser accepts, while an array of one object is written as that object alone.

When the response is meant for a program, cast the value first. CAST ... AS JSON writes any value as exact JSON, brackets included, whatever it holds and however many members it has.

An Array, Written Two Ways
NEW OBJECT ["name" AS "Alice" AND "age" AS 30] SET ?person
AFTER NEW ARRAY SET ?people
AFTER APPEND ?person TO ?people
AFTER APPEND ?person TO ?people
AFTER EMIT ?people
(* Output: {"name": "Alice", "age": 30}, {"name": "Alice", "age": 30} *)
AFTER CAST ?people AS JSON SET ?json
AFTER EMIT ?json
(* Output: [{"name": "Alice", "age": 30}, {"name": "Alice", "age": 30}] *)

Statement Structure

Every OcaltQL statement follows this pattern:

[CHAIN] [SUBJECT] VERB [MODE] [ARGS] [PREPOSITION TARGET] [SET ?var]

Case Sensitivity

OcaltQL is case-insensitive for everything except variable names. EMIT, emit, and Emit are identical. ?var and ?Var are not.

Case Insensitivity
emit "Hello World"
after emit "This works too"
AFTER Emit "So does this"

String Delimiters

Double quotes, single quotes, and backticks are fully interchangeable as string delimiters.

Interchangeable Delimiters
EMIT "double quotes"
AFTER EMIT 'single quotes'
AFTER EMIT `backticks`

Line Rules

A fullstop at the end of a line is optional — it is not required and has no effect on execution. Multiple statements can sit on the same line. The chain keyword (AFTER, AND, OR) acts as the delimiter between statements on the same line.

Optional Fullstop
EMIT "Hello World".
AFTER EMIT "Same result"
Multiple Statements on One Line
EMIT "Hello" AFTER EMIT "World" AFTER EMIT "!"

Comments

Comments are wrapped in (* ... *). They are ignored by the parser and can appear anywhere in the script — inline or on their own line.

Comments
(* This is a comment *)
EMIT "Hello World" (* inline comment *)
AFTER EMIT "Done"

OPEN and CLOSE

OPEN and CLOSE define the body of conditional and loop blocks. They can be nested to any depth.

Nested Blocks
STRING "hello" SET ?var
AFTER IF ?var IS SET
OPEN
  EMIT "outer block"
  AFTER IF ?var IS EQUAL TO "hello"
  OPEN
    EMIT " — inner block"
  CLOSE
CLOSE

SET and Value-Returning Verbs

SET ?var is only valid when the verb produces a returnable value. Verbs that are pure side-effects — such as SAVE — do not accept SET. The runtime enforces this at the caller level per verb.

Valid SET Usage
CALCULATE 10 + 5 SET ?result
AFTER EMIT ?result