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.
EMIT "Hello World"
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.
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]
- CHAIN -
AFTER,AND, orOR. Absent on the first statement. - SUBJECT - optional. A
?varthe verb acts upon. - VERB - the operation.
EMIT,CALCULATE,STRING,REPLACE, etc. - MODE - optional modifier on the verb.
ALL,ONCE,FROM...TO, etc. - ARGS - inputs to the verb. Literals or
?var. - PREPOSITION TARGET - verb-specific.
TO,INTO,WITH,WHERE,AS,FROM. The verb dictates which one applies. - SET ?var - optional. Captures the result. Only valid on value-returning verbs.
Modifiers Can Go in Any Order
The pattern above shows the usual order, not a required one. After the verb and the value it works on, the modifiers can be written in any order, the way attributes on an HTML tag can. A modifier is a keyword with its value, such as FROM 0, WITH "o", TIMEOUT 10 SECONDS or SET ?var. OcaltQL finds each one by its keyword, so where it sits does not matter.
REPLACE STRING ALL "a" WITH "o" WHERE "banana" SET ?x
REPLACE STRING ALL "a" WHERE "banana" WITH "o" SET ?x
REPLACE STRING ALL "a" SET ?x WHERE "banana" WITH "o"
(* All three give: bonono *)
FETCH "https://example.ocalt.com/api/echo.php" SET ?reply METHOD "POST" TIMEOUT 10 SECONDS
AFTER CONVERT IMAGE "/root/photo.png" SET ?path AS "/root/photo.webp" TO webp
A few things do stay fixed:
- The verb comes first. Write the value it works on straight after it. That is always safe.
- A keyword keeps its value.
FROM 0is one modifier and3 SECONDSis one value. They move together, never apart. - Each modifier once, unless the verb allows more than one, like
HEADERonFETCH. - A modifier that begins with AND (for example
COMPUTE power OF 2 AND 8) goes beforeSET. After a finished statement,ANDstarts a new statement that runs alongside it.
Case Sensitivity
OcaltQL is case-insensitive for everything except variable names. EMIT, emit, and Emit are identical. ?var and ?Var are not.
emit "Hello World"
after emit "This works too"
AFTER Emit "So does this"
String Delimiters
Double quotes, single quotes, and backticks all delimit a string, and any of them can span several lines.
Double and single quotes are interchangeable. Inside them a backslash starts an escape: \n is a new line, \t a tab, \r a carriage return, and a backslash before any other character keeps that character, so "say \"hi\"" holds say "hi".
Backticks are raw. Everything between two backticks stays exactly as written: backslashes, quotes, dollar signs and line breaks all reach the verb untouched. That is why code is written in backticks, such as a WEBASSEMBLY TYPE ... ENTER block or an SSH ... ENTER command. The one escape is \`, which writes a backtick inside the block; a backslash written just before a backtick is that escape.
EMIT "double quotes"
AFTER EMIT 'single quotes'
AFTER EMIT `backticks`
EMIT "line one\nline two"
AFTER EMIT `C:\new\table and \d+ stay as written`
AFTER EMIT `a backtick: \` inside`
(* line one
line two
C:\new\table and \d+ stay as written
a backtick: ` inside *)
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.
EMIT "Hello World".
AFTER EMIT "Same result"
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.
(* 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: OcaltQL is nestable everywhere; only operations are not nestable within each other.
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.
CALCULATE 10 + 5 SET ?result
AFTER EMIT ?result