---
title: BRL grammar
summary: The Xtext grammar of BRL as shipped in this release.
order: 900
---

# BRL grammar

The Xtext grammar the BIM Report Language parser is generated from, exactly as shipped in this release. Rules read top-down; `=>` marks a syntactic predicate, `+=` collects a list, `?=` a boolean flag. Terminals not declared here (`ID`, `STRING`, `INT`, comments) come from the common Xtext terminals; the languages that build on BQL inherit every rule from it.

```text {#grammar}
// BRL — BIM.works Reporting Language (docs/brl-design.md)
//
// Declarative report definitions: pages, blocks (tables, charts, viewports,
// trees, kpis, callouts), foreach/when control flow. Style-free: rendering
// emits semantic HTML with brl-* classes, a client-customizable stylesheet
// owns all presentation; page structure maps to CSS Paged Media for PDF.
//
// Mixin chain: Brl -> Bcl -> Bvl -> Bql (single inheritance, like Bcl/Bvl).
// Queries and checks are embedded first-class: `bql GET ...` / `bcl select ...`
// call the inherited Bql/Bcl entry rules directly on one shared AST. The
// introducer keywords are required because both entry rules can match (nearly)
// empty input — they make the BrlValue decision LL-deterministic.
//
// Shared-lexer consequences (one ANTLR lexer for the whole chain):
//  - Every keyword of Bql/Bvl/Bcl is reserved. BRL block/attribute names are
//    parsed as BrlName = ID | <re-allowed keywords>. When a new base-grammar
//    keyword collides with a report attribute name, add it to BrlName.
//  - $parameters inside embedded queries (e.g. WHERE buildingStorey.qid IN
//    $storey) are matched BY NAME against BRL let/foreach bindings by
//    BrlValidator/executor — no grammar coupling needed.
//
// Deliberately validator concerns, NOT grammar concerns (keeps LLM-generated
// documents parseable so the validate->repair loop gets good errors):
//  - the block catalog (page, table, chart, viewport, tree, kpiGrid, ...)
//  - config-attribute vs compact-content-block resolution of `name: value`
//  - "{...}" string interpolation (STRING is parsed as-is here)
//  - viewport constraints (scale => vector output, etc.)
grammar nl.bimbase.bimworks.Brl with nl.bimbase.bimworks.Bcl

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.bimbase.nl/bimworks/Bql" as bql
import "http://www.bimbase.nl/bimworks/Bvl" as bvl
import "http://www.bimbase.nl/bimworks/Bcl" as bcl

generate brl "http://www.bimbase.nl/bimworks/Brl"

// ==================== Structure ====================

BrlDocument:
	"brl" version=LONG
	report=BrlReport
;

BrlReport:
	"report" title=STRING body=BrlBody
;

BrlBody:
	{BrlBody} "{" items+=BrlItem* "}"
;

BrlItem:
	BrlLet | BrlForeach | BrlWhen | BrlElement
;

BrlLet:
	"let" name=BrlName "=" value=BrlValue
;

BrlForeach:
	"foreach" variable=BrlName "in" source=BrlValue body=BrlBody
;

BrlWhen:
	"when" condition=BrlExpression body=BrlBody (=>"else" elseBody=BrlBody)?
;

// page "Title" { ... }  |  table { ... }  |  text: "..."  |  break
// Whether `name: value` is a config attribute of the enclosing block or a
// compact content block is resolved semantically against the block catalog.
BrlElement:
	name=BrlName (label=STRING)? (body=BrlBody | ":" value=BrlValue)?
;

// ==================== Values ====================

BrlValue:
	=>BrlRatio | BrlArray | BrlInlineQuery | BrlInlineCheck | BrlInlineBvl | BrlMarkdown | BrlExpression
;

// Embedded BQL, e.g.:  bql GET type AS Type, COUNT(qid) AS Count GROUP BY type
BrlInlineQuery:
	"bql" query=Bql
;

// Embedded BCL, e.g.:  bcl select (type = IFCWALL) { require property.Pset_WallCommon.IsExternal; }
//
// Deliberately NOT check=Bcl: the inherited Bcl entry rule matches empty input
// (its top-level SelectBlock is fully optional), which made "bcl" followed by
// ordinary BRL items ambiguous — ANTLR warning(200) on 'class' ID '{...}' and
// 'name' STRING, silently preferring the EMPTY check. The wrapper demands a
// non-empty check: an optional name plus at least one select(...) block, or a
// programmed check. Top-level actionSets/conditions/bare requires are not
// available inline; use a select(...) block (reports need a subject anyway).
BrlInlineCheck:
	"bcl" check=BrlBclContent
;

BrlBclContent returns bcl::Bcl:
	{bcl::Bcl} (root=BrlBclRoot | programmed=ProgrammedCheck)
;

BrlBclRoot returns bcl::SelectBlock:
	{bcl::SelectBlock}
	("name" name=STRING)?
	(subSelects+=Select)+
;

// Embedded BVL for viewport styling (docs/bql-bvl-render-design.md §7.2), e.g.:
//   style: bvl if (type = IFCSPACE) { HIDE; } if (property.*.IsExternal = true) { COLOR "#3070b3"; }
//
// Same non-empty-wrapper shape as BrlInlineCheck above, for the same reason:
// the inherited Bvl entry rule's BlockContent matches empty input, which would
// make "bvl" followed by ordinary BRL items ambiguous (warning(200), EMPTY
// style silently preferred). The wrapper demands at least one if(...) chain or
// action set. Feature names mirror the generated bvl::BlockContent EMF class
// (subConditions/actionSets); top-level `group` blocks are deliberately not
// available inline — groups drive viewer color legends, not report styling.
//
// Any change here requires the GenerateBimQuery.mwe2 regeneration (run locally);
// check the ANTLR log for new warning(200)s afterwards — the Brl->Bcl->Bvl->Bql
// shared lexer makes every base-grammar keyword reserved.
BrlInlineBvl:
	"bvl" content=BrlBvlContent
;

BrlBvlContent returns bvl::BlockContent:
	{bvl::BlockContent} (subConditions+=IfCondition | actionSets+=ActionSet)+
;

// Markdown prose for longer text blocks; the only fenced construct in BRL.
BrlMarkdown:
	content=MD_FENCE
;

// scale: 1:100  (validator: positive integers)
BrlRatio:
	numerator=LONG ":" denominator=LONG
;

// Arrays hold names, strings, numbers and ratios — deliberately NOT inline
// queries/checks/markdown/nested arrays: a query inside "[a, b]" made the
// array comma ambiguous with BQL's own feature-list commas (the bulk of the
// ANTLR warning(200)s at the GET/COLLECT/material list decisions).
BrlArray:
	{BrlArray} "[" (values+=BrlArrayValue ("," values+=BrlArrayValue)*)? "]"
;

BrlArrayValue:
	=>BrlRatio | BrlExpression
;

// ==================== BRL expressions ====================
// Precedence (low -> high): or, and, not, comparison, operand. Deliberately
// no arithmetic: data math belongs in BQL. Lowercase and/or/not are new
// keywords (base grammars use uppercase forms).

BrlExpression:
	BrlOr
;

BrlOr returns BrlExpression:
	BrlAnd ({BrlBinary.left=current} operator="or" right=BrlAnd)*
;

BrlAnd returns BrlExpression:
	BrlNot ({BrlBinary.left=current} operator="and" right=BrlNot)*
;

BrlNot returns BrlExpression:
	{BrlUnary} operator="not" operand=BrlNot
	| BrlComparison
;

BrlComparison returns BrlExpression:
	BrlOperand ({BrlBinary.left=current} operator=("==" | "!=" | "<" | "<=" | ">" | ">=") right=BrlOperand)?
;

BrlOperand returns BrlExpression:
	  {BrlNumberLiteral} literal=NumericLiteralWithUnit    // 300 | 1.1 m | 14 cm (reuses Bql units)
	| {BrlStringLiteral} value=STRING                      // may contain {interpolation}, parsed later
	| {BrlBooleanLiteral} value=Boolean                    // Bql's Boolean enum (true/false)
	| {BrlPath} segments+=BrlKeywordValue                  // view: top (same AST as a bare ID value)
	| BrlPathOrCall
	| "(" BrlExpression ")"
;

// model.stats.entities  |  storey.Name  |  now()  |  format(storey.Elevation, "0.00 m")
BrlPathOrCall returns BrlExpression:
	{BrlPath} segments+=BrlName ("." segments+=BrlName)*
	(=>"(" {BrlCall.target=current} (args+=BrlExpression ("," args+=BrlExpression)*)? ")")?
;

// Keyword-as-identifier: base-grammar keywords that are legitimate BRL
// block/attribute names or path segments. Kept MINIMAL on purpose: every
// keyword here is also a token BQL can consume mid-query, so each addition
// widens the ambiguity surface at query/report boundaries (see the resolved
// warning(200) on '*' 'children': BQL path keywords like children/parent/
// space/building/geometry were removed again for exactly that reason — they
// are query vocabulary, not report vocabulary). Extend only when a catalog
// key genuinely collides, and re-check the ANTLR log afterwards.
BrlName returns ecore::EString:
	ID |
	"name" | "value" | "type" | "label" | "text" | "source" | "height" |
	"width" | "depth" | "class" | "view" | "mode" | "image" | "group" |
	"model" | "count" | "success" | "error" | "warning" | "info" |
	// re-allowed 2026-08-24 after a sweep of BrlValidator's block catalog against the
	// inherited keyword list: meta (block), header (meta/page attribute, a keyword since
	// the LENGTH_UNIT= unglue split "header."), level (callout attribute)
	"meta" | "header" | "level"
;

// Keyword-as-value: base-grammar keywords that are bare values of a BRL attribute (BrlValidator's
// enums), but neither block/attribute names nor path segments, so they are allowed as an operand
// only and NOT in BrlName. Every operand position follows a fixed BRL token (`:`, `=`, `in`,
// `when`, an operator, `(`, `[` or `,`), so no decision at a query/report boundary sees them.
// Extend when a base grammar turns a documented value into a keyword (BrlViewportValuesTest
// fails then) and re-check the ANTLR log afterwards.
//  - top/bottom: BVL annotation anchors (AnnotationAnchor) since 2026-10-14; `view: top`. bottom is
//    no view, but parses so the validator can list the views instead of a syntax error.
//  - front/back/left/right: BVL annotation anchors since 2026-10-21; `view: front` etc.
BrlKeywordValue returns ecore::EString:
	"top" | "bottom" | "front" | "back" | "left" | "right"
;

// ==================== Terminals ====================
// Everything else (ID, STRING, LONG, DOUBLE, WS, comments) is inherited from
// the chain (common.Terminals + Bql). Head-grammar terminals are matched
// before inherited ones, so MD_FENCE wins over ID for the 'md' prefix.

// md` ` ` ... ` ` ` — raw markdown, no interpolation. ValueConverter strips the
// delimiters.
terminal MD_FENCE: 'md` ` `' -> '` ` `';

```
