Skip to contents

Declaration vocabulary, without the r8_ prefix of operations on values: JSON text that a declaration carries into its IR as written: a rule's invariant or when as JSONLogic, or a field's default as the value's JSON form. It holds what the R forms do not express, such as an and of three operands, a default that is an enum variant with fields or a struct, and a number that a double does not hold exactly. r8document_rust() writes it where a Rust declaration has no R form.

Usage

json_ir(text)

Arguments

text

Character: One JSON text.

Value

An r8_json_ir: the text, of that class.

Examples

rule(json_ir('{"and": [{">": [{"var": "cost"}, 0]},
  {"<=": [{"var": "cost"}, 100]}, {"!==": [{"var": "name"}, ""]}]}'),
  message = "cost is in (0, 100] and name is not empty.", id = "COST_RANGE")
#> <r8 rule COST_RANGE> {"and":[{">":[{"var":"cost"},0]},{"<=":[{"var":"cost"},100]},{"!==":[{"var":"name"},""]}]}
#>   cost is in (0, 100] and name is not empty.
field(type_double(), default = json_ir("0.5"))
#> <r8 field> double = "0.5"