BACONLang

BACONLang (Bracket Annotated CONstraint Language), or BACON is a lightweight constraint based logical language/format. It is valid JSON, and consequently easy for humans to read and write. It is easy for machines to parse and generate. BACON is a text format that is completely language independent that uses simple structures found in JSON, allowing for it to be sent over JSON based APIs and parsed in any language that supports JSON. These properties make BACON an ideal format for constraint based logical expressions.

BACON is solely built on arrays and strings - universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a constraint based logical format that is interchangeable with programming languages also be based on these structures.

BACON's foundation is the expression. An expression is an ordered list of elements. If an element within an outer expression is an expression, the inner expression evaluates before the outer expression does.

BACON consists of two types of expressions:

An ordered list of elements that start with [one left bracket and ends with ] one right bracket is an or expression. or expressions will always evaluate to the first valid element within the given set of elements.

An ordered list of elements that start with [[two left brackets and ends with ]]two right brackets is an and expression. and expressions will always evaluate to the entire set of elements if the set as a whole is valid.

An element can be an expression or string.

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. This is identical to the JSON string, with the addition of the comma as a control character.

Whitespace can be inserted between any pair of tokens. Excepting a few encoding details, that completely describes the language.


bacon
expression

expression
or
and

or
'[' elements ']'

and
'[' ws [' elements ']' ws ']'

elements
element
element ',' elements

element
ws string ws
ws expression ws

string
'"' characters '"'

characters
""
character characters

character
'0020' . '10ffff' - '"' - '\' - ','
'\' escape

escape
'"'
'\'
','

ws
""
'0020' ws
'000D' ws
'000A' ws
'0009' ws