Reference·BCOL

BCOL grammar

The Xtext grammar of BCOL as shipped in this release.

The Xtext grammar the BIM Compare 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#
// BCOL — BIM.works Compare Language (docs/model-compare-design.md §5).
//
// A compare definition says how the objects of two models (left and right) are matched, which
// rules classify the units (a matched pair, an added object, a removed object), which features
// count as a change and with what tolerance, what is reported, and how every outcome is shown.
// Conditions and feature paths are BQL; the visualisation is BVL (action sets and if blocks),
// which is why the grammar builds on Bvl, like Bcl.
//
// The 3.0 form "identification: <feature> compare (<feature>, ...)" is gone on purpose: no client
// used it (design decision 1, 2026-10-04).
grammar nl.bimbase.bimworks.Bcol with nl.bimbase.bimworks.Bvl

import "http://www.bimbase.nl/bimworks/Bql" as bql
import "http://www.bimbase.nl/bimworks/Bvl" as bvl

generate bcol "http://www.bimbase.nl/bimworks/Bcol"

// Statements, one rule chain (select ... else select ... else { }), the top-level outcome blocks
// (the defaults of every rule) and the style of loaded objects that are not part of the compare,
// in any order. More than one rule chain parses, but the validator refuses it: the first match
// wins across one chain.
Bcol:
	{Bcol}
	(statements += Statement | rules += Rule | outcomes += Outcome | others += Others)*
;

Statement:
	Match | Scope | RulesSide | WatchList | Report | ToleranceDefault | Align | CompareGroupBy
;

// match attribute.GlobalId then attribute.Tag FOR (type = IFCDOOR) then (type, attribute.Name);
// Each matcher pairs objects that are still unpaired; a tuple is a composite key. The oid lineage
// is matched implicitly before the first matcher (§5.3).
Match:
	"match" matchers += Matcher ("then" matchers += Matcher)* ";"
;

Matcher:
	GeometryMatcher | KeyMatcher
;

// The geometric fallback for GlobalId churn (phase 4). The predicate separates it from the
// geometry: features of GetFeature (geometry:headroom, ...), which continue with ":".
GeometryMatcher:
	=>("geometry" "WITHIN") distance = NumericLengthLiteralWithUnit
;

KeyMatcher:
	(keys += GetFeature | "(" keys += GetFeature ("," keys += GetFeature)+ ")")
	("FOR" "(" condition = BooleanExpression ")")?
;

// WHERE <condition>;  left WHERE <condition>;  right WHERE <condition>;
Scope:
	(side = CompareSide)? "WHERE" condition = BooleanExpression ";"
;

// The side every select judges a pair on, unless the select names its own (§5.4).
RulesSide:
	"rules" "on" side = RuleSide ";"
;

// compare (attribute.Name, aabb.width WITHIN 50 mm, geometry.placement WITHIN 10 mm) except (...);
WatchList:
	{WatchList}
	"compare" "(" (items += WatchItem ("," items += WatchItem)*)? ")"
	("except" "(" excluded += GetFeature ("," excluded += GetFeature)* ")")?
	";"
;

WatchItem:
	feature = (GetFeature | GeometryWatch) ("WITHIN" tolerance = Tolerance)?
;

// geometry, or one facet of it (§5.6). Not a BQL feature: GetFeature has no bare "geometry".
GeometryWatch returns bql::Feature:
	{GeometryWatch} "geometry" ("." facet = GeometryFacet)?
;

// report (type, attribute.Name, buildingStorey.attribute.Name AS Storey);
Report:
	"report" "(" items += SingleFeature ("," items += SingleFeature)* ")" ";"
;

// tolerance length 0.1 mm;  tolerance angle 0.01 deg;  tolerance relative 0.0001 %;
ToleranceDefault:
	"tolerance" kind = ToleranceKind tolerance = Tolerance ";"
;

// align auto; compares the right side's geometry in the frame of the dominant shared transform
// (§6.4).
Align:
	"align" mode = AlignMode ";"
;

// group by (type, buildingStorey.attribute.Name);
CompareGroupBy:
	"group" "by" "(" features += GetFeature ("," features += GetFeature)* ")" ";"
;

// select (<condition>) [on any|left|right|both] { <rule body> } else select (...) { ... } else { ... }
// The same shape as a BCL select chain; the first match wins (§5.4).
Rule:
	"select" "(" condition = BooleanExpression ")" ("on" side = RuleSide)? "{"
		body = RuleBody
	"}"
	("else" else = Rule)?
	(=>"else" "{" elseBody = RuleBody "}")?
;

RuleBody:
	{RuleBody}
	("name" name = STRING)?
	(ignore = Ignore)?
	(statements += RuleStatement | outcomes += Outcome)*
;

RuleStatement:
	WatchList | Report
;

// ignore;  or  ignore { HIDE; }  — the units are not reported; the block styles them (§5.4).
Ignore:
	{Ignore} "ignore" ("{" content = BlockContent "}")? ";"
;

Outcome:
	Added | Removed | Changed | Unchanged
;

Added:
	"added" (label = STRING)? body = OutcomeBody
;

Removed:
	"removed" (label = STRING)? body = OutcomeBody
;

// changed (<watch items>) when (<pair condition>) "<label>" { ... }  — every part optional (§5.7).
Changed:
	"changed" ("(" filters += WatchItem ("," filters += WatchItem)* ")")?
	("when" "(" when = BooleanExpression ")")?
	(label = STRING)?
	body = OutcomeBody
;

Unchanged:
	"unchanged" (label = STRING)? body = OutcomeBody
;

