BUL grammar

The Xtext grammar of BUL as shipped in this release.

The Xtext grammar the BIM Update 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 nl.bimbase.bimworks.Bul with nl.bimbase.bimworks.Bql

generate bul "http://www.bimbase.nl/bimworks/Bul"

Bul:
	updates += Update (updates += Update)*
;

Update:
	Set | Del | DeleteObject | TransformObject | ConvertSchema | Georeference
;

// One WHERE may carry multiple comma-separated assignments (the features-viewer edit
// mode records all edits on one object as a single statement): the WHERE is evaluated
// once, each assignment becomes its own TransactionEffect (BimModelTransaction.applyUpdates)
Set:
	"SET" assignments += Assignment ("," assignments += Assignment)* "WHERE" expression=BooleanExpression
;

// The value is a literal, a typed literal, or a feature of the object itself
// (docs/bul-feature-values-design.md): SET quantity."BaseQuantities"."NetVolume" =
// calculated.quantity.netVolume WHERE ... copies each matched object's own value, read once
// at commit time from the version the transaction starts from. Every GetFeature starts with
// a keyword, so the three alternatives are told apart by their first token (a literal starts
// with a number, a string, true/false or null; a typed value with an ID and "("). Wildcards,
// meta features and features with several values are refused after parsing
// (BimModelTransaction), as the zero-name pset rule is.
Assignment:
	feature = SimpleFeature "=" (literal=(BooleanLiteral | LongWithUnitLiteral | DoubleWithUnitLiteral | NullLiteral | StringLiteral) | typed=TypedValue | source=GetFeature)
;

// A property value with its IFC type (docs/upload-diff-design.md section 14.1):
//   SET property."Dimensions"."Width" = IFCPOSITIVELENGTHMEASURE(1200 mm) WHERE ...
//   SET property."Pset_WallCommon"."Reference" = IFCIDENTIFIER("W-01") WHERE ...
// The type is a defined type of the model's schema whose underlying type takes the literal; a
// unit must be of the measure's dimension. Checked after parsing (BimModelTransaction), as the
// type names are no keywords: IFC type names are IDs in the inherited Bql grammar.
TypedValue:
	type=ID "(" literal=(BooleanLiteral | LongWithUnitLiteral | DoubleWithUnitLiteral | StringLiteral) ")"
;

Del:
	"DEL" features += SimpleFeature ("," features += SimpleFeature)* "WHERE" expression=BooleanExpression
;

// Deletes the matched objects themselves (docs/delete-object-plan.md): unlink-only
// with a sole-reference cascade, applied by TransactionEffectApplier. The WHERE is
// resolved once at commit time, like SET/DEL.
DeleteObject:
	{DeleteObject} "DELETE" "OBJECT" "WHERE" expression=BooleanExpression
;

// Rigid world-space transform of the matched objects (docs/object-transform-design.md):
// W' = T · R(axis, angle, pivot) · W, absorbed into the product's own
// IfcLocalPlacement.RelativePlacement by TransactionEffectApplier (copy-on-write for
// shared placement entities). Coordinates are project/world values, default mm with an
// optional length unit; angles in degrees; AXIS is a dimensionless direction (normalized
// by the applier). At least one of MOVE/ROTATE is required — enforced post-parse in
// BimModelTransaction, like the zero-name pset rule above. PIVOT defaults to the
// object's current world placement origin; the UI always writes it explicitly so replay
// is deterministic (the WHERE is resolved once at commit time, like SET/DEL).
// A door or window takes the opening it fills along, and so the hole in its wall, unless
// WITHOUT OPENINGS says otherwise; WITH OPENINGS states the default
// (docs/placement-controls-design.md §16.2).
TransformObject:
	{TransformObject} "TRANSFORM" (move=MoveClause)? (rotate=RotateClause)?
		((withOpenings?="WITH" | withoutOpenings?="WITHOUT") "OPENINGS")? "WHERE" expression=BooleanExpression
;

// Converts the whole model to another IFC schema (docs/ifc-schema-conversion-design.md
// section 6): CONVERT SCHEMA TO IFC4. It makes a version of its own, so it is the only
// statement of its BUL, and it selects nothing: the statement applies to every object. The
// optional WHERE exists for two reasons that have nothing to do with selecting. It keeps
// "expression" a feature of every Update, so that the code that asks any update for its
// expression stays as it is, and it lets a WHERE behind the statement be refused with a
// message that says why (BimModelTransaction) instead of with a syntax error.
ConvertSchema:
	{ConvertSchema} "CONVERT" "SCHEMA" "TO" target=SchemaName ("WHERE" expression=BooleanExpression)?
;

