(* µLang v1 grammar — https://ulang.dev/spec/v1/syntax Reference implementation: ulang-lite 61af4281ed6fd09d5f9f2100d3960630d757ae49 (MIT) *) 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 ;