// ignore;  or  { <BVL> [report (...);] [left { <BVL> }] [right { <BVL> }] } — the report and the
// side blocks follow the BVL actions, in any order.
OutcomeBody:
	{OutcomeBody}
	(
		ignore = Ignore |
		"{"
			content = BlockContent
			(reports += Report | sides += SideBlock)*
		"}"
	)
;

SideBlock:
	side = CompareSide "{" content = BlockContent "}"
;

// The style of loaded objects that are not part of the compare (by default untouched).
Others:
	"others" "{" content = BlockContent "}"
;

// Overrides Bql's SinglePathExpression with one more alternative: left. and right. pin a test
// to one side of a pair, e.g. select (left.type = IFCBUILDINGELEMENTPROXY AND right.type != ...).
// Overridden here rather than in Bql, so the two words are reserved in BCOL texts only. Keep the
// other alternatives in step with Bql.xtext.
SinglePathExpression returns bql::SinglePathExpression:
	ProjectPath | BuildingPath | BuildingStoreyPath | SitePath | SpacePath | RelatedBuildingElementPath | TypeObjectPath | ParentPath | DecomposesPath | ContainedInPath | OwnPath | SidePath
;

SidePath returns bql::SinglePathExpression:
	{SidePath} side = CompareSide ("." (terminalExpression = NewTerminalExpression | subPath = PathExpression))?
;

// Overrides Bql's WherePrimary with one more operand: a feature of the other side, for
// cross-side comparisons such as right.calculated.property.level > left.calculated.property.level.
// Keep the other alternatives in step with Bql.xtext.
WherePrimary returns bql::Expression:
	=>LongWithUnitLiteralTyped |
	DoubleWithUnitLiteralTyped |
	WhereAbsFunction |
	WhereValueFunction |
	WhereCaseExpression |
	RelationAggregate |
	SideFeature |
	ChangeFeature |
	ConditionFeature |
	"(" WhereAddSub ")"
;

// change.<path>: a value of the pair's change set (§5.9), as an operand of a when (...) condition,
// e.g. changed when (change.geometry.translation.length > 100 mm) "Moved far" { ... }
ChangeFeature returns bql::Expression:
	{ChangeFeature} "change" "." path = ChangePath
;

// Overrides Bql's WhereNoParenHeadPrimary, the first operand of a comparison, so a change value can
// lead one too: change.geometry.translation.length > 100 mm. Keep the other alternatives in step
// with Bql.xtext.
WhereNoParenHeadPrimary returns bql::Expression:
	=>LongWithUnitLiteralTyped |
	DoubleWithUnitLiteralTyped |
	WhereAbsFunction |
	WhereValueFunction |
	WhereCaseExpression |
	RelationAggregate |
	ChangeFeature |
	ConditionFeature
;

// Overrides Bvl's LabelValue with one more alternative: a value of the unit's change set, for the
// labels and annotations of compare outcomes (§5.9):
//   annotate(text("Moved " + change.geometry.translation.length) hover) DISPLACEMENT;
// Keep the other alternatives in step with Bvl.xtext.
LabelValue returns bvl::LabelValue:
	ChangeLabel | FeatureLabel | StringLabel | SequenceLabel | ImageLabel
;

ChangeLabel returns bvl::LabelValue:
	{ChangeLabel} (prefix = STRING "+")? "change" "." path = ChangePath ("+" postfix = STRING)?
;

// The path of a change value: geometry.translation.length, geometry.translation, geometry.rotation.angle,
// geometry.scale, count, or a watched feature's record path with .delta for its difference
// (property.Pset_WallCommon.FireRating.delta). The words that are keywords elsewhere are listed so
// they read as names here; quote any other name that is one.
ChangePath:
	ChangeName ("." ChangeName)*
;

ChangeName:
	ID | STRING | "geometry" | "translation" | "rotation" | "scale" | "shape" | "length" | "angle" | "presence" | "placement"
	| "appearance" | "attribute" | "property" | "quantity" | "classification" | "material" | "type" | "children" | "count"
	| "value" | "aabb" | "calculated" | "buildingStorey" | "typeObject" | "obb" | "volume" | "area" | "width" | "height"
	| "depth" | "left" | "right" | "x" | "y" | "z" | "name" | "description" | "counts" | "triangles" | "vertices"
	| "thickness" | "perimeter" | "level" | "id" | "status" | "source" | "space" | "zone" | "parent" | "identification"
	| "predefinedType" | "floorArea" | "grossVolume" | "netVolume" | "grossSurface" | "netSurface" | "footprintArea"
	| "usableArea" | "diameter" | "radius" | "distance"
;

SideFeature returns bql::Expression:
	{SideFeature} side = CompareSide "." feature = ConditionFeature
;

// The *_NONE literals are the unset sentinels (first literal = EMF default), as in Bql's unit
// enums; the validator refuses them when written.
enum CompareSide:
	SIDE_NONE | LEFT="left" | RIGHT="right"
;

enum RuleSide:
	RULE_SIDE_NONE | ANY="any" | LEFT="left" | RIGHT="right" | BOTH="both"
;

enum GeometryFacet:
	FACET_NONE | PRESENCE="presence" | PLACEMENT="placement" | TRANSLATION="translation" | ROTATION="rotation" | SCALE="scale" | SHAPE="shape" | APPEARANCE="appearance"
;

enum ToleranceKind:
	TOLERANCE_NONE | LENGTH="length" | ANGLE="angle" | RELATIVE="relative"
;

enum AlignMode:
	ALIGN_NONE | OFF="none" | AUTO="auto"
;