Engine

3.9. Grammar🔗

How rule texts are written. In the YAML, on is read by parseSelector; requires, always and active by parseCondExpr; values by parseValueExpr; per by parsePer; the count of a grouped invariant by parseQuantity. A text has one meaning, and printing a rule gives a text that reads back to it (both on the Spec details page).

3.9.1. Precedence🔗

A text without parentheses groups by fixed rules; the table shows each with a second text that groups it explicitly. SameReading says both read as the same tree:

🔗def
Spec.SameReading {α : Type} (parse : String → Option α) (a b : String) : Prop
Spec.SameReading {α : Type} (parse : String → Option α) (a b : String) : Prop

Two texts read as the same tree, and they read at all.

Written

Reads as

Claim

never A where x = 1 and ever B

(never A where x = 1) and ever B

Where takes one test and and or end it.

A except B within 1 hour

A except (B within 1 hour)

Suffixes bind tighter than except.

not ever A and ever B or ever C

((not ever A) and ever B) or ever C

Not binds tighter than and and and tighter than or.

a + b * c - d / e

((a + (b * c)) - (d / e))

Multiplication and division bind tighter than addition and subtraction.

(a + 1) > 2

a + 1 > 2, the parentheses open a value

A paren opens a value when an operator follows else a condition.

3.9.2. Literals🔗

Text goes in single quotes, a quote inside is written twice ('it''s'); a negative number is written with its sign (-5), but -x is not a value, write 0 - x.

3.9.3. Summary🔗

Explanation, not a formal claim

A reading aid, not a claim; the parser is the definition, and the statements above are what is proved.

rule         = "on:" selector "requires:" condition
             | "always:" condition
             | "always:" quantity "per:" per {"," per} ["values:" {name ":" value}] ["active:" condition]
per          = value | "each" name "in" value
selector     = suffixed {"except" suffixed}
suffixed     = base {suffix}
base         = Type | Type "(" field {"," field} ")" | "[" [Type {"," Type}] "]" | "any" | "(" selector ")"
suffix       = "where" negation | "in" entity "(" value ")"
             | "within" number unit | "today" | "this" "week" | "this" "month"
condition    = conjunction {"or" conjunction}
conjunction  = negation {"and" negation}
negation     = "not" negation | test
test         = "ever" selector | "never" selector | quantity selector
             | "last" "of" selector "is" Type | value op value | value "is" ["not"] "null"
             | "(" condition ")"
quantity     = "no" | "at" "least" n | "at" "most" n | "exactly" n | "between" n "and" n
value        = product {("+" | "-") product}
product      = term {("*" | "/") term}
term         = literal | number unit | field | "$" field | "now" "(" ")"
             | "(" "last" "of" selector ")" "." field | "count" "(" selector ")"
             | ("sum" | "min" | "max") "(" (Type | "(" selector ")") "." field ")"
             | ("round" | "floor" | "ceil" | "lower") "(" value ")"
             | ("weekday" | "day" | "time_of_day") "(" value ")"
             | "range" "(" value "," value ")" | "(" value ")"