You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To ease adding facts, rules, or caveats, a simple grammar and a parser are available, allowing to declare biscuit elements as plain strings. See [GRAMMAR reference](./parser/GRAMMAR.md) for the complete syntax.
110
+
biscuit-go provides a datalog parser, allowing to input datalog elements as plain strings, along with support for parameter substitution.
111
+
112
+
See [GRAMMAR reference](./parser/GRAMMAR.md) for the complete syntax.
113
+
114
+
The parsers supports parsing whole blocks (containing several facts, rules and checks), whole authorizers (containing several facts, rules, checks and policies), as well as individual facts, rules, checks and policies. Parsing and adding elements individually is especially useful when doing so from inside a loop.
115
+
116
+
The `parser` module provides convenient helpers for parsing a string into datalog elements (`FromStringFact`, `FromStringRule`, `FromStringCheck`, `FromStringPolicy`, `FromStringBlock`, `FromStringAuthorizer`, for static datalog snippets, and their counterparts allowing parameter substitution: `FromStringFactWithParams`, `FromStringRuleWithParams`, `FromStringCheckWithParams`, `FromStringPolicyWithParams`, `FromStringBlockWithParams`, `FromStringAuthorizerWithParams`).
117
+
118
+
#### Panic on parsing errors
119
+
120
+
In most cases, `FromString*` functions will let you handle errors. If you do not wish to handle errors and instead crash on errors (for instance in one-off scripts), it can be done by first creating a parser instance, and using the `panic`-y functions:
Do note that these helpers take two arguments: a datalog snippet and a parameters map. If the datalog snippet does not contain parameters, `nil` can be passed as the second argument.
142
+
116
143
## Examples
117
144
118
145
-[example_test.go](./example_test.go) for a simple use case
Parentheses can be used to force precedence (or to make it explicit).
87
+
65
88
66
89
## Fact
67
90
68
-
A fact is a single predicate that does not contain any variables, e.g. `right(#authority, "file1.txt", #read)`.
91
+
A fact is a single predicate that does not contain any variables, e.g. `right("file1.txt", "read")`.
69
92
70
93
# Rule
71
94
72
95
A rule is formed from a head, a body, and a list of constraints.
73
-
The head is a single predicate, the body is a list of predicates, and followed by an optional list of constraints.
96
+
The head is a single predicate, the body is a list of predicates or constraints. Variables present in the head and in constraints must be introduced by predicates in the body.
74
97
75
-
It has the format: `Head <- Body @ Constraints`.
98
+
It has the format: `Head <- (predicate, constraint)+`.
0 commit comments