Skip to content

BFL Syntax Reference

M. Mert Yıldıran edited this page Oct 23, 2021 · 22 revisions

Basenine Filter Language (BFL) is the language implemented inside Basenine database server that enables the user to query the traffic logs efficiently and precisely.

http and request.method == "GET" and request.path != "/example" and (request.query.a > 42 or request.headers["x"] == "y")

The syntax as a whole evaluates into a boolean outcome, always. Such that the record which makes the boolean true is a record that matches the filter.

There are certain helper methods that can do more than reducing into a boolean value.

Literals

The language supports the following literals:

  • Nil nil
  • Boolean true or false
  • Number 42, 3.14 etc.
  • String "hello world"
  • Regex r"prefix*"

Operators

Operations can be grouped (precedence) using parentheses (...)

The language supports the following operators:

Logical

and, or

Equality

==, !=

Comparison

>=, >, <=, <

Unary

!, -

Helpers

Helpers in BFL are method invocations that enables filtering capability which cannot be provided through the syntax. These are the available helpers in BFL:

startsWith(string)

Returns true if the given selector's value starts with the string. e.g. brand.name.startsWith("Chev")

endsWith(string)

Returns true if the given selector's value ends with the string. e.g. brand.name.endsWith("let")

contains(string)

Returns true if the given selector's value contains the string. e.g. brand.name.contains("ro")

datetime(string) integer

Returns the UNIX timestamp integer which is the equivalent of the time that's provided by the string. If the given date-time string is not in a recognized format then it evaluates to false. The format must be same as "01/02/2006 3:04:05 PM" e.g. timestamp > datetime("10/19/2021 6:29:02 PM")

Selectors

Selectors in BFL are JSONPath(s) that refers to the path in a JSON document. In Basenine, every record is a JSON document. Any selector that does not match a path is evaluated to false.

Following are some selector examples:

  • brand.name basic selector
  • request.path[1] index selector
  • request.headers["a"] == "b" key selector

Selectors can be combined with a subset of helpers such that they evaluate into a boolean without any operator. e.g. brand.name.startsWith("Chev") These are the list of helpers that can be used with selectors:

  • startsWith(string)
  • endsWith(string)
  • contains(string)

Such that instead of writing a boolean expression like brand.name == "Chevrolet", one of the following can be written:

brand.name.startsWith("Chev")
brand.name.endsWith("let")
brand.name.contains("ro")
Clone this wiki locally