// Writes the georeference of the whole model into its IFC data as an IfcMapConversion with an
// IfcProjectedCRS on the 3D 'Model' context (docs/georeference-editing-design.md section 4):
//   GEOREFERENCE CRS "EPSG:28992" ORIGIN (160071.588 m, 384156.389 m, 18.753 m) XAXIS (0.6379, -0.7701)
//   GEOREFERENCE CRS "EPSG:28992" ORIGIN (160071.588, 384156.389, 18.753) ROTATION 309.64 GRIDSCALE 1
//   GEOREFERENCE REMOVE
// ORIGIN is the map position of the engineering origin; a value without a unit is in metres
// (map coordinates, unlike TRANSFORM's model millimetres). XAXIS is the direction of the model's
// X axis in map coordinates, ROTATION the same as an angle in degrees counter-clockwise from east;
// exactly one of the two. GRIDSCALE is the combined scale factor (default 1), not the raw
// IfcMapConversion.Scale, which the server derives from it and the model's length unit. The
// optional WHERE is there for the reason CONVERT SCHEMA has one: it keeps "expression" a feature
// of every Update, and a WHERE is refused after parsing with a message that says why.
Georeference:
	{Georeference} "GEOREFERENCE" (remove?="REMOVE" | set=GeoreferenceSet) ("WHERE" expression=BooleanExpression)?
;

GeoreferenceSet:
	"CRS" crs=STRING
	"ORIGIN" "(" eastings=DoubleWithLengthUnitLiteralTyped "," northings=DoubleWithLengthUnitLiteralTyped "," height=DoubleWithLengthUnitLiteralTyped ")"
	((xaxis?="XAXIS" "(" abscissa=DoubleOrLong "," ordinate=DoubleOrLong ")") | (hasRotation?="ROTATION" rotation=DoubleOrLong))
	(hasGridScale?="GRIDSCALE" gridScale=DoubleOrLong)?
	("CRSDESCRIPTION" description=STRING)?
	("GEODETICDATUM" geodeticDatum=STRING)?
	("VERTICALDATUM" verticalDatum=STRING)?
	("MAPPROJECTION" mapProjection=STRING)?
	("MAPZONE" mapZone=STRING)?
;

// The name of a schema as a user writes it. IFC2X3, IFC4 and IFC4X3 are keywords of the
// language (enum IfcSchema in Bql), so an ID does not match them and they are named here. Any
// other name is an ID or a string; the server answers it with the conversions that exist. A
// name that was written as a string keeps its quotes (ConversionStatement takes them off).
SchemaName:
	"IFC2X3" | "IFC4" | "IFC4X3" | ID | STRING
;

MoveClause:
	"MOVE" "(" x=DoubleWithLengthUnitLiteralTyped "," y=DoubleWithLengthUnitLiteralTyped "," z=DoubleWithLengthUnitLiteralTyped ")"
;

RotateClause:
	"ROTATE" "(" ("AXIS" | local?="LOCAL_AXIS") "(" ax=DoubleOrLong "," ay=DoubleOrLong "," az=DoubleOrLong ")" "," angle=DoubleOrLong
		("," "PIVOT" "(" px=DoubleWithLengthUnitLiteralTyped "," py=DoubleWithLengthUnitLiteralTyped "," pz=DoubleWithLengthUnitLiteralTyped ")")? ")"
;

SimpleFeature:
	SimpleAttributeFeature | SimplePropertyFeature | SimpleQuantityFeature | SimpleClassificationFeature
;

// Member names are optional: the zero-name form (property."Pset") addresses the WHOLE
// set and is only legal in DEL (deletes the pset/qset; enforced in BimModelTransaction,
// docs/features-panel-additions-plan.md §7) — a SET requires at least one member name.
// The optional .description field (SET only) writes the member's IFC Description — the
// features panel uses it to persist a picked bSDD property URI (Bsdd2/docs/UI-INTEGRATION.md
// §6.3). "description" is already a keyword in the inherited Bql grammar (PropertyFeature
// field names), so a property literally named description must be written quoted — same
// rule as classification's name/location below.
SimplePropertyFeature:
	({SimplePropertyFeature} ("property" "." propertySetName=(STRING | ID) ("." propertyNames += (STRING | ID))* ("." field="description")?))
;

SimpleQuantityFeature:
	({SimpleQuantityFeature} ("quantity" "." quantitySetName=(STRING | ID) ("." quantityNames += (STRING | ID))*))
;

SimpleAttributeFeature:
	({SimpleAttributeFeature} ("attribute" "." name=Attribute))
;

// classification."<system>" = "<identity>"            -> link/upsert a reference (SET)
// classification."<system>"."<identity>".name = "..." -> field on this object's reference (SET)
// classification."<system>"."<identity>"              -> unlink one reference (DEL only)
// classification."<system>"                           -> unlink all refs in the system (DEL only)
// References are addressed by (system name, identity); identity = ItemReference (IFC2X3)
// or Identification (IFC4+). Semantics in TransactionEffectApplier
// (docs/features-panel-additions-plan.md §10). "name"/"location" are already keywords in
// the inherited Bql grammar (ClassificationFeature), so bare name/location as an
// IDENTITY must be written quoted.
SimpleClassificationFeature:
	({SimpleClassificationFeature} "classification" "." systemName=(STRING | ID) ("." identity=(STRING | ID) ("." field=("name" | "location"))?)?)
;