Two texts read as the same tree, and they read at all.
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:
Written | Reads as | Claim |
|---|---|---|
|
| |
|
| |
|
| |
|
| Multiplication and division bind tighter than addition and subtraction. |
|
| 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 ")"