fql_serialize 0.2.6

Internal crate for serializing Fauna Query Language (FQL) requests.
Documentation
// Copyright Fauna, Inc.
// SPDX-License-Identifier: MIT-0

// From https://pest.rs/book/examples/json.html
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }

op = { "(" }
cp = { ")" }
ocb = { "{" }
ccb = { "}" }
osb = { "[" }
csb = { "]" }
comma = { "," }
colon = { ":" }

object = {
    ocb ~ ccb |
    ocb ~ pair ~ (comma ~ pair)* ~ comma? ~ ccb
}

pair = { string ~ colon ~ expr }

array = {
    osb ~ csb |
    osb ~ expr ~ (comma ~ expr)* ~ comma? ~ csb
}

value = _{ object | array | string | number | boolean | null }

boolean = { "true" | "false" }

null = { "null" }

string = ${ "\"" ~ inner ~ "\"" }

inner = @{ char* }

char = {
    !("\"" | "\\") ~ ANY
    | "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
    | "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}

number = @{
    "-"?
    ~ ("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*)
    ~ ("." ~ ASCII_DIGIT*)?
    ~ (^"e" ~ ("+" | "-")? ~ ASCII_DIGIT+)?
}

expr = _{
  fqlExpr |
  value
}

fqlExpr = {
  niladicExpr |
  monadicExpr |
  dyadicExpr |
  triadicExpr |
  quadraticExpr |
  variadicExpr
}

// To avoid conflicts on substrings, order more selective variants first 
// e.g. "Cosh" before "Cos"
niladicExpr = { niladicVerb ~ op ~ cp }
monadicExpr = { monadicVerb ~ op ~ expr ~ cp }
dyadicExpr = { dyadicVerb ~ op ~ expr ~ comma ~ expr ~ cp }
triadicExpr = { triadicVerb ~ op ~ expr ~ comma ~ expr ~ comma ~ expr ~ cp }
quadraticExpr = { quadraticVerb ~ op ~ expr ~ comma ~ expr ~ comma ~ expr ~ comma ~ expr ~ cp }
variadicExpr = { variadicVerb ~ op ~ expr ~ (comma ~ expr)* ~ cp }

niladicVerb = {
  "AccessProviders" |
  "Collections" |
  "CurrentIdentity" |
  "CurrentToken" |
  "Credentials" |
  "Databases" |
  "Functions" |
  "HasCurrentIdentity" |
  "HasCurrentToken" |
  "Indexes" |
  "Keys" |
  "NewId" |
  "Now" |
  "Roles" |
  "Tokens"
}

monadicVerb = {
  "Abort" |
  "Abs" |
  "Acos" |
  "Asin" |
  "All" |
  "Any" |
  "Atan" |
  "BitNot" |
  "Ceil" |
  "Cosh" |
  "Cos" |
  "Count" |
  "CreateAccessProvider" |
  "CreateCollection" |
  "CreateDatabase" |
  "CreateFunction" |
  "CreateIndex" |
  "CreateKey" |
  "CreateRole" |
  "Date" |
  "DayOfMonth" |
  "DayOfWeek" |
  "DayOfYear" |
  "Degrees" |
  "Delete" |
  "Documents" |
  "Events" |
  "Exp" |
  "Floor" |
  "Hour" |
  "IsArray" |
  "IsBoolean" |
  "IsBytes" |
  "IsCollection" |
  "IsCredentials" |
  "IsDatabase" |
  "IsDate" |
  "IsDoc" |
  "IsDouble" |
  "IsEmpty" |
  "IsFunction" |
  "IsIndex" |
  "IsInteger" |
  "IsKey" |
  "IsLambda" |
  "IsNonEmpty" |
  "IsNull" |
  "IsNumber" |
  "IsObject" |
  "IsRef" |
  "IsRole" |
  "IsSet" |
  "IsString" |
  "IsTimestamp" |
  "IsToken" |
  "KeyFromSecret" |
  "LTrim" |
  "Length" |
  "Ln" |
  "Logout" |
  "Log" |
  "LowerCase" |
  "Minute" |
  "Month" |
  "Not" |
  "Query" |
  "RTrim" |
  "Radians" |
  "RegexEscape" |
  "Reverse" |
  "Second" |
  "Sign" |
  "Singleton" |
  "Sinh" |
  "Sin" |
  "Space" |
  "Sqrt" |
  "Sum" |
  "Tanh" |
  "Tan" |
  "Time" |
  "TitleCase" |
  "ToArray" |
  "ToDate" |
  "ToDouble" |
  "ToInteger" |
  "ToMicros" |
  "ToMillis" |
  "ToNumber" |
  "ToObject" |
  "ToSeconds" |
  "ToString" |
  "ToTime" |
  "Trim" |
  "UpperCase" |
  "Var" |
  "Year"
}

dyadicVerb = {
  "Append" |
  "At" |
  "Casefold" |
  "ContainsField" |
  "ContainsPath" |
  "ContainsStrRegex" |
  "ContainsStr" |
  "ContainsValue" |
  "Create" |
  "Drop" |
  "EndsWith" |
  "Epoch" |
  "Filter" |
  "Foreach" |
  "Hypot" |
  "Identify" |
  "Join" |
  "Lambda" |
  "Let" |
  "Login" |
  "Map" |
  "MoveDatabase" |
  "Pow" |
  "Prepend" |
  "Ref" |
  "Replace" |
  "StartsWith" |
  "Take" |
  "Update"
}

triadicVerb = {
  "If" |
  "Range" |
  "Reduce" |
  "Remove" |
  "ReplaceStr" |
  "TimeAdd" |
  "TimeDiff" |
  "TimeSubtract"
}

quadraticVerb = {
  "Insert"
}

variadicVerb = {
  "AccessProviders" | // Accepts zero or one arguments
  "AccessProvider" | // Accepts one or two arguments
  "Add" |
  "And" |
  "BitAnd" |
  "BitOr" |
  "BitXor" |
  "Call" |
  "Collections" | // Accepts zero or one arguments
  "Collection" | // Accepts one or two arguments
  "Concat" | // Accepts one or two arguments
  "Credentials" | // Accepts zero or one arguments
  "Databases" | // Accepts zero or one arguments
  "Database" | // Accepts one or two arguments
  "Difference" |
  "Distinct" |
  "Divide" |
  "Do" |
  "Equals" |
  "Exists" | // Accepts one or two arguments
  "FindStrRegex" | // Accepts between two and four arguments
  "FindStr" | // Accepts two or three arguments
  "Format" |
  "Functions" | // Accepts zero or one arguments
  "Function" | // Accepts one or two arguments
  "GT" |
  "GTE" |
  "Get" | // Accepts one or two arguments
  "Indexes" | // Accepts zero or one arguments
  "Index" | // Accepts one or two arguments
  "Intersection" |
  "Keys" | // Accepts zero or one arguments
  "LTE" |
  "LT" |
  "Match" | // Accepts one or two arguments
  "Max" |
  "Mean" |
  "Merge" | // Accepts two or three arguments
  "Min" |
  "Modulo" |
  "Multiply" |
  "Or" |
  "Paginate" | // Accepts one or two argumnets
  "Repeat" | // Accepts one or two arguments
  "ReplaceStrRegex" | // Accepts three or four arguments
  "Roles" | // Accepts zero or one arguments
  "Role" | // Accepts one or two arguments
  "Round" | // Accepts one or two arguments
  "Select" | // Accepts two or three arguments
  "Substring" | // Accepts two or three arguments
  "Subtract" |
  "Tokens" | // Accepts zero or one arguments
  "Trunc" | // Accepts one or two arguments
  "Union"
}

fql = _{ SOI ~ expr ~ EOI }