From cbc7aace721cdef0bc0edefefe01f90c5a1b74aa Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Fri, 29 Oct 2021 22:25:05 +0200 Subject: [PATCH] add an EBNF grammar for Datalog --- SPECIFICATIONS.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/SPECIFICATIONS.md b/SPECIFICATIONS.md index 2bfabd2..5386d4c 100644 --- a/SPECIFICATIONS.md +++ b/SPECIFICATIONS.md @@ -144,6 +144,61 @@ A *boolean* is `true` or `false`. A *set* is a deduplicated list of terms of the same type. It cannot contain variables or other sets. +#### Grammar + +The logic language is descibed by the following EBNF grammar: + +``` + ::= ( | )* + ::= ? ( | | ) ? ";" ? + ::= ( | )* + ::= ? ( | | | ) ? ";" ? + + ::= "//" ([a-z] | [A-Z] ) ([a-z] | [A-Z] | [0-9] | "_" | ":" | " " | "\t" | "(" | ")" | "$" | "[" | "]" )* "\n" + + ::= "(" ? (? "," ? )* ? ")" + ::= ? "<-" ? + ::= "check" "if" + ::= ("allow" | "deny") "if" + + ::= ? ("," ? ?)* + ::= | + + ::= "(" ? (? "," ? )* ? ")" + ::= | + ::= | | | | | + + + ::= [0-9]+ + ::= "hex:" ([a-z] | [0-9] )+ + ::= "true" | "false" + ::= [0-9]* "-" [0-9] [0-9] "-" [0-9] [0-9] "T" [0-9] [0-9] ":" [0-9] [0-9] ":" [0-9] [0-9] ( "Z" | ( "+" [0-9] [0-9] ":" [0-9] [0-9] )) + ::= "[" ? ( ( ? "," ? )* ? )? "]" + + ::= (? ? )* + ::= | ( ? ) + ::= "!" ? + ::= "." "(" ? ( ( ? "," ? )* )? ? ")" + ::= ([a-z] | [A-Z] ) ([a-z] | [A-Z] | [0-9] | "_" )* + + ::= | ("(" ? ? ")") + ::= "<" | ">" | "<=" | ">=" | "==" | "&&" | "||" | "+" | "-" | "*" | "/" + + ::= (" " | "\t" | "\n")+ +``` + +The `name`, `variable` and `string` rules are defined as: +- `name`: + - first character is any UTF-8 letter character + - following characters are any UTF-8 letter character, numbers, `_` or `:` +- `variable`: + - first character is `$` + - following characters are any UTF-8 letter character, numbers, `_` or '=`:` +- ` string`: + - first character is `"` + - any printable UTF-8 character except `"` which must be escaped as `\"` + - last character is `"` + ### Scopes Since the first block defines the token's rights through facts and rules, and