Reference
Grammar
The syntax of µLang v1 in EBNF. It describes what parses. The executable subset then decides what can run, and a bounds scan runs before parsing.
Download ulang-v1.ebnf. It is explained in Syntax.
file = { contract } ;
contract = "CONTRACT" name "{"
[ mode ] [ context ] [ trigger ]
[ guarantee ] [ prohibition ] [ observability ]
"}" ;
mode = "ENFORCEMENT_MODE" ":"
( "enforced" | "ENFORCED" | "advisory" | "ADVISORY" | "audit" | "AUDIT" ) ;
context = "CONTEXT" "{" { entities } [ constants ] "}" ;
entities = "ENTITIES" [ name ] "{" field { field } "}" ;
field = name ":" type ;
type = "int" | "float" | "bool" | "string"
| name [ "<" type { "," type } ">" ] ;
constants = "CONSTANTS" [ name ] "{" { constant } "}" ;
constant = name ":" type ( "==" | "=" ) literal [ source ] ;
trigger = "TRIGGER" "{" event { event } "}" ;
event = name [ "(" [ args ] ")" ] [ "WHEN" condition ] ;
guarantee = "GUARANTEE" "{" { "ENSURE" clause } "}" ;
prohibition = "PROHIBITION" "{" { "FORBID" clause } "}" ;
clause = name [ "(" [ args ] ")" ] [ "WHEN" condition ] [ source ] ;
observability = "OBSERVABILITY" "{" { "LOG" string "ON" word } "}" ;
source = "[" "SOURCE:" text "]" ;
condition = conjunction { "OR" conjunction } ;
conjunction = primary { "AND" primary } ;
primary = "(" condition ")"
| value [ op value ]
| word "=" value ; (* assignment: outside the subset *)
op = "==" | "!=" | "<=" | ">=" | "<" | ">" ;
value = term { "-" integer } ; (* subtraction: outside the subset *)
term = integer | float | string | boolean
| word [ "(" [ args ] ")" ] (* a call: outside the subset *)
| "(" value ")" ; (* right-hand side only *)
args = value { "," value } ;
literal = integer | float | string | boolean ;